29 Aug, 2009, Silenus wrote in the 1st comment:
Votes: 0
How does one go about implementing custom predicates in STL to do things like filtering and applying stuff to all the members of a container?
29 Aug, 2009, Erok wrote in the 2nd comment:
Votes: 0
http://www.cplusplus.com/reference/algor...

I think that's what you are looking for.
29 Aug, 2009, Silenus wrote in the 3rd comment:
Votes: 0
Thanks but what type is Predicate / Function? are these typedefs?
29 Aug, 2009, Erok wrote in the 4th comment:
Votes: 0
Did you read the parameters section?
29 Aug, 2009, Silenus wrote in the 5th comment:
Votes: 0
woops I guess I missed that. They are type parameters of metatype class. The reason I am asking is I am writing a pass through function to the STL container which is embedded in the class so I am curious what type definition i should give the function formal. I speculate from this I will just define it as:

bool f(T const&)

or some such. Thanks;.
29 Aug, 2009, elanthis wrote in the 6th comment:
Votes: 0
Silenus, it depends on the algorithm you're using. for_each just calls the function once for each member, and the return value is ignored. Something like find_if is also a unary function, but must return any value convertable to bool.

The algorithms are all implemented as templates so they're not at all strict on types. Anything that is implicitly convertable between what the algorithm is using and what your function uses is fine. You can also write your predicates as templates if you feel you might need to reuse the same logic on a few different types.
01 Sep, 2009, Silenus wrote in the 7th comment:
Votes: 0
Thanks. I guess I will have to check an STL guide and see how the conversions are taking place. The problem sometimes with template arguments is it's difficult to tell (since they are too generic) what exactly is expected in terms of "type signature". There is a fair deal I dont understand here.

Thanks.
01 Sep, 2009, David Haley wrote in the 8th comment:
Votes: 0
Isn't the whole point of template arguments to be generic? I guess I'm not sure I understand your question?

The good thing is that often the STL source is available for you to read. The bad thing is that it's written using a very obscure style of coding that I find makes it very hard to read until you get used to it.
01 Sep, 2009, Silenus wrote in the 9th comment:
Votes: 0
Actually it's a comment w.r.t. the fact that additional constraints on a generic argument tend to exist but cannot be determined under the template is instantiated. Yeah I wonder if my skill level is at the point I can read the STL source code yet. I guess there is one way to find out :P.
01 Sep, 2009, David Haley wrote in the 10th comment:
Votes: 0
It's not really a question of skill level to be honest. They just use a rather peculiar way of writing things that is extremely terse and requires unpacking. They seem to think that long variable names are evil, for example. :wink: Also, since they code for very high efficiency, sometimes things happen and it's not obvious why, but it makes things faster.
0.0/10