Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
A binder to call a binary function with the value bound as first argument. If the second argument needs to be bound, use std::bind2nd instead.
The use of std::bind1st is clearest in division:
* If on all elements, an element called x, you want to perform '1.0 / x', use std::bind1st one the 1.0. This is demonstrated in the function Reciprocal, which is shown below in the example. * If on all elements, an element called x, you want to perform 'x / 2.0', use std::bind2nd one the 2.0. This is demonstrated in the function Halve.
Replaces all elements by their reprocicals, that is replaces all elements called 'x' by '1.0/x'.
//From http://www.richelbilderbeek.nl/CppReciprocal.htm
void Reciprocal (std::vector<double>& v)
{
std::transform(v.begin(),v.end(),v.begin(),
std::bind1st(std::divides<double>(),1.0));
}
[0] ...
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.