24
Ranges library
[ranges]
24.7
Range adaptors
[range.adaptors]
24.7.14
Common view
[range.common]
24.7.14.1
Overview
[range.common.overview]
1
#
common_view
takes a
view
which has different types for its iterator and sentinel and turns it into a
view
of the same elements with an iterator and sentinel of the same type
.
2
#
[
Note
1
:
common_view
is useful for calling legacy algorithms that expect a range's iterator and sentinel types to be the same
.
—
end note
]
3
#
The name
views
::
common
denotes a range adaptor object (
[range.
adaptor.
object]
)
.
Given a subexpression
E
, the expression
views
::
common
(
E
)
is expression-equivalent to:
(3.1)
views
::
all
(
E
)
, if
decltype
(
(
E
)
)
models
common_range
and
views
::
all
(
E
)
is a well-formed expression
.
(3.2)
Otherwise,
common_view
{
E
}
.
4
#
[
Example
1
:
// Legacy algorithm:
template
<
class
ForwardIterator
>
size_t count
(
ForwardIterator first, ForwardIterator last
)
;
template
<
forward_range
R
>
void
my_algo
(
R
&
&
r
)
{
auto
&
&
common
=
common_view
{
r
}
;
auto
cnt
=
count
(
common
.
begin
(
)
, common
.
end
(
)
)
;
// ...
}
—
end example
]