peek inside container's elements from UnaryPredicate

Discussion in 'C++' started by Rares Vernica, Jul 5, 2008.

  1. Hello,

    Suppose I have a container of pair<int, int>, how would I use the
    predefined function objects/adapters (e.g., greater, bind1st, mem_func,
    compose_f_gx) and the "count" function from <algorithm> to get and
    number of pairs, "p", that have "p.first > 5"?

    Writing a custom UnaryPredicate function is easy, but I would
    prefer to use the predefined ones if possible.

    Example:

    std::list<std::pair<int, int> > c;
    // insert elements in c
    int x = count(c.begin(), c.end(), /* UnaryPredicate */);
    // x is the number of pairs, p, with p.first > 5

    More general, how can I compose the predefined function
    objects/adapters, so that the resulting UnaryPredicate peeks inside the
    elements of a container?

    Thanks,
    Rares
     
    Rares Vernica, Jul 5, 2008
    #1
    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. Replies:
    4
    Views:
    805
    Daniel T.
    Feb 16, 2006
  2. wolverine
    Replies:
    2
    Views:
    455
    Marcus Kwok
    Jul 24, 2006
  3. Luis Zarrabeitia
    Replies:
    5
    Views:
    376
    Peter Otten
    Oct 2, 2008
  4. Terry Reedy
    Replies:
    2
    Views:
    337
    Steven D'Aprano
    Oct 2, 2008
  5. Steven D'Aprano

    How to peek inside a decorated function

    Steven D'Aprano, Feb 15, 2009, in forum: Python
    Replies:
    6
    Views:
    348
    Peter Otten
    Feb 15, 2009
Loading...

Share This Page