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

125 lines
3.3 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[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.5String 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*]