Skip to content

[ranges] Improve examples #5791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions source/ranges.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2201,11 +2201,11 @@
\begin{example}
\begin{codeblock}
template<bool YieldElements>
std::generator<any> f(std::ranges::@\libconcept{input_range}@ auto&& r) {
generator<any> f(ranges::@\libconcept{input_range}@ auto&& r) {
if constexpr (YieldElements)
co_yield std::ranges::elements_of(r); // yield each element of \tcode{r}
co_yield ranges::elements_of(r); // yield each element of \tcode{r}
else
co_yield r; // yield \tcode{r} as a single value
co_yield r; // yield \tcode{r} as a single value
}
\end{codeblock}
\end{example}
Expand Down Expand Up @@ -3825,7 +3825,7 @@
\begin{example}
\begin{codeblock}
auto ints = istringstream{"0 1 2 3 4"};
ranges::copy(ranges::istream_view<int>(ints), ostream_iterator<int>{cout, "-"});
ranges::copy(views::istream<int>(ints), ostream_iterator<int>{cout, "-"});
// prints \tcode{0-1-2-3-4-}
\end{codeblock}
\end{example}
Expand Down Expand Up @@ -5919,7 +5919,7 @@
\begin{codeblock}
auto input = istringstream{"0 1 2 3 4 5 6 7 8 9"};
auto small = [](const auto x) noexcept { return x < 5; };
auto small_ints = istream_view<int>(input) | views::take_while(small);
auto small_ints = views::istream<int>(input) | views::take_while(small);
for (const auto i : small_ints) {
cout << i << ' '; // prints \tcode{0 1 2 3 4}
}
Expand Down Expand Up @@ -14251,9 +14251,9 @@
\pnum
\begin{example}
\begin{codeblock}
std::vector<int> v { 0, 1, 2 };
vector<int> v { 0, 1, 2 };
for (auto&& [a, b, c] : views::cartesian_product(v, v, v)) {
std::cout << a << ' ' << b << ' ' << c << '\n';
cout << a << ' ' << b << ' ' << c << '\n';
}
// The above prints
// \tcode{0 0 0}
Expand Down Expand Up @@ -15003,14 +15003,14 @@
is successively produced as an element of the sequence.
\begin{example}
\begin{codeblock}
std::generator<int> ints(int start = 0) {
generator<int> ints(int start = 0) {
while (true)
co_yield start++;
}

void f() {
for (auto i : ints() | std::views::take(3))
std::cout << i << ' '; // prints \tcode{0 1 2}
for (auto i : ints() | views::take(3))
cout << i << ' '; // prints \tcode{0 1 2}
}
\end{codeblock}
\end{example}
Expand Down