Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::vector<std::string> v = {...};
- my_func(v.begin(), v.end());
- void my_func(??? i1, ??? i2)
- {
- std::for_each(i1, i2, ...); // dumb example implementation
- }
- template <typename T>
- void my_func(T i1, T i2)
- {
- std::for_each(i1,i2,...); //dumb example implementation
- }
- template <typename T, typename U>
- void my_func(T i1, U i2)
- {
- std::for_each(i1,i2,...); //dumb example implementation
- }
- auto my_func = [](auto i1, auto i2)
- {
- std::for_each(i1,i2,...); //dumb example implementation
- };
- template<typename Iterator>
- void my_func(Iterator startIter, const Iterator endIter)
- {
- std::for_each(startIter, endIter, /* lambda */);
- }
- const auto defaultCallable = [](auto element){ }; // does nothing
- template<typename Iterator, typename Callable = decltype(defaultCallable)>
- void my_func(Iterator startIter, const Iterator endIter, Callable func = {})
- {
- std::for_each(startIter, endIter, func);
- }
- template <template<typename...> class Iterable, typename T>
- void foo(
- const Iterable<T>& y // the container
- ){
- for (auto&& e : y){
- // e is the 'thingy' in the container.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement