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 <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{ 2,5,7,1,1,9,3,6,1,2,2,6 };
- //itstep::print(10, '\t');
- //itstep::print(20, ' ');
- //itstep::print(30);
- //auto arrIt{ dynArr.begin() };
- //arrIt += 2;
- //std::cout << "dynArr[2] = " << *arrIt << '\n';
- //arrIt -= 1;
- //std::cout << "dynArr[1] = " << *arrIt << '\n';
- std::for_each(dynArr.cbegin(), dynArr.cend(), [](auto el) {itstep::print<int>(el, ' '); });
- std::cout << '\n';
- std::sort(dynArr.begin(), dynArr.end(), [](auto a, auto b) {return a % 2 == 0 and b % 2 != 0 ; });
- //auto uniqueEnd{std::unique(dynArr.begin(), dynArr.end())};
- //std::for_each(dynArr.begin(), uniqueEnd, [](auto el) {itstep::print<int>(el, ' '); });
- std::cout << '\n';
- std::for_each(dynArr.cbegin(), dynArr.cend(), [](auto el) {itstep::print<int>(el, ' '); });
- /*std::for_each(dynArr.rbegin(), dynArr.rend(), [](auto el) {itstep::print<int>(el, ' '); });
- std::cout << '\n';*/
- //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