Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::bind2nd

 

std::bind2nd is a binder to call a binary function with the value bound as second argument. If the first argument needs to be bound, use std::bind1st instead.

 

The distinction between std::bind1st and std::bind2nd gets clear in division:

 

 

 

 

 

#include <algorithm>
#include <numeric>
#include <vector>

//From http://www.richelbilderbeek.nl/CppHalve.htm
void Halve (std::vector<double>& v)
{
  std::transform(
    v.begin(),v.end(),v.begin(),
    std::bind2nd(std::divides<double>(),2.0));
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict