fork download
  1. #include <iostream>
  2. #include <deque>
  3. #include <algorithm>
  4.  
  5. int main() {
  6.  
  7. std::deque<int> d{1,2,3,4,5};
  8.  
  9. std::cout << "Before multiplying all elements by 2: \n";
  10. for(auto e: d)
  11. std::cout << e << ' ';
  12. std::cout << '\n';
  13.  
  14. std::transform(std::begin(d), std::end(d), std::begin(d), [](int d){ return (d *= 2); });
  15.  
  16. std::cout << "\nAfter multiplying all elements by 2: \n";
  17. for(auto e: d)
  18. std::cout << e << ' ';
  19. std::cout << '\n';
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
Before multiplying all elements by 2: 
1 2 3 4 5 

After multiplying all elements by 2: 
2 4 6 8 10