26
Ranges library
[ranges]
26.7
Range adaptors
[range.adaptors]
26.7.22
As const view
[range.as.const]
26.7.22.1
Overview
[range.as.const.overview]
1
#
as_
const_
view
presents a view of an underlying sequence as constant
.
That is, the elements of an
as_
const_
view
cannot be modified
.
2
#
The name
views
::
as_
const
denotes a range adaptor object (
[range.
adaptor.
object]
)
.
Let
E
be an expression, let
T
be
decltype
(
(
E
)
)
, and let
U
be
remove_
cvref_
t
<
T
>
.
The expression
views
::
as_
const
(
E
)
is expression-equivalent to:
(2.1)
If
views
::
all_
t
<
T
>
models
constant_
range
, then
views
::
all
(
E
)
.
(2.2)
Otherwise, if
U
denotes
empty_
view
<
X
>
for some type
X
, then
auto
(
views
::
empty
<
const
X
>
)
.
(2.3)
Otherwise, if
U
denotes
span
<
X, Extent
>
for some type
X
and some extent
Extent
, then
span
<
const
X, Extent
>
(
E
)
.
(2.4)
Otherwise, if
U
denotes
ref_
view
<
X
>
for some type
X
and
const
X
models
constant_
range
, then
ref_
view
(
static_
cast
<
const
X
&
>
(
E
.
base
(
)
)
)
.
(2.5)
Otherwise, if
E
is an lvalue,
const
U
models
constant_
range
, and
U
does not model
view
, then
ref_
view
(
static_
cast
<
const
U
&
>
(
E
)
)
.
(2.6)
Otherwise,
as_
const_
view
(
E
)
.
3
#
[
Example
1
:
template
<
constant_
range
R
>
void
cant_touch_this
(
R
&
&
)
; vector
<
char
>
hammer
=
{
'm'
,
'c'
}
; span
<
char
>
beat
=
hammer; cant_touch_this
(
views
::
as_const
(
beat
)
)
;
// will not modify the elements of
hammer
—
end example
]