Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <list>
- #include <algorithm>
- template <typename ElemType>
- class Printer
- {
- std::ostream& out;
- char delimiter;
- public:
- Printer(std::ostream& outP, char delimiterP) : out{ outP }, delimiter{ delimiterP } {};
- Printer() :Printer{ std::cout, '\0' } {};
- Printer(char delimiterP) : Printer{ std::cout, delimiterP } {};
- void operator()(const ElemType& elem) const
- {
- out << elem;
- if (delimiter) out << delimiter;
- };
- };
- class Numerator
- {
- int curr;
- int delta;
- static int sumCnt;
- public:
- Numerator(int startP, int deltaP) : curr{ startP }, delta{ deltaP }{};
- Numerator() : Numerator{ 0,1 } {};
- int operator()()
- {
- ++sumCnt;
- int ret{ curr };
- curr += delta;
- return ret;
- }
- static int getSumCnt() { return sumCnt; };
- };
- int Numerator::sumCnt{ 0 };
- int main()
- {
- std::vector<int> arr(10);
- std::vector<int> arr1(20);
- std::list<char> symbols{ 'a','s','d','a','s','x','v' };
- Printer<int> printer{ ' ' };
- Printer<int> printerNl{ '\n' };
- /*std::for_each(arr.begin(), arr.end(),
- [](auto& el) { el = rand() % 10; std::cout << el << ' '; });*/
- int cnt{ 1 };
- int delta{ 2 };
- Numerator num{1,3};
- Numerator num2x2{ 2,2 };
- //std::generate(arr.begin(), arr.end(), [&]() { return cnt+=delta; });
- std::generate(arr.begin(), arr.end(), num);
- std::cout << '\n';
- std::copy(arr.begin(), arr.end(), std::ostream_iterator<int>(std::cout, " ")); std::cout << '\n';
- std::cout << '\n';
- std::generate(arr1.begin(), arr1.end(), num2x2);
- std::cout << '\n';
- std::copy(arr1.begin(), arr1.end(), std::ostream_iterator<int>(std::cout, " ")); std::cout << '\n';
- std::cout << "Totally Numerated elements: " << Numerator::getSumCnt() << '\n';
- /*auto it{ arr.begin() };
- while ((it = std::find(it, arr.end(), 1)) != arr.end())
- {
- std::cout << "res is: " << std::distance(arr.begin(), it) << " <=> " << *it << '\n';
- ++it;
- }*/
- //std::copy(arr.begin(), arr.end(), std::ostream_iterator<int>(std::cout, " ")); std::cout << '\n';
- //std::cout << '\n';
- //std::stable_partition(arr.begin(), arr.end(), [](int el) { return el % 2; });
- //std::copy(arr.begin(), arr.end(), std::ostream_iterator<int>(std::cout, " ")); std::cout << '\n';
- //std::cout << '\n';
- //auto res{ std::find(arr.begin(), arr.end(), 0)};
- //auto res{ std::count_if(arr.begin(), arr.end(),[](int el) { return (el % 2 == 0) and (el > 5); }) };
- /*if (res != arr.end())
- {
- std::cout << "res is: " << std::distance(arr.begin(), res) << " <=> " << *res << '\n';
- }
- else
- {
- std::cout << "Not FOUND!!\n";
- }*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement