//=============================================================================

#include <array>
#include <algorithm>
#include <execution>
#include <concepts>
#include <numeric>
#include <iostream>
#include <string>
#include <memory>
#include <unordered_map>
#include <vector>
#include <tuple>
#include <list>
#include <deque>
using namespace std;

void print(int x)
{
   cout << x << '-';
}

struct Print
{
   void operator()(int x) const
   {
      cout << x << '_';
   }
};

int main()
{
   cout << "FH2022 Oktober\n\n";

   vector<int> v{ 1,2,3,5,7,11,13 };
   cout << v.size() << '\n';

   for (int i = 20; i < 35; ++i) v.push_back(i);
   //for (int i = 20; i < 35; ++i) v.push_front(i);

   cout << v.size() << '\n';
   for (vector<int>::const_iterator it = cbegin(v); it != cend(v); ++it)
   {
      cout << *it << ',';
      //(*it)++;
   }
   cout << '\n';

   for (auto it = cbegin(v); it != cend(v); ++it)
   {
      cout << *it << ',';
   }
   cout << '\n';

   int res = 0;
   for (auto it = cbegin(v); it != cend(v); ++it)
   {
      res += *it;
   }
   cout << "Summe: " << res << '\n';

   res = accumulate(cbegin(v), cend(v), 0);
   cout << "Summe: " << res << '\n';

   sort(execution::par, rbegin(v) + 3, rend(v) - 2);
   for (auto it = cbegin(v); it != cend(v); ++it)
   {
      cout << *it << ',';
   }
   cout << '\n';

   for_each(cbegin(v), cend(v), print);
   cout << '\n';

   for_each(cbegin(v), cend(v), Print{});
   cout << '\n';

   for_each(cbegin(v), cend(v), [](int x) { cout << x << '#'; });
   cout << '\n';

   vector<string> vs{ "Tom", "Marcel", "Karl-Heinrich", "Lars" };
   sort(begin(vs), end(vs), [](auto s1, auto s2) { return s1.length() < s2.length(); });
   for_each(cbegin(vs), cend(vs), [](auto x) { cout << x << ','; });
   cout << '\n';


   auto vxx = vs
      | views::transform([](auto s) { return s + "22"; })
      | views::filter([](auto s) { return s.length() > 7; });

   for (auto x : vxx)  // No raw loop
   {
      cout << x << ", ";
   }
   cout << '\n';

   for (auto it = cbegin(vs); it != cend(vs); ++it)
   {
      cout << *it << ' ' << (*it).length() << '\n';
      cout << *it << ' ' << it->length() << '\n';
   }

   deque<int> dq{ 1,2,3,4,5,6,7 };
   for (auto x : dq)  // No raw loop
   {
      cout << x << ", ";
   }
   cout << '\n';

   array<int, 4> a{ 1,2,3 };  // Aufgefüllt mit Null-Bytes
   for_each(cbegin(a), cend(a), [](int x) { cout << x << ','; });
   cout << '\n';

   array<int, 50'000> a2;  // Zufaellige Startwerte
   for_each(cbegin(a2), cend(a2), [](int x) { cout << x << ','; });
   cout << '\n';
}
