Files
2025-10-25 03:02:53 +03:00

97 lines
2.6 KiB
Markdown

[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);