Name
bind1st function template — Creates a binder1st function object
Synopsis
template <typename Operation, typename T>
binder1st<Operation> bind1st(const Operation& op, const T& x);
The bind1st
function is a
convenient way to construct a binder1st
object. Use bind1st
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—in other words, where the threshold is less than or equal to the data point. Here is one way to do this:
std::cout << std::count_if(data.begin( ), data.end( ), std::bind1st(std::less_equal<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.