|
1892 | 1892 | \pnum
|
1893 | 1893 | \begin{example}
|
1894 | 1894 | \begin{codeblock}
|
1895 |
| -empty_view<int> e; |
| 1895 | +auto e = views::empty<int>; |
1896 | 1896 | static_assert(ranges::empty(e));
|
1897 | 1897 | static_assert(0 == e.size());
|
1898 | 1898 | \end{codeblock}
|
|
1935 | 1935 | \pnum
|
1936 | 1936 | \begin{example}
|
1937 | 1937 | \begin{codeblock}
|
1938 |
| -single_view s{4}; |
1939 |
| -for (int i : s) |
| 1938 | +for (int i : views::single(4)) |
1940 | 1939 | cout << i; // prints \tcode{4}
|
1941 | 1940 | \end{codeblock}
|
1942 | 1941 | \end{example}
|
|
2073 | 2072 | \pnum
|
2074 | 2073 | \begin{example}
|
2075 | 2074 | \begin{codeblock}
|
2076 |
| -for (int i : iota_view{1, 10}) |
| 2075 | +for (int i : views::iota(1, 10)) |
2077 | 2076 | cout << i << ' '; // prints: 1 2 3 4 5 6 7 8 9
|
2078 | 2077 | \end{codeblock}
|
2079 | 2078 | \end{example}
|
|
3187 | 3186 | \begin{example}
|
3188 | 3187 | \begin{codeblock}
|
3189 | 3188 | vector<int> is{ 0, 1, 2, 3, 4, 5, 6 };
|
3190 |
| -filter_view evens{is, [](int i) { return 0 == i % 2; }}; |
| 3189 | +auto evens = views::filter(is, [](int i) { return 0 == i % 2; }); |
3191 | 3190 | for (int i : evens)
|
3192 | 3191 | cout << i << ' '; // prints: 0 2 4 6
|
3193 | 3192 | \end{codeblock}
|
|
3610 | 3609 | \begin{example}
|
3611 | 3610 | \begin{codeblock}
|
3612 | 3611 | vector<int> is{ 0, 1, 2, 3, 4 };
|
3613 |
| -transform_view squares{is, [](int i) { return i * i; }}; |
| 3612 | +auto squares = views::transform(is, [](int i) { return i * i; }); |
3614 | 3613 | for (int i : squares)
|
3615 | 3614 | cout << i << ' '; // prints: 0 1 4 9 16
|
3616 | 3615 | \end{codeblock}
|
|
4340 | 4339 | \begin{example}
|
4341 | 4340 | \begin{codeblock}
|
4342 | 4341 | vector<int> is{0,1,2,3,4,5,6,7,8,9};
|
4343 |
| -take_view few{is, 5}; |
4344 |
| -for (int i : few) |
| 4342 | +for (int i : is | views::take(5)) |
4345 | 4343 | cout << i << ' '; // prints: 0 1 2 3 4
|
4346 | 4344 | \end{codeblock}
|
4347 | 4345 | \end{example}
|
|
4749 | 4747 | \begin{example}
|
4750 | 4748 | \begin{codeblock}
|
4751 | 4749 | auto ints = views::iota(0) | views::take(10);
|
4752 |
| -auto latter_half = drop_view{ints, 5}; |
4753 |
| -for (auto i : latter_half) { |
| 4750 | +for (auto i : ints | views::drop(5)) { |
4754 | 4751 | cout << i << ' '; // prints \tcode{5 6 7 8 9}
|
4755 | 4752 | }
|
4756 | 4753 | \end{codeblock}
|
|
4878 | 4875 | \begin{codeblock}
|
4879 | 4876 | constexpr auto source = " \t \t \t hello there";
|
4880 | 4877 | auto is_invisible = [](const auto x) { return x == ' ' || x == '\t'; };
|
4881 |
| -auto skip_ws = drop_while_view{source, is_invisible}; |
| 4878 | +auto skip_ws = views::drop_while(source, is_invisible); |
4882 | 4879 | for (auto c : skip_ws) {
|
4883 | 4880 | cout << c; // prints \tcode{hello there} with no leading space
|
4884 | 4881 | }
|
|
4991 | 4988 | \begin{example}
|
4992 | 4989 | \begin{codeblock}
|
4993 | 4990 | vector<string> ss{"hello", " ", "world", "!"};
|
4994 |
| -join_view greeting{ss}; |
4995 |
| -for (char ch : greeting) |
| 4991 | +for (char ch : ss | views::join) |
4996 | 4992 | cout << ch; // prints: \tcode{hello world!}
|
4997 | 4993 | \end{codeblock}
|
4998 | 4994 | \end{example}
|
|
5481 | 5477 | \begin{example}
|
5482 | 5478 | \begin{codeblock}
|
5483 | 5479 | string str{"the quick brown fox"};
|
5484 |
| -split_view sentence{str, ' '}; |
5485 |
| -for (auto word : sentence) { |
| 5480 | +for (auto word : str | views::split(' ')) { |
5486 | 5481 | for (char ch : word)
|
5487 | 5482 | cout << ch;
|
5488 | 5483 | cout << '*';
|
|
6057 | 6052 |
|
6058 | 6053 | template<@\libconcept{forward_range}@ R>
|
6059 | 6054 | void my_algo(R&& r) {
|
6060 |
| - auto&& common = common_view{r}; |
| 6055 | + auto&& common = views::common(r); |
6061 | 6056 | auto cnt = count(common.begin(), common.end());
|
6062 | 6057 | // ...
|
6063 | 6058 | }
|
|
6182 | 6177 | \begin{example}
|
6183 | 6178 | \begin{codeblock}
|
6184 | 6179 | vector<int> is {0,1,2,3,4};
|
6185 |
| -reverse_view rv {is}; |
6186 |
| -for (int i : rv) |
| 6180 | +for (int i : is | views::reverse) |
6187 | 6181 | cout << i << ' '; // prints: 4 3 2 1 0
|
6188 | 6182 | \end{codeblock}
|
6189 | 6183 | \end{example}
|
|
6327 | 6321 |
|
6328 | 6322 | \begin{example}
|
6329 | 6323 | \begin{codeblock}
|
6330 |
| -auto names = keys_view{historical_figures}; |
| 6324 | +auto names = historical_figures | views::keys; |
6331 | 6325 | for (auto&& name : names) {
|
6332 | 6326 | cout << name << ' '; // prints \tcode{Babbage Hamilton Lovelace Turing }
|
6333 | 6327 | }
|
|
6341 | 6335 | \begin{example}
|
6342 | 6336 | \begin{codeblock}
|
6343 | 6337 | auto is_even = [](const auto x) { return x % 2 == 0; };
|
6344 |
| -cout << ranges::count_if(values_view{historical_figures}, is_even); // prints \tcode{2} |
| 6338 | +cout << ranges::count_if(historical_figures | views::values, is_even); // prints \tcode{2} |
6345 | 6339 | \end{codeblock}
|
6346 | 6340 | \end{example}
|
6347 | 6341 |
|
|
0 commit comments