|
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} |
|
2109 | 2108 | \pnum |
2110 | 2109 | \begin{example} |
2111 | 2110 | \begin{codeblock} |
2112 | | -for (int i : iota_view{1, 10}) |
| 2111 | +for (int i : views::iota(1, 10)) |
2113 | 2112 | cout << i << ' '; // prints: 1 2 3 4 5 6 7 8 9 |
2114 | 2113 | \end{codeblock} |
2115 | 2114 | \end{example} |
|
3353 | 3352 | \begin{example} |
3354 | 3353 | \begin{codeblock} |
3355 | 3354 | vector<int> is{ 0, 1, 2, 3, 4, 5, 6 }; |
3356 | | -filter_view evens{is, [](int i) { return 0 == i % 2; }}; |
| 3355 | +auto evens = views::filter(is, [](int i) { return 0 == i % 2; }); |
3357 | 3356 | for (int i : evens) |
3358 | 3357 | cout << i << ' '; // prints: 0 2 4 6 |
3359 | 3358 | \end{codeblock} |
|
3774 | 3773 | \begin{example} |
3775 | 3774 | \begin{codeblock} |
3776 | 3775 | vector<int> is{ 0, 1, 2, 3, 4 }; |
3777 | | -transform_view squares{is, [](int i) { return i * i; }}; |
| 3776 | +auto squares = views::transform(is, [](int i) { return i * i; }); |
3778 | 3777 | for (int i : squares) |
3779 | 3778 | cout << i << ' '; // prints: 0 1 4 9 16 |
3780 | 3779 | \end{codeblock} |
|
4487 | 4486 | \begin{example} |
4488 | 4487 | \begin{codeblock} |
4489 | 4488 | vector<int> is{0,1,2,3,4,5,6,7,8,9}; |
4490 | | -take_view few{is, 5}; |
4491 | | -for (int i : few) |
| 4489 | +for (int i : is | views::take(5)) |
4492 | 4490 | cout << i << ' '; // prints: 0 1 2 3 4 |
4493 | 4491 | \end{codeblock} |
4494 | 4492 | \end{example} |
|
4898 | 4896 | \begin{example} |
4899 | 4897 | \begin{codeblock} |
4900 | 4898 | auto ints = views::iota(0) | views::take(10); |
4901 | | -auto latter_half = drop_view{ints, 5}; |
4902 | | -for (auto i : latter_half) { |
| 4899 | +for (auto i : ints | views::drop(5)) { |
4903 | 4900 | cout << i << ' '; // prints \tcode{5 6 7 8 9} |
4904 | 4901 | } |
4905 | 4902 | \end{codeblock} |
|
5027 | 5024 | \begin{codeblock} |
5028 | 5025 | constexpr auto source = " \t \t \t hello there"; |
5029 | 5026 | auto is_invisible = [](const auto x) { return x == ' ' || x == '\t'; }; |
5030 | | -auto skip_ws = drop_while_view{source, is_invisible}; |
| 5027 | +auto skip_ws = views::drop_while(source, is_invisible); |
5031 | 5028 | for (auto c : skip_ws) { |
5032 | 5029 | cout << c; // prints \tcode{hello there} with no leading space |
5033 | 5030 | } |
|
5140 | 5137 | \begin{example} |
5141 | 5138 | \begin{codeblock} |
5142 | 5139 | vector<string> ss{"hello", " ", "world", "!"}; |
5143 | | -join_view greeting{ss}; |
5144 | | -for (char ch : greeting) |
| 5140 | +for (char ch : ss | views::join) |
5145 | 5141 | cout << ch; // prints: \tcode{hello world!} |
5146 | 5142 | \end{codeblock} |
5147 | 5143 | \end{example} |
|
5626 | 5622 | \begin{example} |
5627 | 5623 | \begin{codeblock} |
5628 | 5624 | string str{"the quick brown fox"}; |
5629 | | -lazy_split_view sentence{str, ' '}; |
5630 | | -for (auto word : sentence) { |
| 5625 | +for (auto word : str | views::lazy_split(' ')) { |
5631 | 5626 | for (char ch : word) |
5632 | 5627 | cout << ch; |
5633 | 5628 | cout << '*'; |
|
6533 | 6528 |
|
6534 | 6529 | template<@\libconcept{forward_range}@ R> |
6535 | 6530 | void my_algo(R&& r) { |
6536 | | - auto&& common = common_view{r}; |
| 6531 | + auto&& common = views::common(r); |
6537 | 6532 | auto cnt = count(common.begin(), common.end()); |
6538 | 6533 | // ... |
6539 | 6534 | } |
|
6658 | 6653 | \begin{example} |
6659 | 6654 | \begin{codeblock} |
6660 | 6655 | vector<int> is {0,1,2,3,4}; |
6661 | | -reverse_view rv {is}; |
6662 | | -for (int i : rv) |
| 6656 | +for (int i : is | views::reverse) |
6663 | 6657 | cout << i << ' '; // prints: 4 3 2 1 0 |
6664 | 6658 | \end{codeblock} |
6665 | 6659 | \end{example} |
|
6803 | 6797 |
|
6804 | 6798 | \begin{example} |
6805 | 6799 | \begin{codeblock} |
6806 | | -auto names = keys_view{historical_figures}; |
| 6800 | +auto names = historical_figures | views::keys; |
6807 | 6801 | for (auto&& name : names) { |
6808 | 6802 | cout << name << ' '; // prints \tcode{Babbage Hamilton Lovelace Turing } |
6809 | 6803 | } |
|
6817 | 6811 | \begin{example} |
6818 | 6812 | \begin{codeblock} |
6819 | 6813 | auto is_even = [](const auto x) { return x % 2 == 0; }; |
6820 | | -cout << ranges::count_if(values_view{historical_figures}, is_even); // prints \tcode{2} |
| 6814 | +cout << ranges::count_if(historical_figures | views::values, is_even); // prints \tcode{2} |
6821 | 6815 | \end{codeblock} |
6822 | 6816 | \end{example} |
6823 | 6817 |
|
|
0 commit comments