|
-
May 26th, 2011, 06:04 PM
#9
Re: predicate function
 Originally Posted by Lindley
You're right, I goofed on the operator.
Ah, ok. 
And remove_if is not a good example of this predicate (perhaps std::sort would be better).
Indeed, for std::sort() a binary predicate makes perfect sense. I'm not familiar enough with the STL algorithms to reliably tell off the top of my head which of them require a binary predicate and which a unary one (given it requires a predicate at all).
I'm curious about what would happen when remove_if() actually would get presented a binary predicate. I somehow suppose it would throw some sort of "operator not defined" error during template instantiation, right?
Of course it would be no problem to define a functor which is both a unary and a binary predicate at the same time. This would provide allround compatibility though I have only a vague idea of what that might be useful for. (However, I don't have the slightest idea of which practical use the predicate skeleton presented by the OP in post #5 might be either.)
While it's clearly not possible to simply take the address of an overloaded function due to overload resolution ambiguity, it might be even possible to use overloaded unary and binary function-style predicates of the same name for the STL algorithms due to the way template instantiation works (at compile-time!). However, this is just wild speculation and I can't imagine any practical use for that either.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|