|
-
May 26th, 2011, 04:43 PM
#7
Re: predicate function
Lindley, under which circumstances does remove_if() take a binary predicate?
I had my proposed code sample just ready when the notification mail about your post came in, and now that I have it I want to post it... It is a functor-style unary predicate that takes the "other" T and the bool as constructor parameters:
Code:
class predicate
{
public:
predicate(const T &b, bool c) : m_b(b), m_c(c)
{}
bool operator()(const T &a) const
{
return m_c ? a.x < m_b.y : a.x > m_b.y;
}
private:
const T &m_b;
bool m_c;
};
BTW, how does your first example work at all, as I don't see an operator() in there anywhere? Is there a third way to define predicates I don't know of yet?
Actually, I, personally, find the lambda function example even easier to understand. I'm gradually approaching comprehension of them...
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
|