|
1925 | 1925 | \pnum
|
1926 | 1926 | \begin{example}
|
1927 | 1927 | \begin{codeblock}
|
1928 |
| -empty_view<int> e; |
| 1928 | +auto e = views::empty<int>; |
1929 | 1929 | static_assert(ranges::empty(e));
|
1930 | 1930 | static_assert(0 == e.size());
|
1931 | 1931 | \end{codeblock}
|
|
1968 | 1968 | \pnum
|
1969 | 1969 | \begin{example}
|
1970 | 1970 | \begin{codeblock}
|
1971 |
| -single_view s{4}; |
1972 |
| -for (int i : s) |
| 1971 | +for (int i : views::single(4)) |
1973 | 1972 | cout << i; // prints \tcode{4}
|
1974 | 1973 | \end{codeblock}
|
1975 | 1974 | \end{example}
|
|
2106 | 2105 | \pnum
|
2107 | 2106 | \begin{example}
|
2108 | 2107 | \begin{codeblock}
|
2109 |
| -for (int i : iota_view{1, 10}) |
| 2108 | +for (int i : views::iota(1, 10)) |
2110 | 2109 | cout << i << ' '; // prints: 1 2 3 4 5 6 7 8 9
|
2111 | 2110 | \end{codeblock}
|
2112 | 2111 | \end{example}
|
|
3350 | 3349 | \begin{example}
|
3351 | 3350 | \begin{codeblock}
|
3352 | 3351 | vector<int> is{ 0, 1, 2, 3, 4, 5, 6 };
|
3353 |
| -filter_view evens{is, [](int i) { return 0 == i % 2; }}; |
| 3352 | +auto evens = views::filter(is, [](int i) { return 0 == i % 2; }); |
3354 | 3353 | for (int i : evens)
|
3355 | 3354 | cout << i << ' '; // prints: 0 2 4 6
|
3356 | 3355 | \end{codeblock}
|
|
3771 | 3770 | \begin{example}
|
3772 | 3771 | \begin{codeblock}
|
3773 | 3772 | vector<int> is{ 0, 1, 2, 3, 4 };
|
3774 |
| -transform_view squares{is, [](int i) { return i * i; }}; |
| 3773 | +auto squares = views::transform(is, [](int i) { return i * i; }); |
3775 | 3774 | for (int i : squares)
|
3776 | 3775 | cout << i << ' '; // prints: 0 1 4 9 16
|
3777 | 3776 | \end{codeblock}
|
|
4482 | 4481 | \begin{example}
|
4483 | 4482 | \begin{codeblock}
|
4484 | 4483 | vector<int> is{0,1,2,3,4,5,6,7,8,9};
|
4485 |
| -take_view few{is, 5}; |
4486 |
| -for (int i : few) |
| 4484 | +for (int i : is | views::take(5)) |
4487 | 4485 | cout << i << ' '; // prints: 0 1 2 3 4
|
4488 | 4486 | \end{codeblock}
|
4489 | 4487 | \end{example}
|
|
4891 | 4889 | \begin{example}
|
4892 | 4890 | \begin{codeblock}
|
4893 | 4891 | auto ints = views::iota(0) | views::take(10);
|
4894 |
| -auto latter_half = drop_view{ints, 5}; |
4895 |
| -for (auto i : latter_half) { |
| 4892 | +for (auto i : ints | views::drop(5)) { |
4896 | 4893 | cout << i << ' '; // prints \tcode{5 6 7 8 9}
|
4897 | 4894 | }
|
4898 | 4895 | \end{codeblock}
|
|
5020 | 5017 | \begin{codeblock}
|
5021 | 5018 | constexpr auto source = " \t \t \t hello there";
|
5022 | 5019 | auto is_invisible = [](const auto x) { return x == ' ' || x == '\t'; };
|
5023 |
| -auto skip_ws = drop_while_view{source, is_invisible}; |
| 5020 | +auto skip_ws = views::drop_while(source, is_invisible); |
5024 | 5021 | for (auto c : skip_ws) {
|
5025 | 5022 | cout << c; // prints \tcode{hello there} with no leading space
|
5026 | 5023 | }
|
|
5133 | 5130 | \begin{example}
|
5134 | 5131 | \begin{codeblock}
|
5135 | 5132 | vector<string> ss{"hello", " ", "world", "!"};
|
5136 |
| -join_view greeting{ss}; |
5137 |
| -for (char ch : greeting) |
| 5133 | +for (char ch : ss | views::join) |
5138 | 5134 | cout << ch; // prints: \tcode{hello world!}
|
5139 | 5135 | \end{codeblock}
|
5140 | 5136 | \end{example}
|
|
5619 | 5615 | \begin{example}
|
5620 | 5616 | \begin{codeblock}
|
5621 | 5617 | string str{"the quick brown fox"};
|
5622 |
| -lazy_split_view sentence{str, ' '}; |
5623 |
| -for (auto word : sentence) { |
| 5618 | +for (auto word : str | views::lazy_split(' ')) { |
5624 | 5619 | for (char ch : word)
|
5625 | 5620 | cout << ch;
|
5626 | 5621 | cout << '*';
|
|
6525 | 6520 |
|
6526 | 6521 | template<@\libconcept{forward_range}@ R>
|
6527 | 6522 | void my_algo(R&& r) {
|
6528 |
| - auto&& common = common_view{r}; |
| 6523 | + auto&& common = views::common(r); |
6529 | 6524 | auto cnt = count(common.begin(), common.end());
|
6530 | 6525 | // ...
|
6531 | 6526 | }
|
|
6650 | 6645 | \begin{example}
|
6651 | 6646 | \begin{codeblock}
|
6652 | 6647 | vector<int> is {0,1,2,3,4};
|
6653 |
| -reverse_view rv {is}; |
6654 |
| -for (int i : rv) |
| 6648 | +for (int i : is | views::reverse) |
6655 | 6649 | cout << i << ' '; // prints: 4 3 2 1 0
|
6656 | 6650 | \end{codeblock}
|
6657 | 6651 | \end{example}
|
|
6795 | 6789 |
|
6796 | 6790 | \begin{example}
|
6797 | 6791 | \begin{codeblock}
|
6798 |
| -auto names = keys_view{historical_figures}; |
| 6792 | +auto names = historical_figures | views::keys; |
6799 | 6793 | for (auto&& name : names) {
|
6800 | 6794 | cout << name << ' '; // prints \tcode{Babbage Hamilton Lovelace Turing }
|
6801 | 6795 | }
|
|
6809 | 6803 | \begin{example}
|
6810 | 6804 | \begin{codeblock}
|
6811 | 6805 | auto is_even = [](const auto x) { return x % 2 == 0; };
|
6812 |
| -cout << ranges::count_if(values_view{historical_figures}, is_even); // prints \tcode{2} |
| 6806 | +cout << ranges::count_if(historical_figures | views::values, is_even); // prints \tcode{2} |
6813 | 6807 | \end{codeblock}
|
6814 | 6808 | \end{example}
|
6815 | 6809 |
|
|
0 commit comments