[range.as.const.overview]

# 25 Ranges library [[ranges]](./#ranges)

## 25.7 Range adaptors [[range.adaptors]](range.adaptors#range.as.const.overview)

### 25.7.22 As const view [[range.as.const]](range.as.const#overview)

#### 25.7.22.1 Overview [range.as.const.overview]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L10028)

as_const_view presents a view of an underlying sequence as constant[.](#1.sentence-1)

That is, the elements of an as_const_view cannot be modified[.](#1.sentence-2)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L10032)

The name views​::​as_const denotes
a range adaptor object ([[range.adaptor.object]](range.adaptor.object "25.7.2 Range adaptor objects"))[.](#2.sentence-1)

Let E be an expression,
let T be decltype((E)), and
let U be remove_cvref_t<T>[.](#2.sentence-2)

The expression views​::​as_const(E) is expression-equivalent to:

- [(2.1)](#2.1)

  If views​::​all_t<T> models [constant_range](range.refinements#concept:constant_range "25.4.6 Other range refinements [range.refinements]"),
then views​::​all(E)[.](#2.1.sentence-1)

- [(2.2)](#2.2)

  Otherwise,
if U denotes empty_view<X> for some type X, then auto(views​::​empty<const X>)[.](#2.2.sentence-1)

- [(2.3)](#2.3)

  Otherwise,
if U denotes span<X, Extent> for some type X and some extent Extent,
then span<const X, Extent>(E)[.](#2.3.sentence-1)

- [(2.4)](#2.4)

  Otherwise,
if U denotes ref_view<X> for some type X andconst X models [constant_range](range.refinements#concept:constant_range "25.4.6 Other range refinements [range.refinements]"),
then ref_view(static_cast<const X&>(E.base()))[.](#2.4.sentence-1)

- [(2.5)](#2.5)

  Otherwise,
if E is an lvalue,const U models [constant_range](range.refinements#concept:constant_range "25.4.6 Other range refinements [range.refinements]"), andU does not model [view](range.view#concept:view "25.4.5 Views [range.view]"),
then ref_view(static_cast<const U&>(E))[.](#2.5.sentence-1)

- [(2.6)](#2.6)

  Otherwise, as_const_view(E)[.](#2.6.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L10067)

[*Example [1](#example-1)*: template<[constant_range](range.refinements#concept:constant_range "25.4.6 Other range refinements [range.refinements]") 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*]
