Using bind2nd() to create a unary function object that will return true when a value is greater than 10. - C++ STL Algorithm

C++ examples for STL Algorithm:bind2nd

Description

Using bind2nd() to create a unary function object that will return true when a value is greater than 10.

Demo Code

#include <iostream>
#include <list>
#include <functional>
#include <algorithm>
using namespace std;
template<class InIter>
void show_range(const char *msg, InIter start, InIter end);
int main()//from ww  w.  jav a  2 s.c o  m
{
   list<int> lst;
   list<int>::iterator res_itr;
   for(unsigned i=1; i < 20; ++i) lst.push_back(i);
   show_range("Original sequence:\n", lst.begin(), lst.end());
   cout << endl;

   res_itr = remove_if(lst.begin(), lst.end(), bind2nd(greater<int>(), 10));
   show_range("Resulting sequence:\n", lst.begin(), res_itr);
   return 0;
}

template<class InIter>
void show_range(const char *msg, InIter start, InIter end) {
   InIter itr;
   cout << msg;
   for(itr = start; itr != end; ++itr)
      cout << *itr << " ";
   cout << endl;
}

Result


Related Tutorials