Ranges
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1// C++ Vorlesung xxx
2// C++-20: Demo of ranges, view
3// Will: "The C++ Standard Library", §11
4
5/*
6 g++ -O3 -std=c++20 main.cpp
7 g++ -O3 -std=c++20 -pedantic -Weffc++ -Wall -Wextra -pedantic -Wswitch-default -Wfloat-equal -Wundef -Wredundant-decls -Winit-self -Wshadow -Wparentheses -Wshadow -Wunreachable-code -Wuninitialized -Wmaybe-uninitialized main.cpp
8 ---
9 cppcheck --enable=all --inconclusive --std=c++20 --suppress=missingIncludeSystem main.cpp
10 clang++ -O3 -std=c++20 main.cpp
11 clang++ -std=c++20 -fsyntax-only -Wdocumentation -Wconversion -Wshadow -Wfloat-conversion -pedantic main.cpp
12 clang++ -std=c++20 -Weverything -Wno-c++98-compat -Wno-padded main.cpp
13 clang++ -cc1 --help
14 ---
15 dpcpp -O3 -std=c++20 -Wall -Wextra -pedantic main.cpp
16 *
17*/
18
19#include <algorithm>
20#include <iostream>
21#include <vector>
22using namespace std;
23
24// Will: "The C++ Standard Library", §11
25#include <ranges>
26int main()
27{
28 vector<int> numbers{1,2,3,4,5,6};
29
30 auto results = numbers | std::views::filter ( [](int n){return n%2 == 0;} )
31 | std::views::transform ( [](int n){return n*2; } );
32
33 for (auto v:results) cout << v << " ";
34 cout << endl;
35 return 0;
36}
37
int main()
Definition main.cpp:26