Guest User

Untitled

a guest
Aug 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. lambda with templates
  2. template <class in, class out, class T>
  3. out stransform(in b, in e, out d, T p(const T&)) {
  4. while (b != e)
  5. *d++ = p(*b++);
  6. return d;
  7. }
  8.  
  9. stransform(begin(vec1), end(vec1), back_inserter(vec2), predi<double>);
  10.  
  11. stransform(begin(vec1), end(vec1), back_inserter(vec2), [] (double x) ->double {return x * 10;} );
  12.  
  13. template <class in, class out, class UnaryPredicate>
  14. out stransform(in b, in e, out d, UnaryPredicate p);
  15.  
  16. stransform (
  17. begin (vec1),
  18. end (vec1),
  19. back_inserter (vec2),
  20. [] (const double & x) -> double {
  21. return x * 10;
  22. });
  23.  
  24. template<class InputIterator, class OutputIterator, class Functor>
  25. OutputIterator
  26. transform(InputIterator begin, InputIterator end, OutputIterator out, Functor f);
  27.  
  28. // function declaration
  29. int increment(int);
  30.  
  31. int array[] = { 0, 1, 2, 3, 4 };
  32. transform(std::begin(array), std::end(array), std::begin(array), increment);
  33.  
  34. template<typename InputIterator, typename OutputIterator, typename Functor>
  35. OutputIterator
  36. transform(InputIterator begin, InputIterator end, OutputIterator out, Functor f);
Add Comment
Please, Sign In to add comment