template <class T> struct greater : binary_function <T,T,bool> {
bool operator() (const T& x, const T& y) const
{return x>y;}
};
template <class T> struct logical_and : binary_function <T,T,bool> {
bool operator() (const T& x, const T& y) const
{return x&&y;}
};
// (i > 5 && i <=10)
countBoost = std::count_if(vecInts.begin(), vecInts.end(),
boost::bind(std::logical_and<bool>(),
^^^^ // ???? Why ????
boost::bind(std::greater<int>(), _1, 5),
boost::bind(std::less_equal<int>(), _1, 10))
);
Based on my understanding, the pass-in type T for std::logical_and<T> is the type of the pass-in parameters of function operator(). Given the above code, it seems that the type of std::greater is bool that is determined by the returned value of operator().
Is that correct?
Thank you
The boost binder does a bit more magic than what you might be expecting. When one of the bound arguments is a bind expression itself, it will execute that expression during the call and use the result. In this case, the internal bound expressions are calls to
std::less<int>andstd::greater<int>, both of which yield abool, which is then passed to thestd::logical_and<bool>.