Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <memory>
- #include <array>
- #include <vector>
- #include <forward_list>
- #include <algorithm>
- #include <functional>
- namespace itstep
- {
- template <typename InIter, typename Func>
- void for_each(InIter begin, InIter end, Func func)
- {
- for (; begin != end; ++begin)
- {
- func(*begin);
- }
- }
- template <typename T>
- void print(const T& elem, char delimeter = '\0')
- {
- std::cout << elem;
- if (delimeter)
- {
- std::cout << delimeter;
- }
- }
- template <typename T>
- void mul2(T& elem)
- {
- elem *= 2;
- }
- }
- //void tester(void(*func)(int, int))
- //template<typename FuncType>
- //void tester(FuncType func)
- void tester(std::function<void(int, int)> func)
- {
- func(rand() % 10, rand() % 10);
- }
- void print3Num(int a, int b, int c)
- {
- std::cout << "a = " << a << " b = " << b << " c = " << c << '\n';
- }
- void wrapper(int a, int c) { print3Num(a, 55, c); }
- int main()
- {
- std::vector<int> dynArr{ 1,2,3,4,5,6,7,8,9,10 };
- //itstep::print(10, '\t');
- //itstep::print(20, ' ');
- //itstep::print(30);
- std::for_each(dynArr.begin(), dynArr.end(), [](auto el) {itstep::print<int>(el, '\t'); });
- std::for_each(dynArr.begin(), dynArr.end(), [](auto el) {itstep::print<int>(el, ' '); });
- //const int fixedVal{ 55 };
- ////tester(wrapper);
- //tester([fixedVal](int first, int second)->void { print3Num(first, fixedVal, second); });
- //tester([fixedVal](int first, int second)->void { print3Num(fixedVal, first, second); });
- //return 0;
- //using intFunct = int(*)(int, int);
- //auto maxL{ [](int a, int b) {return a > b ? a : b; } };
- //int x{ 42 };
- //int y{ 33 };
- //int z{ 77 };
- //auto numberPrinter{ [x,&y]()mutable -> void { std::cout << x++ << ' ' << y++ << '\n'; return ; } };
- //
- //// [&x,y,&z](){}
- //auto empty{ [z](int num, char sym, bool flag){ } };
- //
- //numberPrinter();
- //x = 442;
- //y = 333;
- //numberPrinter();
- //std::cout << "x = " << x << '\n';
- ////int(*fPtr)(int, int);
- //intFunct fPtr;
- //std::function<int(int, int)> funcPtr{ maxL };
- //fPtr = maxL;
- //auto copyMax{ maxL };
- //std::cout << funcPtr(10, 20) << '\n';
- //std::array<int, 10> staticArr;
- ////std::vector<int> dynArr{1,2,3,4,5,6,7,8,9,10};
- //std::forward_list<int> dynArr{ 1,2,3,4,5,6,7,8,9,10 };
- //auto begin{ dynArr.begin() };
- //auto end{ dynArr.end() };
- //auto printer{ [](auto& elem) { std::cout << elem << ' '; } };
- //itstep::for_each(dynArr.begin(), dynArr.end(), printer);
- //std::cout << '\n';
- //std::for_each(dynArr.begin(), dynArr.end(), [](auto& elem) { elem *= 2; });
- //std::cout << '\n';
- //std::for_each(dynArr.begin(), dynArr.end(), printer);
- // [] () {}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement