Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <forward_list>
- #include <functional>
- #include <algorithm>
- std::vector<int> dodajParzyste() {
- std::cout << "Dodaje parzyste\n";
- std::vector<int> wynik{ 2, 4, 6 };
- return wynik;
- }
- std::vector<int> dodajNieparzyste() {
- std::cout << "Dodaje nieparzyste\n";
- std::vector<int> wynik{ 1, 3, 5 };
- return wynik;
- }
- template <typename Container>
- void addElementsToContainer(Container& existing, Container&& added) {
- std::move(added.begin(), added.end(), std::back_inserter(existing));
- }
- int main() {
- std::forward_list<std::function<std::vector<int>()>> funkcje{};
- funkcje.push_front(dodajParzyste);
- funkcje.push_front(dodajNieparzyste);
- std::vector<int> liczby{};
- std::for_each(funkcje.begin(), funkcje.end(), [&liczby](const auto& func) {
- addElementsToContainer(liczby, func());
- });
- for (auto x : liczby) {
- std::cout << x << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement