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






Negate contents of a list with transform() and negate()

  
#include <iostream>
#include <list>
#include <functional>
#include <algorithm>
using namespace std;
   
int main()
{
  list<double> l;
  int i;
   
  for(i=1; i<10; i++) l.push_back((double)i);
   
  list<double>::iterator p = l.begin();
  while(p != l.end()) {
    cout << *p << " ";
    p++;
  }
  cout << endl;
   
  p = transform(l.begin(), l.end(),l.begin(),negate<double>());
   
  cout << "Negated contents of the list:\n";
  p = l.begin();
  while(p != l.end()) {
    cout << *p << " ";
    p++;
  }
   
  return 0;
}
  
    
  








Related examples in the same category

1.negate for list
2.negate the contents of result