Divided contents of a list with transform() and divides() : divides « STL Algorithms Helper « C++






Divided contents of a list with transform() and divides()

  
#include <iostream>
#include <list>
#include <functional>
#include <algorithm>
using namespace std;
   
int main()
{
  list<double> l;
  list<double> divisors;
  int i;
   
  for(i=10; i<100; i+=10) l.push_back((double)i);
  for(i=1; i<10; i++) divisors.push_back(3.0);
   
  list<double>::iterator p = l.begin();
  while(p != l.end()) {
    cout << *p << endl;
    p++;
  }
   
  p = transform(l.begin(), l.end(),divisors.begin(), l.begin(),divides<double>()); // call function object
   
  p = l.begin();
  while(p != l.end()) {
    cout << *p << " ";
    p++;
  }
   
  return 0;
}
  
    
  








Related examples in the same category

1.Use a binary function object divides
2.Transform a vector with bind1st and divides
3.Transform with divides