- tmp/tmplgfq0quv/{from.md → to.md} +139 -68
tmp/tmplgfq0quv/{from.md → to.md}
RENAMED
|
@@ -23,10 +23,12 @@ public:
|
|
| 23 |
constexpr basic_string_view() noexcept;
|
| 24 |
constexpr basic_string_view(const basic_string_view&) noexcept = default;
|
| 25 |
constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default;
|
| 26 |
constexpr basic_string_view(const charT* str);
|
| 27 |
constexpr basic_string_view(const charT* str, size_type len);
|
|
|
|
|
|
|
| 28 |
|
| 29 |
// [string.view.iterators], iterator support
|
| 30 |
constexpr const_iterator begin() const noexcept;
|
| 31 |
constexpr const_iterator end() const noexcept;
|
| 32 |
constexpr const_iterator cbegin() const noexcept;
|
|
@@ -38,11 +40,11 @@ public:
|
|
| 38 |
|
| 39 |
// [string.view.capacity], capacity
|
| 40 |
constexpr size_type size() const noexcept;
|
| 41 |
constexpr size_type length() const noexcept;
|
| 42 |
constexpr size_type max_size() const noexcept;
|
| 43 |
-
constexpr bool empty() const noexcept;
|
| 44 |
|
| 45 |
// [string.view.access], element access
|
| 46 |
constexpr const_reference operator[](size_type pos) const;
|
| 47 |
constexpr const_reference at(size_type pos) const;
|
| 48 |
constexpr const_reference front() const;
|
|
@@ -53,29 +55,39 @@ public:
|
|
| 53 |
constexpr void remove_prefix(size_type n);
|
| 54 |
constexpr void remove_suffix(size_type n);
|
| 55 |
constexpr void swap(basic_string_view& s) noexcept;
|
| 56 |
|
| 57 |
// [string.view.ops], string operations
|
| 58 |
-
size_type copy(charT* s, size_type n, size_type pos = 0) const;
|
| 59 |
|
| 60 |
constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
|
|
|
|
| 61 |
constexpr int compare(basic_string_view s) const noexcept;
|
| 62 |
constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
|
| 63 |
constexpr int compare(size_type pos1, size_type n1, basic_string_view s,
|
| 64 |
size_type pos2, size_type n2) const;
|
| 65 |
constexpr int compare(const charT* s) const;
|
| 66 |
constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
|
| 67 |
-
constexpr int compare(size_type pos1, size_type n1, const charT* s,
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
|
| 70 |
constexpr size_type find(charT c, size_type pos = 0) const noexcept;
|
| 71 |
constexpr size_type find(const charT* s, size_type pos, size_type n) const;
|
| 72 |
constexpr size_type find(const charT* s, size_type pos = 0) const;
|
| 73 |
constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
|
| 74 |
constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
|
| 75 |
constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
|
| 76 |
constexpr size_type rfind(const charT* s, size_type pos = npos) const;
|
|
|
|
| 77 |
constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
|
| 78 |
constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
|
| 79 |
constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
|
| 80 |
constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
|
| 81 |
constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
|
|
@@ -96,73 +108,102 @@ public:
|
|
| 96 |
|
| 97 |
private:
|
| 98 |
const_pointer data_; // exposition only
|
| 99 |
size_type size_; // exposition only
|
| 100 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
```
|
| 102 |
|
| 103 |
In every specialization `basic_string_view<charT, traits>`, the type
|
| 104 |
-
`traits` shall
|
| 105 |
-
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
#### Construction and assignment <a id="string.view.cons">[[string.view.cons]]</a>
|
| 109 |
|
| 110 |
``` cpp
|
| 111 |
constexpr basic_string_view() noexcept;
|
| 112 |
```
|
| 113 |
|
| 114 |
-
*
|
| 115 |
-
|
| 116 |
-
*Postconditions:* `size_ == 0` and `data_ == nullptr`.
|
| 117 |
|
| 118 |
``` cpp
|
| 119 |
constexpr basic_string_view(const charT* str);
|
| 120 |
```
|
| 121 |
|
| 122 |
-
*
|
| 123 |
|
| 124 |
-
*Effects:* Constructs a `basic_string_view`,
|
| 125 |
-
|
| 126 |
|
| 127 |
*Complexity:* 𝑂(`traits::length(str)`).
|
| 128 |
|
| 129 |
``` cpp
|
| 130 |
constexpr basic_string_view(const charT* str, size_type len);
|
| 131 |
```
|
| 132 |
|
| 133 |
-
*
|
| 134 |
|
| 135 |
-
*Effects:* Constructs a `basic_string_view`,
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
#### Iterator support <a id="string.view.iterators">[[string.view.iterators]]</a>
|
| 139 |
|
| 140 |
``` cpp
|
| 141 |
using const_iterator = implementation-defined // type of basic_string_view::const_iterator;
|
| 142 |
```
|
| 143 |
|
| 144 |
-
A type that meets the requirements of a constant
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
| 148 |
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
pointers, iterators, and references returned from `str`’s methods.
|
| 152 |
-
|
| 153 |
-
All requirements on container iterators ([[container.requirements]])
|
| 154 |
-
apply to `basic_string_view::const_iterator` as well.
|
| 155 |
|
| 156 |
``` cpp
|
| 157 |
constexpr const_iterator begin() const noexcept;
|
| 158 |
constexpr const_iterator cbegin() const noexcept;
|
| 159 |
```
|
| 160 |
|
| 161 |
*Returns:* An iterator such that
|
| 162 |
|
| 163 |
-
- if `!empty()`, `
|
| 164 |
- otherwise, an unspecified value such that \[`begin()`, `end()`) is a
|
| 165 |
valid range.
|
| 166 |
|
| 167 |
``` cpp
|
| 168 |
constexpr const_iterator end() const noexcept;
|
|
@@ -187,15 +228,10 @@ constexpr const_reverse_iterator crend() const noexcept;
|
|
| 187 |
|
| 188 |
#### Capacity <a id="string.view.capacity">[[string.view.capacity]]</a>
|
| 189 |
|
| 190 |
``` cpp
|
| 191 |
constexpr size_type size() const noexcept;
|
| 192 |
-
```
|
| 193 |
-
|
| 194 |
-
*Returns:* `size_`.
|
| 195 |
-
|
| 196 |
-
``` cpp
|
| 197 |
constexpr size_type length() const noexcept;
|
| 198 |
```
|
| 199 |
|
| 200 |
*Returns:* `size_`.
|
| 201 |
|
|
@@ -205,22 +241,22 @@ constexpr size_type max_size() const noexcept;
|
|
| 205 |
|
| 206 |
*Returns:* The largest possible number of char-like objects that can be
|
| 207 |
referred to by a `basic_string_view`.
|
| 208 |
|
| 209 |
``` cpp
|
| 210 |
-
constexpr bool empty() const noexcept;
|
| 211 |
```
|
| 212 |
|
| 213 |
*Returns:* `size_ == 0`.
|
| 214 |
|
| 215 |
#### Element access <a id="string.view.access">[[string.view.access]]</a>
|
| 216 |
|
| 217 |
``` cpp
|
| 218 |
constexpr const_reference operator[](size_type pos) const;
|
| 219 |
```
|
| 220 |
|
| 221 |
-
*
|
| 222 |
|
| 223 |
*Returns:* `data_[pos]`.
|
| 224 |
|
| 225 |
*Throws:* Nothing.
|
| 226 |
|
|
@@ -238,21 +274,21 @@ constexpr const_reference at(size_type pos) const;
|
|
| 238 |
|
| 239 |
``` cpp
|
| 240 |
constexpr const_reference front() const;
|
| 241 |
```
|
| 242 |
|
| 243 |
-
*
|
| 244 |
|
| 245 |
*Returns:* `data_[0]`.
|
| 246 |
|
| 247 |
*Throws:* Nothing.
|
| 248 |
|
| 249 |
``` cpp
|
| 250 |
constexpr const_reference back() const;
|
| 251 |
```
|
| 252 |
|
| 253 |
-
*
|
| 254 |
|
| 255 |
*Returns:* `data_[size() - 1]`.
|
| 256 |
|
| 257 |
*Throws:* Nothing.
|
| 258 |
|
|
@@ -260,30 +296,31 @@ constexpr const_reference back() const;
|
|
| 260 |
constexpr const_pointer data() const noexcept;
|
| 261 |
```
|
| 262 |
|
| 263 |
*Returns:* `data_`.
|
| 264 |
|
| 265 |
-
[*Note 2*: Unlike `basic_string::data()` and string
|
| 266 |
-
may return a pointer to a buffer that is not null-terminated.
|
| 267 |
-
it is typically a mistake to pass `data()` to a function that
|
| 268 |
-
a `const charT*` and expects a null-terminated
|
|
|
|
| 269 |
|
| 270 |
#### Modifiers <a id="string.view.modifiers">[[string.view.modifiers]]</a>
|
| 271 |
|
| 272 |
``` cpp
|
| 273 |
constexpr void remove_prefix(size_type n);
|
| 274 |
```
|
| 275 |
|
| 276 |
-
*
|
| 277 |
|
| 278 |
*Effects:* Equivalent to: `data_ += n; size_ -= n;`
|
| 279 |
|
| 280 |
``` cpp
|
| 281 |
constexpr void remove_suffix(size_type n);
|
| 282 |
```
|
| 283 |
|
| 284 |
-
*
|
| 285 |
|
| 286 |
*Effects:* Equivalent to: `size_ -= n;`
|
| 287 |
|
| 288 |
``` cpp
|
| 289 |
constexpr void swap(basic_string_view& s) noexcept;
|
|
@@ -292,18 +329,18 @@ constexpr void swap(basic_string_view& s) noexcept;
|
|
| 292 |
*Effects:* Exchanges the values of `*this` and `s`.
|
| 293 |
|
| 294 |
#### String operations <a id="string.view.ops">[[string.view.ops]]</a>
|
| 295 |
|
| 296 |
``` cpp
|
| 297 |
-
size_type copy(charT* s, size_type n, size_type pos = 0) const;
|
| 298 |
```
|
| 299 |
|
| 300 |
Let `rlen` be the smaller of `n` and `size() - pos`.
|
| 301 |
|
| 302 |
*Throws:* `out_of_range` if `pos > size()`.
|
| 303 |
|
| 304 |
-
*
|
| 305 |
|
| 306 |
*Effects:* Equivalent to `traits::copy(s, data() + pos, rlen)`.
|
| 307 |
|
| 308 |
*Returns:* `rlen`.
|
| 309 |
|
|
@@ -334,13 +371,13 @@ compare. The function then compares the two strings by calling
|
|
| 334 |
|
| 335 |
*Complexity:* 𝑂(`rlen`).
|
| 336 |
|
| 337 |
*Returns:* The nonzero result if the result of the comparison is
|
| 338 |
nonzero. Otherwise, returns a value as indicated in
|
| 339 |
-
|
| 340 |
|
| 341 |
-
**Table: `compare()` results** <a id="
|
| 342 |
|
| 343 |
| Condition | Return Value |
|
| 344 |
| ---------------------- | ------------ |
|
| 345 |
| `size() < str.size()` | `< 0` |
|
| 346 |
| `size() == str.size()` | ` 0` |
|
|
@@ -372,50 +409,84 @@ constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
|
|
| 372 |
|
| 373 |
*Effects:* Equivalent to:
|
| 374 |
`return substr(pos1, n1).compare(basic_string_view(s));`
|
| 375 |
|
| 376 |
``` cpp
|
| 377 |
-
constexpr int compare(size_type pos1, size_type n1,
|
| 378 |
-
const charT* s, size_type n2) const;
|
| 379 |
```
|
| 380 |
|
| 381 |
*Effects:* Equivalent to:
|
| 382 |
`return substr(pos1, n1).compare(basic_string_view(s, n2));`
|
| 383 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
#### Searching <a id="string.view.find">[[string.view.find]]</a>
|
| 385 |
|
| 386 |
-
|
| 387 |
-
`
|
| 388 |
-
|
| 389 |
|
| 390 |
-
|
| 391 |
-
|
| 392 |
-
encouraged to do better.
|
| 393 |
-
|
| 394 |
-
Each member function of the form
|
| 395 |
|
|
|
|
| 396 |
``` cpp
|
| 397 |
-
constexpr return-type F(const charT* s, size_type pos);
|
| 398 |
```
|
| 399 |
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
Each member function of the form
|
| 403 |
-
|
| 404 |
``` cpp
|
| 405 |
-
constexpr return-type F(const charT* s, size_type pos, size_type n);
|
| 406 |
```
|
| 407 |
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
Each member function of the form
|
| 411 |
-
|
| 412 |
``` cpp
|
| 413 |
-
constexpr return-type F(charT c, size_type pos);
|
| 414 |
```
|
| 415 |
|
| 416 |
-
|
|
|
|
| 417 |
|
| 418 |
``` cpp
|
| 419 |
constexpr size_type find(basic_string_view str, size_type pos = 0) const noexcept;
|
| 420 |
```
|
| 421 |
|
|
|
|
| 23 |
constexpr basic_string_view() noexcept;
|
| 24 |
constexpr basic_string_view(const basic_string_view&) noexcept = default;
|
| 25 |
constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default;
|
| 26 |
constexpr basic_string_view(const charT* str);
|
| 27 |
constexpr basic_string_view(const charT* str, size_type len);
|
| 28 |
+
template<class It, class End>
|
| 29 |
+
constexpr basic_string_view(It begin, End end);
|
| 30 |
|
| 31 |
// [string.view.iterators], iterator support
|
| 32 |
constexpr const_iterator begin() const noexcept;
|
| 33 |
constexpr const_iterator end() const noexcept;
|
| 34 |
constexpr const_iterator cbegin() const noexcept;
|
|
|
|
| 40 |
|
| 41 |
// [string.view.capacity], capacity
|
| 42 |
constexpr size_type size() const noexcept;
|
| 43 |
constexpr size_type length() const noexcept;
|
| 44 |
constexpr size_type max_size() const noexcept;
|
| 45 |
+
[[nodiscard]] constexpr bool empty() const noexcept;
|
| 46 |
|
| 47 |
// [string.view.access], element access
|
| 48 |
constexpr const_reference operator[](size_type pos) const;
|
| 49 |
constexpr const_reference at(size_type pos) const;
|
| 50 |
constexpr const_reference front() const;
|
|
|
|
| 55 |
constexpr void remove_prefix(size_type n);
|
| 56 |
constexpr void remove_suffix(size_type n);
|
| 57 |
constexpr void swap(basic_string_view& s) noexcept;
|
| 58 |
|
| 59 |
// [string.view.ops], string operations
|
| 60 |
+
constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
|
| 61 |
|
| 62 |
constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
|
| 63 |
+
|
| 64 |
constexpr int compare(basic_string_view s) const noexcept;
|
| 65 |
constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
|
| 66 |
constexpr int compare(size_type pos1, size_type n1, basic_string_view s,
|
| 67 |
size_type pos2, size_type n2) const;
|
| 68 |
constexpr int compare(const charT* s) const;
|
| 69 |
constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
|
| 70 |
+
constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;
|
| 71 |
+
|
| 72 |
+
constexpr bool starts_with(basic_string_view x) const noexcept;
|
| 73 |
+
constexpr bool starts_with(charT x) const noexcept;
|
| 74 |
+
constexpr bool starts_with(const charT* x) const;
|
| 75 |
+
constexpr bool ends_with(basic_string_view x) const noexcept;
|
| 76 |
+
constexpr bool ends_with(charT x) const noexcept;
|
| 77 |
+
constexpr bool ends_with(const charT* x) const;
|
| 78 |
+
|
| 79 |
+
// [string.view.find], searching
|
| 80 |
constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
|
| 81 |
constexpr size_type find(charT c, size_type pos = 0) const noexcept;
|
| 82 |
constexpr size_type find(const charT* s, size_type pos, size_type n) const;
|
| 83 |
constexpr size_type find(const charT* s, size_type pos = 0) const;
|
| 84 |
constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
|
| 85 |
constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
|
| 86 |
constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
|
| 87 |
constexpr size_type rfind(const charT* s, size_type pos = npos) const;
|
| 88 |
+
|
| 89 |
constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
|
| 90 |
constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
|
| 91 |
constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
|
| 92 |
constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
|
| 93 |
constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
|
|
|
|
| 108 |
|
| 109 |
private:
|
| 110 |
const_pointer data_; // exposition only
|
| 111 |
size_type size_; // exposition only
|
| 112 |
};
|
| 113 |
+
|
| 114 |
+
// [string.view.deduct], deduction guide
|
| 115 |
+
template<class It, class End>
|
| 116 |
+
basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
|
| 117 |
```
|
| 118 |
|
| 119 |
In every specialization `basic_string_view<charT, traits>`, the type
|
| 120 |
+
`traits` shall meet the character traits requirements [[char.traits]].
|
| 121 |
+
|
| 122 |
+
[*Note 1*: The program is ill-formed if `traits::char_type` is not the
|
| 123 |
+
same type as `charT`. — *end note*]
|
| 124 |
+
|
| 125 |
+
For a `basic_string_view str`, any operation that invalidates a pointer
|
| 126 |
+
in the range \[`str.data()`, `str.data() + str.size()`) invalidates
|
| 127 |
+
pointers, iterators, and references returned from `str`’s member
|
| 128 |
+
functions.
|
| 129 |
+
|
| 130 |
+
The complexity of `basic_string_view` member functions is 𝑂(1) unless
|
| 131 |
+
otherwise specified.
|
| 132 |
|
| 133 |
#### Construction and assignment <a id="string.view.cons">[[string.view.cons]]</a>
|
| 134 |
|
| 135 |
``` cpp
|
| 136 |
constexpr basic_string_view() noexcept;
|
| 137 |
```
|
| 138 |
|
| 139 |
+
*Ensures:* `size_ == 0` and `data_ == nullptr`.
|
|
|
|
|
|
|
| 140 |
|
| 141 |
``` cpp
|
| 142 |
constexpr basic_string_view(const charT* str);
|
| 143 |
```
|
| 144 |
|
| 145 |
+
*Preconditions:* \[`str`, `str + traits::length(str)`) is a valid range.
|
| 146 |
|
| 147 |
+
*Effects:* Constructs a `basic_string_view`, initializing `data_` with
|
| 148 |
+
`str` and initializing `size_` with `traits::length(str)`.
|
| 149 |
|
| 150 |
*Complexity:* 𝑂(`traits::length(str)`).
|
| 151 |
|
| 152 |
``` cpp
|
| 153 |
constexpr basic_string_view(const charT* str, size_type len);
|
| 154 |
```
|
| 155 |
|
| 156 |
+
*Preconditions:* \[`str`, `str + len`) is a valid range.
|
| 157 |
|
| 158 |
+
*Effects:* Constructs a `basic_string_view`, initializing `data_` with
|
| 159 |
+
`str` and initializing `size_` with `len`.
|
| 160 |
+
|
| 161 |
+
``` cpp
|
| 162 |
+
template<class It, class End>
|
| 163 |
+
constexpr basic_string_view(It begin, End end);
|
| 164 |
+
```
|
| 165 |
+
|
| 166 |
+
*Constraints:*
|
| 167 |
+
|
| 168 |
+
- `It` satisfies `contiguous_iterator`.
|
| 169 |
+
- `End` satisfies `sized_sentinel_for<It>`.
|
| 170 |
+
- `is_same_v<iter_value_t<It>, charT>` is `true`.
|
| 171 |
+
- `is_convertible_v<End, size_type>` is `false`.
|
| 172 |
+
|
| 173 |
+
*Preconditions:*
|
| 174 |
+
|
| 175 |
+
- \[`begin`, `end`) is a valid range.
|
| 176 |
+
- `It` models `contiguous_iterator`.
|
| 177 |
+
- `End` models `sized_sentinel_for<It>`.
|
| 178 |
+
|
| 179 |
+
*Effects:* Initializes `data_` with `to_address(begin)` and initializes
|
| 180 |
+
`size_` with `end - begin`.
|
| 181 |
|
| 182 |
#### Iterator support <a id="string.view.iterators">[[string.view.iterators]]</a>
|
| 183 |
|
| 184 |
``` cpp
|
| 185 |
using const_iterator = implementation-defined // type of basic_string_view::const_iterator;
|
| 186 |
```
|
| 187 |
|
| 188 |
+
A type that meets the requirements of a constant
|
| 189 |
+
*Cpp17RandomAccessIterator*[[random.access.iterators]], models
|
| 190 |
+
`contiguous_iterator` [[iterator.concept.contiguous]], and meets the
|
| 191 |
+
constexpr iterator requirements [[iterator.requirements.general]], whose
|
| 192 |
+
`value_type` is the template parameter `charT`.
|
| 193 |
|
| 194 |
+
All requirements on container iterators [[container.requirements]] apply
|
| 195 |
+
to `basic_string_view::const_iterator` as well.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
|
| 197 |
``` cpp
|
| 198 |
constexpr const_iterator begin() const noexcept;
|
| 199 |
constexpr const_iterator cbegin() const noexcept;
|
| 200 |
```
|
| 201 |
|
| 202 |
*Returns:* An iterator such that
|
| 203 |
|
| 204 |
+
- if `!empty()`, `addressof(*begin()) == data_`,
|
| 205 |
- otherwise, an unspecified value such that \[`begin()`, `end()`) is a
|
| 206 |
valid range.
|
| 207 |
|
| 208 |
``` cpp
|
| 209 |
constexpr const_iterator end() const noexcept;
|
|
|
|
| 228 |
|
| 229 |
#### Capacity <a id="string.view.capacity">[[string.view.capacity]]</a>
|
| 230 |
|
| 231 |
``` cpp
|
| 232 |
constexpr size_type size() const noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
constexpr size_type length() const noexcept;
|
| 234 |
```
|
| 235 |
|
| 236 |
*Returns:* `size_`.
|
| 237 |
|
|
|
|
| 241 |
|
| 242 |
*Returns:* The largest possible number of char-like objects that can be
|
| 243 |
referred to by a `basic_string_view`.
|
| 244 |
|
| 245 |
``` cpp
|
| 246 |
+
[[nodiscard]] constexpr bool empty() const noexcept;
|
| 247 |
```
|
| 248 |
|
| 249 |
*Returns:* `size_ == 0`.
|
| 250 |
|
| 251 |
#### Element access <a id="string.view.access">[[string.view.access]]</a>
|
| 252 |
|
| 253 |
``` cpp
|
| 254 |
constexpr const_reference operator[](size_type pos) const;
|
| 255 |
```
|
| 256 |
|
| 257 |
+
*Preconditions:* `pos < size()`.
|
| 258 |
|
| 259 |
*Returns:* `data_[pos]`.
|
| 260 |
|
| 261 |
*Throws:* Nothing.
|
| 262 |
|
|
|
|
| 274 |
|
| 275 |
``` cpp
|
| 276 |
constexpr const_reference front() const;
|
| 277 |
```
|
| 278 |
|
| 279 |
+
*Preconditions:* `!empty()`.
|
| 280 |
|
| 281 |
*Returns:* `data_[0]`.
|
| 282 |
|
| 283 |
*Throws:* Nothing.
|
| 284 |
|
| 285 |
``` cpp
|
| 286 |
constexpr const_reference back() const;
|
| 287 |
```
|
| 288 |
|
| 289 |
+
*Preconditions:* `!empty()`.
|
| 290 |
|
| 291 |
*Returns:* `data_[size() - 1]`.
|
| 292 |
|
| 293 |
*Throws:* Nothing.
|
| 294 |
|
|
|
|
| 296 |
constexpr const_pointer data() const noexcept;
|
| 297 |
```
|
| 298 |
|
| 299 |
*Returns:* `data_`.
|
| 300 |
|
| 301 |
+
[*Note 2*: Unlike `basic_string::data()` and *string-literal*s,
|
| 302 |
+
`data()` may return a pointer to a buffer that is not null-terminated.
|
| 303 |
+
Therefore it is typically a mistake to pass `data()` to a function that
|
| 304 |
+
takes just a `const charT*` and expects a null-terminated
|
| 305 |
+
string. — *end note*]
|
| 306 |
|
| 307 |
#### Modifiers <a id="string.view.modifiers">[[string.view.modifiers]]</a>
|
| 308 |
|
| 309 |
``` cpp
|
| 310 |
constexpr void remove_prefix(size_type n);
|
| 311 |
```
|
| 312 |
|
| 313 |
+
*Preconditions:* `n <= size()`.
|
| 314 |
|
| 315 |
*Effects:* Equivalent to: `data_ += n; size_ -= n;`
|
| 316 |
|
| 317 |
``` cpp
|
| 318 |
constexpr void remove_suffix(size_type n);
|
| 319 |
```
|
| 320 |
|
| 321 |
+
*Preconditions:* `n <= size()`.
|
| 322 |
|
| 323 |
*Effects:* Equivalent to: `size_ -= n;`
|
| 324 |
|
| 325 |
``` cpp
|
| 326 |
constexpr void swap(basic_string_view& s) noexcept;
|
|
|
|
| 329 |
*Effects:* Exchanges the values of `*this` and `s`.
|
| 330 |
|
| 331 |
#### String operations <a id="string.view.ops">[[string.view.ops]]</a>
|
| 332 |
|
| 333 |
``` cpp
|
| 334 |
+
constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
|
| 335 |
```
|
| 336 |
|
| 337 |
Let `rlen` be the smaller of `n` and `size() - pos`.
|
| 338 |
|
| 339 |
*Throws:* `out_of_range` if `pos > size()`.
|
| 340 |
|
| 341 |
+
*Preconditions:* \[`s`, `s + rlen`) is a valid range.
|
| 342 |
|
| 343 |
*Effects:* Equivalent to `traits::copy(s, data() + pos, rlen)`.
|
| 344 |
|
| 345 |
*Returns:* `rlen`.
|
| 346 |
|
|
|
|
| 371 |
|
| 372 |
*Complexity:* 𝑂(`rlen`).
|
| 373 |
|
| 374 |
*Returns:* The nonzero result if the result of the comparison is
|
| 375 |
nonzero. Otherwise, returns a value as indicated in
|
| 376 |
+
[[string.view.compare]].
|
| 377 |
|
| 378 |
+
**Table: `compare()` results** <a id="string.view.compare">[string.view.compare]</a>
|
| 379 |
|
| 380 |
| Condition | Return Value |
|
| 381 |
| ---------------------- | ------------ |
|
| 382 |
| `size() < str.size()` | `< 0` |
|
| 383 |
| `size() == str.size()` | ` 0` |
|
|
|
|
| 409 |
|
| 410 |
*Effects:* Equivalent to:
|
| 411 |
`return substr(pos1, n1).compare(basic_string_view(s));`
|
| 412 |
|
| 413 |
``` cpp
|
| 414 |
+
constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;
|
|
|
|
| 415 |
```
|
| 416 |
|
| 417 |
*Effects:* Equivalent to:
|
| 418 |
`return substr(pos1, n1).compare(basic_string_view(s, n2));`
|
| 419 |
|
| 420 |
+
``` cpp
|
| 421 |
+
constexpr bool starts_with(basic_string_view x) const noexcept;
|
| 422 |
+
```
|
| 423 |
+
|
| 424 |
+
*Effects:* Equivalent to: `return substr(0, x.size()) == x;`
|
| 425 |
+
|
| 426 |
+
``` cpp
|
| 427 |
+
constexpr bool starts_with(charT x) const noexcept;
|
| 428 |
+
```
|
| 429 |
+
|
| 430 |
+
*Effects:* Equivalent to: `return !empty() && traits::eq(front(), x);`
|
| 431 |
+
|
| 432 |
+
``` cpp
|
| 433 |
+
constexpr bool starts_with(const charT* x) const;
|
| 434 |
+
```
|
| 435 |
+
|
| 436 |
+
*Effects:* Equivalent to: `return starts_with(basic_string_view(x));`
|
| 437 |
+
|
| 438 |
+
``` cpp
|
| 439 |
+
constexpr bool ends_with(basic_string_view x) const noexcept;
|
| 440 |
+
```
|
| 441 |
+
|
| 442 |
+
*Effects:* Equivalent to:
|
| 443 |
+
|
| 444 |
+
``` cpp
|
| 445 |
+
return size() >= x.size() && compare(size() - x.size(), npos, x) == 0;
|
| 446 |
+
```
|
| 447 |
+
|
| 448 |
+
``` cpp
|
| 449 |
+
constexpr bool ends_with(charT x) const noexcept;
|
| 450 |
+
```
|
| 451 |
+
|
| 452 |
+
*Effects:* Equivalent to: `return !empty() && traits::eq(back(), x);`
|
| 453 |
+
|
| 454 |
+
``` cpp
|
| 455 |
+
constexpr bool ends_with(const charT* x) const;
|
| 456 |
+
```
|
| 457 |
+
|
| 458 |
+
*Effects:* Equivalent to: `return ends_with(basic_string_view(x));`
|
| 459 |
+
|
| 460 |
#### Searching <a id="string.view.find">[[string.view.find]]</a>
|
| 461 |
|
| 462 |
+
Member functions in this subclause have complexity
|
| 463 |
+
𝑂(`size() * str.size()`) at worst, although implementations should do
|
| 464 |
+
better.
|
| 465 |
|
| 466 |
+
Let *F* be one of `find`, `rfind`, `find_first_of`, `find_last_of`,
|
| 467 |
+
`find_first_not_of`, and `find_last_not_of`.
|
|
|
|
|
|
|
|
|
|
| 468 |
|
| 469 |
+
- Each member function of the form
|
| 470 |
``` cpp
|
| 471 |
+
constexpr return-type F(const charT* s, size_type pos) const;
|
| 472 |
```
|
| 473 |
|
| 474 |
+
has effects equivalent to: `return F(basic_string_view(s), pos);`
|
| 475 |
+
- Each member function of the form
|
|
|
|
|
|
|
| 476 |
``` cpp
|
| 477 |
+
constexpr return-type F(const charT* s, size_type pos, size_type n) const;
|
| 478 |
```
|
| 479 |
|
| 480 |
+
has effects equivalent to: `return F(basic_string_view(s, n), pos);`
|
| 481 |
+
- Each member function of the form
|
|
|
|
|
|
|
| 482 |
``` cpp
|
| 483 |
+
constexpr return-type F(charT c, size_type pos) const noexcept;
|
| 484 |
```
|
| 485 |
|
| 486 |
+
has effects equivalent to:
|
| 487 |
+
`return F(basic_string_view(addressof(c), 1), pos);`
|
| 488 |
|
| 489 |
``` cpp
|
| 490 |
constexpr size_type find(basic_string_view str, size_type pos = 0) const noexcept;
|
| 491 |
```
|
| 492 |
|