[string.view.access]

# 27 Strings library [[strings]](./#strings)

## 27.3 String view classes [[string.view]](string.view#access)

### 27.3.3 Class template basic_string_view [[string.view.template]](string.view.template#string.view.access)

#### 27.3.3.6 Element access [string.view.access]

[ð](#lib:operator%5b%5d,basic_string_view)

`constexpr const_reference operator[](size_type pos) const;
`

[1](#1)

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

*Hardened preconditions*: pos < size() is true[.](#1.sentence-1)

[*Note [1](#note-1)*:

This precondition is stronger than the one on basic_string​::​operator[][.](#1.sentence-2)

â *end note*]

[2](#2)

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

*Returns*: *data_*[pos][.](#2.sentence-1)

[3](#3)

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

*Throws*: Nothing[.](#3.sentence-1)

[ð](#lib:at,basic_string_view)

`constexpr const_reference at(size_type pos) const;
`

[4](#4)

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

*Returns*: *data_*[pos][.](#4.sentence-1)

[5](#5)

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

*Throws*: out_of_range if pos >= size()[.](#5.sentence-1)

[ð](#lib:front,basic_string_view)

`constexpr const_reference front() const;
`

[6](#6)

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

*Hardened preconditions*: empty() is false[.](#6.sentence-1)

[7](#7)

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

*Returns*: *data_*[0][.](#7.sentence-1)

[8](#8)

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

*Throws*: Nothing[.](#8.sentence-1)

[ð](#lib:back,basic_string_view)

`constexpr const_reference back() const;
`

[9](#9)

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

*Hardened preconditions*: empty() is false[.](#9.sentence-1)

[10](#10)

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

*Returns*: *data_*[size() - 1][.](#10.sentence-1)

[11](#11)

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

*Throws*: Nothing[.](#11.sentence-1)

[ð](#lib:data,basic_string_view)

`constexpr const_pointer data() const noexcept;
`

[12](#12)

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

*Returns*: *data_*[.](#12.sentence-1)

[13](#13)

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

[*Note [2](#note-2)*:

Unlike basic_string​::​data() and [*string-literal*](lex.string#nt:string-literal "5.13.5 String literals [lex.string]")*s*,data() can return a pointer to a buffer that is not null-terminated[.](#13.sentence-1)

Therefore it is typically a mistake to pass data() to a function that takes just a const charT* and expects a null-terminated string[.](#13.sentence-2)

â *end note*]
