List<class> or list<Vector> access ?

B

Birthe Gebhardt

Dear all,
I could not find the way to handle 'not normal' list objects, for example
using remove_if, find etc.

Example :
class Todo
{
public :
..
int getNumber(){ return num_;}
private:
int num_
}

int main(void)
{
list<Todo> lst_Todo;
...
// here comes the problem
lst_Todo.remove_if(???); // where num_ = x
}

The other constelation is: list<vector<vektor<int> > >

Have someone an idea who to talk with this objects ?

Many thanks.

brgds,
Birthe
 
M

Mark P

Birthe said:
Dear all,
I could not find the way to handle 'not normal' list objects, for example
using remove_if, find etc.

Example :
class Todo
{
public :
..
int getNumber(){ return num_;}
private:
int num_
}

int main(void)
{
list<Todo> lst_Todo;
...
// here comes the problem
lst_Todo.remove_if(???); // where num_ = x
}

You need a unary function or function object. Something like this:

class TodoEquals
{
public:
TodoEquals( int value ) : value( value ) {}
bool operator()( const Todo& td ) { return td.getNumber() == value; }

private:
int value;
};

Use as:

lst_Todo.remove_if( TodoEquals(x) );


The other constelation is: list<vector<vektor<int> > >

vector has no member function remove_if but you can use the template
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top