A
Allerdyce.John
I would like to know what is the advantage of inherit from
unary_function template?
For example, I have this in my code:
What is the advantage of doing this:
class Same : std::unary_function<A*, bool>
{
public:
Same(A* a) : _a(a){};
bool operator()(A*a1);
private:
A* _a;
};
instead of this:
class Same
{
public:
Same(A* a) : _a(a){};
bool operator()(A*a1);
private:
A* _a;
};
typedef list<A*> AList
bool MyAList::contains(A* a) {
AList::iterator iter;
iter = find_if ( _aList.begin(), _aList.end(), Same(a));
if (iter == _aList.end())
return false;
else
return true;
}
unary_function template?
For example, I have this in my code:
What is the advantage of doing this:
class Same : std::unary_function<A*, bool>
{
public:
Same(A* a) : _a(a){};
bool operator()(A*a1);
private:
A* _a;
};
instead of this:
class Same
{
public:
Same(A* a) : _a(a){};
bool operator()(A*a1);
private:
A* _a;
};
typedef list<A*> AList
bool MyAList::contains(A* a) {
AList::iterator iter;
iter = find_if ( _aList.begin(), _aList.end(), Same(a));
if (iter == _aList.end())
return false;
else
return true;
}