[string.access]

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

## 27.4 String classes [[string.classes]](string.classes#string.access)

### 27.4.3 Class template basic_string [[basic.string]](basic.string#string.access)

#### 27.4.3.6 Element access [string.access]

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

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

[1](#1)

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

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

[2](#2)

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

*Returns*: *(begin() + pos) if pos < size()[.](#2.sentence-1)

Otherwise,
returns a reference to an object of type charT with valuecharT(), where modifying the object to any value other thancharT() leads to undefined behavior[.](#2.sentence-2)

[3](#3)

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

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

[4](#4)

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

*Complexity*: Constant time[.](#4.sentence-1)

[ð](#lib:at,basic_string)

`constexpr const_reference at(size_type pos) const;
constexpr reference       at(size_type pos);
`

[5](#5)

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

*Returns*: operator[](pos)[.](#5.sentence-1)

[6](#6)

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

*Throws*: out_of_range ifpos >= size()[.](#6.sentence-1)

[ð](#lib:front,basic_string)

`constexpr const charT& front() const;
constexpr charT& front();
`

[7](#7)

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

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

[8](#8)

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

*Effects*: Equivalent to: return operator[](0);

[ð](#lib:back,basic_string)

`constexpr const charT& back() const;
constexpr charT& back();
`

[9](#9)

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

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

[10](#10)

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

*Effects*: Equivalent to: return operator[](size() - 1);
