Name
bind2nd function template — Creates a binder2nd function object
Synopsis
template <typename Operation, typename T>
binder2nd<Operation> bind2nd(const Operation& op, const T& x);
The bind2nd
function is a
convenient way to construct a binder2nd
object. Use bind2nd
when you have a binary function
and always want to supply the same value as the first argument to
the function.
Example
Suppose you have a container of data points, and you want to count the number of points that exceed a threshold. Here is one way to do this:
std::cout << std::count_if(data.begin( ), data.end( ), std::bind2nd(std::greater<double>( ), threshold)) << '\n';
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.