C++20 introduces views::all
which is a range adaptor that returns a view
that includes all elements of its range argument.
The expression views::all(E)
is expression-equivalent (has the same effect) to:
decay-copy(E)
if the decayed type ofE
modelsview
.- Otherwise,
ref_view{E}
if that expression is well-formed - Otherwise,
subrange{E}
The first case represents that a view
's type is not changed after being piped with views::all
(goldbot):
auto r = views::iota(0);
static_assert(std::same_as<decltype(r), decltype(r | views::all)>);
The second case is used to wrap a viewable_range
with ref_view
to facilitate range pipe operations:
int r[] = {0, 1, 2};
static_assert(std::same_as<ranges::ref_view<int[3]>, decltype(r | views::all)>);
But regarding the third case, I can't think of under what circumstances subrange{E}
is well-formed and ref_view{E}
is ill-formed.
What is its purpose? Can someone give an example of it?