List<class> or list<Vector> access ?

Discussion in 'C++' started by Birthe Gebhardt, Aug 14, 2006.

  1. 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
    Birthe Gebhardt, Aug 14, 2006
    #1
    1. Advertising

  2. Birthe Gebhardt

    Mark P Guest

    Birthe Gebhardt wrote:
    > 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
    function provided in <algorithm> to do basically the same thing.

    > Have someone an idea who to talk with this objects ?
    >
    > Many thanks.
    >
    > brgds,
    > Birthe
    Mark P, Aug 14, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ding feng
    Replies:
    8
    Views:
    847
    Dhruv
    Jul 2, 2003
  2. pmatos
    Replies:
    6
    Views:
    23,778
  3. Replies:
    8
    Views:
    1,913
    Csaba
    Feb 18, 2006
  4. Javier
    Replies:
    2
    Views:
    559
    James Kanze
    Sep 4, 2007
  5. Rushikesh Joshi
    Replies:
    0
    Views:
    356
    Rushikesh Joshi
    Jul 10, 2004
Loading...

Share This Page