replace_if bind2nd and greater : bind2nd « STL Algorithms Helper « C++ Tutorial






#include <algorithm>
#include <functional>
#include <vector>
#include <iostream>
using namespace std;

void print(int elem)
{
  cout << elem << " ";
}

int main(int argc, char** argv)
{
  vector<int> myVector;
  myVector.push_back(1);
  myVector.push_back(2);
  myVector.push_back(3);
  myVector.push_back(4);
  myVector.push_back(5);
  myVector.push_back(6);


  replace_if(myVector.begin(), myVector.end(), bind2nd(greater<int>(), 100),100);
  for_each(myVector.begin(), myVector.end(), &print);
  cout << endl;

  return (0);
}








32.6.bind2nd
32.6.1.Demonstrate bind2nd()
32.6.2.Use the generic count algorithm with predicate: Determine the number of array elements that are not equal to 1
32.6.3.Use bind2nd() to create a unary function object that will return true when a value is greater than 10.
32.6.4.replace_if, bind2nd and less
32.6.5.replace_if bind2nd and greater
32.6.6.trasform, bind2nd and plus