Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. std::vector<std::string> v = {...};
  2. my_func(v.begin(), v.end());
  3.  
  4. void my_func(??? i1, ??? i2)
  5. {
  6. std::for_each(i1, i2, ...); // dumb example implementation
  7. }
  8.  
  9. template <typename T>
  10. void my_func(T i1, T i2)
  11. {
  12. std::for_each(i1,i2,...); //dumb example implementation
  13. }
  14.  
  15. template <typename T, typename U>
  16. void my_func(T i1, U i2)
  17. {
  18. std::for_each(i1,i2,...); //dumb example implementation
  19. }
  20.  
  21. auto my_func = [](auto i1, auto i2)
  22. {
  23. std::for_each(i1,i2,...); //dumb example implementation
  24. };
  25.  
  26. template<typename Iterator>
  27. void my_func(Iterator startIter, const Iterator endIter)
  28. {
  29. std::for_each(startIter, endIter, /* lambda */);
  30. }
  31.  
  32. const auto defaultCallable = [](auto element){ }; // does nothing
  33. template<typename Iterator, typename Callable = decltype(defaultCallable)>
  34. void my_func(Iterator startIter, const Iterator endIter, Callable func = {})
  35. {
  36. std::for_each(startIter, endIter, func);
  37. }
  38.  
  39. template <template<typename...> class Iterable, typename T>
  40. void foo(
  41. const Iterable<T>& y // the container
  42. ){
  43. for (auto&& e : y){
  44. // e is the 'thingy' in the container.
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement