Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Exemple d’utilisation de la fonction objet ‘bind2nd’

 list, list, iterator
{filelink=15276}

#include <iostream>
#include
<list>
#include <functional>
#include <algorithm>
using namespace std;
 
int main()
{
  list<int> lst;
  list<int>::iterator p, endp;
 
  for(int i=1; i < 20; i++) lst.push_back(i);
 
  cout << "Contenu de la liste:";
  p = lst.begin();
  while(p != lst.end()) {
    cout << *p << " ";
    p++;
  }
  cout << endl;
 
  //Compter le nombre d'élément qui excede 10
  cout <<count_if(lst.begin(  ), lst.end(  ),
       bind2nd(greater<double>(  ), 10)) << 'n';
  return 0;
}

No comments yet.

Leave a Comment