predicates,

V

vsgdp

Why derive from: binary_function? It seems like that class just does some
typedefs.

For example, in Stroustrup (pg. 517 3rd edition):

class Club_eq : public unary_function<Club, bool> {
string s;
public:
explicit Club_eq(const string& ss) : s(ss) {}
bool operator()(const Club& c) const { return c.name == s; }
};

He still uses "Club" and "bool" instead of the typdefed argument_type and
result_type. So what is the point of these base classes?
 
J

Jerry Coffin

Why derive from: binary_function? It seems like that class just does some
typedefs.

For example, in Stroustrup (pg. 517 3rd edition):

class Club_eq : public unary_function<Club, bool> {
string s;
public:
explicit Club_eq(const string& ss) : s(ss) {}
bool operator()(const Club& c) const { return c.name == s; }
};

He still uses "Club" and "bool" instead of the typdefed argument_type and
result_type. So what is the point of these base classes?

The typedefs aren't (at least primarily) for the benefit of the code
in the predicate itself. Rather, they're for use by the code in the
algorithm(s) to which you pass the predicate as an argument. The
typedefs give that code information about your predicate so the
predicate can be used correctly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top