template <typename elemType, typename Comp = less<elemType> >
class LessThanPred {
public:
LessThanPred(const elemType &val) : _val(val){}
bool operator()(const elemType &val) const
{ return Comp(val, _val); }
void val(const elemType &newval) { _val = newval; }
elemType val() const { return _val; }
private:
elemType _val;};
That's an example from Essential c++. Comp
is obviously a function object class name. Why could I use the Comp(val, _val)
directly? Normally I think I should firstly define a function object like this: Comp comp
, then invoke comp
not Comp
.