Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > peek inside container's elements from UnaryPredicate

Reply
Thread Tools

peek inside container's elements from UnaryPredicate

 
 
Rares Vernica
Guest
Posts: n/a
 
      07-05-2008
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:air<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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to peek inside a decorated function Steven D'Aprano Python 6 02-15-2009 12:23 PM
Re: Peek inside iterator (is there a PEP about this?) Terry Reedy Python 2 10-02-2008 02:06 PM
Peek inside iterator (is there a PEP about this?) Luis Zarrabeitia Python 5 10-02-2008 08:40 AM
OT: Sneek Peek: Microcephalic InterNeil Explorer Personal Edition PC LOAD LETTER MCSE 132 01-23-2006 08:28 PM
CE Pro Sneak Peek: Defy Broadcast Flag, Build Your Own PVR. Allan DVD Video 0 03-10-2005 11:54 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57