fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <functional>
  4.  
  5. template<typename T>
  6. void tripleElements(T& container)
  7. {
  8. typedef decltype(*std::begin(container)) value_type;
  9. typedef typename std::remove_reference<value_type>::type value_type_decayed;
  10.  
  11. std::transform(std::begin(container), std::end(container),std::begin(container),
  12. std::bind(std::multiplies<value_type_decayed>{}, std::placeholders::_1, 3));
  13. }
  14.  
  15. int main()
  16. {
  17. int t[] = { 3, 4, 5 };
  18. tripleElements(t);
  19.  
  20. for(auto e : t)
  21. std::cout << e << " ";
  22.  
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
9 12 15