- tmp/tmpqo809kre/{from.md → to.md} +102 -34
tmp/tmpqo809kre/{from.md → to.md}
RENAMED
|
@@ -1,19 +1,21 @@
|
|
| 1 |
## String view classes <a id="string.view">[[string.view]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
The class template `basic_string_view` describes an object that can
|
| 4 |
refer to a constant contiguous sequence of char-like [[strings.general]]
|
| 5 |
objects with the first element of the sequence at position zero. In the
|
| 6 |
-
rest of
|
| 7 |
`basic_string_view` object is designated by `charT`.
|
| 8 |
|
| 9 |
[*Note 1*: The library provides implicit conversions from
|
| 10 |
`const charT*` and `std::basic_string<charT, ...>` to
|
| 11 |
`std::basic_string_view<charT, ...>` so that user code can accept just
|
| 12 |
`std::basic_string_view<charT>` as a non-templated parameter wherever a
|
| 13 |
-
sequence of characters is expected. User-defined types
|
| 14 |
-
|
| 15 |
interoperate with these functions. — *end note*]
|
| 16 |
|
| 17 |
### Header `<string_view>` synopsis <a id="string.view.synop">[[string.view.synop]]</a>
|
| 18 |
|
| 19 |
``` cpp
|
|
@@ -23,13 +25,13 @@ namespace std {
|
|
| 23 |
// [string.view.template], class template basic_string_view
|
| 24 |
template<class charT, class traits = char_traits<charT>>
|
| 25 |
class basic_string_view;
|
| 26 |
|
| 27 |
template<class charT, class traits>
|
| 28 |
-
|
| 29 |
template<class charT, class traits>
|
| 30 |
-
|
| 31 |
|
| 32 |
// [string.view.comparison], non-member comparison functions
|
| 33 |
template<class charT, class traits>
|
| 34 |
constexpr bool operator==(basic_string_view<charT, traits> x,
|
| 35 |
basic_string_view<charT, traits> y) noexcept;
|
|
@@ -43,11 +45,11 @@ namespace std {
|
|
| 43 |
template<class charT, class traits>
|
| 44 |
basic_ostream<charT, traits>&
|
| 45 |
operator<<(basic_ostream<charT, traits>& os,
|
| 46 |
basic_string_view<charT, traits> str);
|
| 47 |
|
| 48 |
-
// basic_string_view typedef
|
| 49 |
using string_view = basic_string_view<char>;
|
| 50 |
using u8string_view = basic_string_view<char8_t>;
|
| 51 |
using u16string_view = basic_string_view<char16_t>;
|
| 52 |
using u32string_view = basic_string_view<char32_t>;
|
| 53 |
using wstring_view = basic_string_view<wchar_t>;
|
|
@@ -76,11 +78,14 @@ namespace std {
|
|
| 76 |
The function templates defined in [[utility.swap]] and
|
| 77 |
[[iterator.range]] are available when `<string_view>` is included.
|
| 78 |
|
| 79 |
### Class template `basic_string_view` <a id="string.view.template">[[string.view.template]]</a>
|
| 80 |
|
|
|
|
|
|
|
| 81 |
``` cpp
|
|
|
|
| 82 |
template<class charT, class traits = char_traits<charT>>
|
| 83 |
class basic_string_view {
|
| 84 |
public:
|
| 85 |
// types
|
| 86 |
using traits_type = traits;
|
|
@@ -88,11 +93,11 @@ public:
|
|
| 88 |
using pointer = value_type*;
|
| 89 |
using const_pointer = const value_type*;
|
| 90 |
using reference = value_type&;
|
| 91 |
using const_reference = const value_type&;
|
| 92 |
using const_iterator = implementation-defined // type of basic_string_view::const_iterator; // see [string.view.iterators]
|
| 93 |
-
|
| 94 |
using const_reverse_iterator = reverse_iterator<const_iterator>;
|
| 95 |
using reverse_iterator = const_reverse_iterator;
|
| 96 |
using size_type = size_t;
|
| 97 |
using difference_type = ptrdiff_t;
|
| 98 |
static constexpr size_type npos = size_type(-1);
|
|
@@ -100,13 +105,16 @@ public:
|
|
| 100 |
// [string.view.cons], construction and assignment
|
| 101 |
constexpr basic_string_view() noexcept;
|
| 102 |
constexpr basic_string_view(const basic_string_view&) noexcept = default;
|
| 103 |
constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default;
|
| 104 |
constexpr basic_string_view(const charT* str);
|
|
|
|
| 105 |
constexpr basic_string_view(const charT* str, size_type len);
|
| 106 |
template<class It, class End>
|
| 107 |
constexpr basic_string_view(It begin, End end);
|
|
|
|
|
|
|
| 108 |
|
| 109 |
// [string.view.iterators], iterator support
|
| 110 |
constexpr const_iterator begin() const noexcept;
|
| 111 |
constexpr const_iterator end() const noexcept;
|
| 112 |
constexpr const_iterator cbegin() const noexcept;
|
|
@@ -152,10 +160,14 @@ public:
|
|
| 152 |
constexpr bool starts_with(const charT* x) const;
|
| 153 |
constexpr bool ends_with(basic_string_view x) const noexcept;
|
| 154 |
constexpr bool ends_with(charT x) const noexcept;
|
| 155 |
constexpr bool ends_with(const charT* x) const;
|
| 156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
// [string.view.find], searching
|
| 158 |
constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
|
| 159 |
constexpr size_type find(charT c, size_type pos = 0) const noexcept;
|
| 160 |
constexpr size_type find(const charT* s, size_type pos, size_type n) const;
|
| 161 |
constexpr size_type find(const charT* s, size_type pos = 0) const;
|
|
@@ -187,29 +199,42 @@ public:
|
|
| 187 |
private:
|
| 188 |
const_pointer data_; // exposition only
|
| 189 |
size_type size_; // exposition only
|
| 190 |
};
|
| 191 |
|
| 192 |
-
// [string.view.deduct], deduction
|
| 193 |
template<class It, class End>
|
| 194 |
basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
|
|
|
|
|
|
|
|
|
|
| 195 |
```
|
| 196 |
|
|
|
|
|
|
|
| 197 |
In every specialization `basic_string_view<charT, traits>`, the type
|
| 198 |
`traits` shall meet the character traits requirements [[char.traits]].
|
| 199 |
|
| 200 |
[*Note 1*: The program is ill-formed if `traits::char_type` is not the
|
| 201 |
same type as `charT`. — *end note*]
|
| 202 |
|
| 203 |
For a `basic_string_view str`, any operation that invalidates a pointer
|
| 204 |
-
in the range
|
| 205 |
-
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
The complexity of `basic_string_view` member functions is 𝑂(1) unless
|
| 209 |
otherwise specified.
|
| 210 |
|
|
|
|
|
|
|
|
|
|
| 211 |
#### Construction and assignment <a id="string.view.cons">[[string.view.cons]]</a>
|
| 212 |
|
| 213 |
``` cpp
|
| 214 |
constexpr basic_string_view() noexcept;
|
| 215 |
```
|
|
@@ -255,10 +280,53 @@ template<class It, class End>
|
|
| 255 |
- `End` models `sized_sentinel_for<It>`.
|
| 256 |
|
| 257 |
*Effects:* Initializes `data_` with `to_address(begin)` and initializes
|
| 258 |
`size_` with `end - begin`.
|
| 259 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
#### Iterator support <a id="string.view.iterators">[[string.view.iterators]]</a>
|
| 261 |
|
| 262 |
``` cpp
|
| 263 |
using const_iterator = implementation-defined // type of basic_string_view::const_iterator;
|
| 264 |
```
|
|
@@ -344,14 +412,14 @@ of returning `charT()`. — *end note*]
|
|
| 344 |
|
| 345 |
``` cpp
|
| 346 |
constexpr const_reference at(size_type pos) const;
|
| 347 |
```
|
| 348 |
|
|
|
|
|
|
|
| 349 |
*Throws:* `out_of_range` if `pos >= size()`.
|
| 350 |
|
| 351 |
-
*Returns:* `data_[pos]`.
|
| 352 |
-
|
| 353 |
``` cpp
|
| 354 |
constexpr const_reference front() const;
|
| 355 |
```
|
| 356 |
|
| 357 |
*Preconditions:* `!empty()`.
|
|
@@ -375,11 +443,11 @@ constexpr const_pointer data() const noexcept;
|
|
| 375 |
```
|
| 376 |
|
| 377 |
*Returns:* `data_`.
|
| 378 |
|
| 379 |
[*Note 2*: Unlike `basic_string::data()` and *string-literal*s,
|
| 380 |
-
`data()`
|
| 381 |
Therefore it is typically a mistake to pass `data()` to a function that
|
| 382 |
takes just a `const charT*` and expects a null-terminated
|
| 383 |
string. — *end note*]
|
| 384 |
|
| 385 |
#### Modifiers <a id="string.view.modifiers">[[string.view.modifiers]]</a>
|
|
@@ -412,45 +480,43 @@ constexpr void swap(basic_string_view& s) noexcept;
|
|
| 412 |
constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
|
| 413 |
```
|
| 414 |
|
| 415 |
Let `rlen` be the smaller of `n` and `size() - pos`.
|
| 416 |
|
| 417 |
-
*Throws:* `out_of_range` if `pos > size()`.
|
| 418 |
-
|
| 419 |
*Preconditions:* \[`s`, `s + rlen`) is a valid range.
|
| 420 |
|
| 421 |
*Effects:* Equivalent to `traits::copy(s, data() + pos, rlen)`.
|
| 422 |
|
| 423 |
*Returns:* `rlen`.
|
| 424 |
|
|
|
|
|
|
|
| 425 |
*Complexity:* 𝑂(`rlen`).
|
| 426 |
|
| 427 |
``` cpp
|
| 428 |
constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
|
| 429 |
```
|
| 430 |
|
| 431 |
Let `rlen` be the smaller of `n` and `size() - pos`.
|
| 432 |
|
| 433 |
-
*Throws:* `out_of_range` if `pos > size()`.
|
| 434 |
-
|
| 435 |
*Effects:* Determines `rlen`, the effective length of the string to
|
| 436 |
reference.
|
| 437 |
|
| 438 |
*Returns:* `basic_string_view(data() + pos, rlen)`.
|
| 439 |
|
|
|
|
|
|
|
| 440 |
``` cpp
|
| 441 |
constexpr int compare(basic_string_view str) const noexcept;
|
| 442 |
```
|
| 443 |
|
| 444 |
Let `rlen` be the smaller of `size()` and `str.size()`.
|
| 445 |
|
| 446 |
*Effects:* Determines `rlen`, the effective length of the strings to
|
| 447 |
compare. The function then compares the two strings by calling
|
| 448 |
`traits::compare(data(), str.data(), rlen)`.
|
| 449 |
|
| 450 |
-
*Complexity:* 𝑂(`rlen`).
|
| 451 |
-
|
| 452 |
*Returns:* The nonzero result if the result of the comparison is
|
| 453 |
nonzero. Otherwise, returns a value as indicated in
|
| 454 |
[[string.view.compare]].
|
| 455 |
|
| 456 |
**Table: `compare()` results** <a id="string.view.compare">[string.view.compare]</a>
|
|
@@ -459,10 +525,13 @@ nonzero. Otherwise, returns a value as indicated in
|
|
| 459 |
| ---------------------- | ------------ |
|
| 460 |
| `size() < str.size()` | `< 0` |
|
| 461 |
| `size() == str.size()` | ` 0` |
|
| 462 |
| `size() > str.size()` | `> 0` |
|
| 463 |
|
|
|
|
|
|
|
|
|
|
| 464 |
``` cpp
|
| 465 |
constexpr int compare(size_type pos1, size_type n1, basic_string_view str) const;
|
| 466 |
```
|
| 467 |
|
| 468 |
*Effects:* Equivalent to: `return substr(pos1, n1).compare(str);`
|
|
@@ -533,10 +602,18 @@ constexpr bool ends_with(charT x) const noexcept;
|
|
| 533 |
constexpr bool ends_with(const charT* x) const;
|
| 534 |
```
|
| 535 |
|
| 536 |
*Effects:* Equivalent to: `return ends_with(basic_string_view(x));`
|
| 537 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 538 |
#### Searching <a id="string.view.find">[[string.view.find]]</a>
|
| 539 |
|
| 540 |
Member functions in this subclause have complexity
|
| 541 |
𝑂(`size() * str.size()`) at worst, although implementations should do
|
| 542 |
better.
|
|
@@ -664,22 +741,10 @@ conditions hold:
|
|
| 664 |
*Effects:* Determines `xpos`.
|
| 665 |
|
| 666 |
*Returns:* `xpos` if the function can determine such a value for `xpos`.
|
| 667 |
Otherwise, returns `npos`.
|
| 668 |
|
| 669 |
-
### Deduction guide <a id="string.view.deduct">[[string.view.deduct]]</a>
|
| 670 |
-
|
| 671 |
-
``` cpp
|
| 672 |
-
template<class It, class End>
|
| 673 |
-
basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
|
| 674 |
-
```
|
| 675 |
-
|
| 676 |
-
*Constraints:*
|
| 677 |
-
|
| 678 |
-
- `It` satisfies `contiguous_iterator`.
|
| 679 |
-
- `End` satisfies `sized_sentinel_for<It>`.
|
| 680 |
-
|
| 681 |
### Non-member comparison functions <a id="string.view.comparison">[[string.view.comparison]]</a>
|
| 682 |
|
| 683 |
Let `S` be `basic_string_view<charT, traits>`, and `sv` be an instance
|
| 684 |
of `S`. Implementations shall provide sufficient additional overloads
|
| 685 |
marked `constexpr` and `noexcept` so that an object `t` with an implicit
|
|
@@ -737,12 +802,15 @@ template<class charT, class traits>
|
|
| 737 |
template<class charT, class traits>
|
| 738 |
constexpr see below operator<=>(basic_string_view<charT, traits> lhs,
|
| 739 |
\itcorr basic_string_view<charT, traits> rhs) noexcept;
|
| 740 |
```
|
| 741 |
|
| 742 |
-
Let `R` denote the type `traits::comparison_category` if
|
| 743 |
-
|
|
|
|
|
|
|
|
|
|
| 744 |
|
| 745 |
*Returns:* `static_cast<R>(lhs.compare(rhs) <=> 0)`.
|
| 746 |
|
| 747 |
### Inserters and extractors <a id="string.view.io">[[string.view.io]]</a>
|
| 748 |
|
|
|
|
| 1 |
## String view classes <a id="string.view">[[string.view]]</a>
|
| 2 |
|
| 3 |
+
### General <a id="string.view.general">[[string.view.general]]</a>
|
| 4 |
+
|
| 5 |
The class template `basic_string_view` describes an object that can
|
| 6 |
refer to a constant contiguous sequence of char-like [[strings.general]]
|
| 7 |
objects with the first element of the sequence at position zero. In the
|
| 8 |
+
rest of [[string.view]], the type of the char-like objects held in a
|
| 9 |
`basic_string_view` object is designated by `charT`.
|
| 10 |
|
| 11 |
[*Note 1*: The library provides implicit conversions from
|
| 12 |
`const charT*` and `std::basic_string<charT, ...>` to
|
| 13 |
`std::basic_string_view<charT, ...>` so that user code can accept just
|
| 14 |
`std::basic_string_view<charT>` as a non-templated parameter wherever a
|
| 15 |
+
sequence of characters is expected. User-defined types can define their
|
| 16 |
+
own implicit conversions to `std::basic_string_view<charT>` in order to
|
| 17 |
interoperate with these functions. — *end note*]
|
| 18 |
|
| 19 |
### Header `<string_view>` synopsis <a id="string.view.synop">[[string.view.synop]]</a>
|
| 20 |
|
| 21 |
``` cpp
|
|
|
|
| 25 |
// [string.view.template], class template basic_string_view
|
| 26 |
template<class charT, class traits = char_traits<charT>>
|
| 27 |
class basic_string_view;
|
| 28 |
|
| 29 |
template<class charT, class traits>
|
| 30 |
+
constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true;
|
| 31 |
template<class charT, class traits>
|
| 32 |
+
constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true;
|
| 33 |
|
| 34 |
// [string.view.comparison], non-member comparison functions
|
| 35 |
template<class charT, class traits>
|
| 36 |
constexpr bool operator==(basic_string_view<charT, traits> x,
|
| 37 |
basic_string_view<charT, traits> y) noexcept;
|
|
|
|
| 45 |
template<class charT, class traits>
|
| 46 |
basic_ostream<charT, traits>&
|
| 47 |
operator<<(basic_ostream<charT, traits>& os,
|
| 48 |
basic_string_view<charT, traits> str);
|
| 49 |
|
| 50 |
+
// basic_string_view typedef-names
|
| 51 |
using string_view = basic_string_view<char>;
|
| 52 |
using u8string_view = basic_string_view<char8_t>;
|
| 53 |
using u16string_view = basic_string_view<char16_t>;
|
| 54 |
using u32string_view = basic_string_view<char32_t>;
|
| 55 |
using wstring_view = basic_string_view<wchar_t>;
|
|
|
|
| 78 |
The function templates defined in [[utility.swap]] and
|
| 79 |
[[iterator.range]] are available when `<string_view>` is included.
|
| 80 |
|
| 81 |
### Class template `basic_string_view` <a id="string.view.template">[[string.view.template]]</a>
|
| 82 |
|
| 83 |
+
#### General <a id="string.view.template.general">[[string.view.template.general]]</a>
|
| 84 |
+
|
| 85 |
``` cpp
|
| 86 |
+
namespace std {
|
| 87 |
template<class charT, class traits = char_traits<charT>>
|
| 88 |
class basic_string_view {
|
| 89 |
public:
|
| 90 |
// types
|
| 91 |
using traits_type = traits;
|
|
|
|
| 93 |
using pointer = value_type*;
|
| 94 |
using const_pointer = const value_type*;
|
| 95 |
using reference = value_type&;
|
| 96 |
using const_reference = const value_type&;
|
| 97 |
using const_iterator = implementation-defined // type of basic_string_view::const_iterator; // see [string.view.iterators]
|
| 98 |
+
using iterator = const_iterator;
|
| 99 |
using const_reverse_iterator = reverse_iterator<const_iterator>;
|
| 100 |
using reverse_iterator = const_reverse_iterator;
|
| 101 |
using size_type = size_t;
|
| 102 |
using difference_type = ptrdiff_t;
|
| 103 |
static constexpr size_type npos = size_type(-1);
|
|
|
|
| 105 |
// [string.view.cons], construction and assignment
|
| 106 |
constexpr basic_string_view() noexcept;
|
| 107 |
constexpr basic_string_view(const basic_string_view&) noexcept = default;
|
| 108 |
constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default;
|
| 109 |
constexpr basic_string_view(const charT* str);
|
| 110 |
+
basic_string_view(nullptr_t) = delete;
|
| 111 |
constexpr basic_string_view(const charT* str, size_type len);
|
| 112 |
template<class It, class End>
|
| 113 |
constexpr basic_string_view(It begin, End end);
|
| 114 |
+
template<class R>
|
| 115 |
+
constexpr explicit basic_string_view(R&& r);
|
| 116 |
|
| 117 |
// [string.view.iterators], iterator support
|
| 118 |
constexpr const_iterator begin() const noexcept;
|
| 119 |
constexpr const_iterator end() const noexcept;
|
| 120 |
constexpr const_iterator cbegin() const noexcept;
|
|
|
|
| 160 |
constexpr bool starts_with(const charT* x) const;
|
| 161 |
constexpr bool ends_with(basic_string_view x) const noexcept;
|
| 162 |
constexpr bool ends_with(charT x) const noexcept;
|
| 163 |
constexpr bool ends_with(const charT* x) const;
|
| 164 |
|
| 165 |
+
constexpr bool contains(basic_string_view x) const noexcept;
|
| 166 |
+
constexpr bool contains(charT x) const noexcept;
|
| 167 |
+
constexpr bool contains(const charT* x) const;
|
| 168 |
+
|
| 169 |
// [string.view.find], searching
|
| 170 |
constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
|
| 171 |
constexpr size_type find(charT c, size_type pos = 0) const noexcept;
|
| 172 |
constexpr size_type find(const charT* s, size_type pos, size_type n) const;
|
| 173 |
constexpr size_type find(const charT* s, size_type pos = 0) const;
|
|
|
|
| 199 |
private:
|
| 200 |
const_pointer data_; // exposition only
|
| 201 |
size_type size_; // exposition only
|
| 202 |
};
|
| 203 |
|
| 204 |
+
// [string.view.deduct], deduction guides
|
| 205 |
template<class It, class End>
|
| 206 |
basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
|
| 207 |
+
template<class R>
|
| 208 |
+
basic_string_view(R&&) -> basic_string_view<ranges::range_value_t<R>>;
|
| 209 |
+
}
|
| 210 |
```
|
| 211 |
|
| 212 |
+
[^2]
|
| 213 |
+
|
| 214 |
In every specialization `basic_string_view<charT, traits>`, the type
|
| 215 |
`traits` shall meet the character traits requirements [[char.traits]].
|
| 216 |
|
| 217 |
[*Note 1*: The program is ill-formed if `traits::char_type` is not the
|
| 218 |
same type as `charT`. — *end note*]
|
| 219 |
|
| 220 |
For a `basic_string_view str`, any operation that invalidates a pointer
|
| 221 |
+
in the range
|
| 222 |
+
|
| 223 |
+
``` cpp
|
| 224 |
+
{[}str.data(), {str.data() + str.size()}{)}
|
| 225 |
+
```
|
| 226 |
+
|
| 227 |
+
invalidates pointers, iterators, and references returned from `str`’s
|
| 228 |
+
member functions.
|
| 229 |
|
| 230 |
The complexity of `basic_string_view` member functions is 𝑂(1) unless
|
| 231 |
otherwise specified.
|
| 232 |
|
| 233 |
+
`basic_string_view<charT, traits>` is a trivially copyable type
|
| 234 |
+
[[term.trivially.copyable.type]].
|
| 235 |
+
|
| 236 |
#### Construction and assignment <a id="string.view.cons">[[string.view.cons]]</a>
|
| 237 |
|
| 238 |
``` cpp
|
| 239 |
constexpr basic_string_view() noexcept;
|
| 240 |
```
|
|
|
|
| 280 |
- `End` models `sized_sentinel_for<It>`.
|
| 281 |
|
| 282 |
*Effects:* Initializes `data_` with `to_address(begin)` and initializes
|
| 283 |
`size_` with `end - begin`.
|
| 284 |
|
| 285 |
+
*Throws:* When and what `end - begin` throws.
|
| 286 |
+
|
| 287 |
+
``` cpp
|
| 288 |
+
template<class R>
|
| 289 |
+
constexpr explicit basic_string_view(R&& r);
|
| 290 |
+
```
|
| 291 |
+
|
| 292 |
+
Let `d` be an lvalue of type `remove_cvref_t<R>`.
|
| 293 |
+
|
| 294 |
+
*Constraints:*
|
| 295 |
+
|
| 296 |
+
- `remove_cvref_t<R>` is not the same type as `basic_string_view`,
|
| 297 |
+
- `R` models `ranges::contiguous_range` and `ranges::sized_range`,
|
| 298 |
+
- `is_same_v<ranges::range_value_t<R>, charT>` is `true`,
|
| 299 |
+
- `is_convertible_v<R, const charT*>` is `false`, and
|
| 300 |
+
- `d.operator ::std::basic_string_view<charT, traits>()` is not a valid
|
| 301 |
+
expression.
|
| 302 |
+
|
| 303 |
+
*Effects:* Initializes `data_` with `ranges::data(r)` and `size_` with
|
| 304 |
+
`ranges::size(r)`.
|
| 305 |
+
|
| 306 |
+
*Throws:* Any exception thrown by `ranges::data(r)` and
|
| 307 |
+
`ranges::size(r)`.
|
| 308 |
+
|
| 309 |
+
#### Deduction guides <a id="string.view.deduct">[[string.view.deduct]]</a>
|
| 310 |
+
|
| 311 |
+
``` cpp
|
| 312 |
+
template<class It, class End>
|
| 313 |
+
basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
|
| 314 |
+
```
|
| 315 |
+
|
| 316 |
+
*Constraints:*
|
| 317 |
+
|
| 318 |
+
- `It` satisfies `contiguous_iterator`.
|
| 319 |
+
- `End` satisfies `sized_sentinel_for<It>`.
|
| 320 |
+
|
| 321 |
+
``` cpp
|
| 322 |
+
template<class R>
|
| 323 |
+
basic_string_view(R&&) -> basic_string_view<ranges::range_value_t<R>>;
|
| 324 |
+
```
|
| 325 |
+
|
| 326 |
+
*Constraints:* `R` satisfies `ranges::contiguous_range`.
|
| 327 |
+
|
| 328 |
#### Iterator support <a id="string.view.iterators">[[string.view.iterators]]</a>
|
| 329 |
|
| 330 |
``` cpp
|
| 331 |
using const_iterator = implementation-defined // type of basic_string_view::const_iterator;
|
| 332 |
```
|
|
|
|
| 412 |
|
| 413 |
``` cpp
|
| 414 |
constexpr const_reference at(size_type pos) const;
|
| 415 |
```
|
| 416 |
|
| 417 |
+
*Returns:* `data_[pos]`.
|
| 418 |
+
|
| 419 |
*Throws:* `out_of_range` if `pos >= size()`.
|
| 420 |
|
|
|
|
|
|
|
| 421 |
``` cpp
|
| 422 |
constexpr const_reference front() const;
|
| 423 |
```
|
| 424 |
|
| 425 |
*Preconditions:* `!empty()`.
|
|
|
|
| 443 |
```
|
| 444 |
|
| 445 |
*Returns:* `data_`.
|
| 446 |
|
| 447 |
[*Note 2*: Unlike `basic_string::data()` and *string-literal*s,
|
| 448 |
+
`data()` can return a pointer to a buffer that is not null-terminated.
|
| 449 |
Therefore it is typically a mistake to pass `data()` to a function that
|
| 450 |
takes just a `const charT*` and expects a null-terminated
|
| 451 |
string. — *end note*]
|
| 452 |
|
| 453 |
#### Modifiers <a id="string.view.modifiers">[[string.view.modifiers]]</a>
|
|
|
|
| 480 |
constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
|
| 481 |
```
|
| 482 |
|
| 483 |
Let `rlen` be the smaller of `n` and `size() - pos`.
|
| 484 |
|
|
|
|
|
|
|
| 485 |
*Preconditions:* \[`s`, `s + rlen`) is a valid range.
|
| 486 |
|
| 487 |
*Effects:* Equivalent to `traits::copy(s, data() + pos, rlen)`.
|
| 488 |
|
| 489 |
*Returns:* `rlen`.
|
| 490 |
|
| 491 |
+
*Throws:* `out_of_range` if `pos > size()`.
|
| 492 |
+
|
| 493 |
*Complexity:* 𝑂(`rlen`).
|
| 494 |
|
| 495 |
``` cpp
|
| 496 |
constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
|
| 497 |
```
|
| 498 |
|
| 499 |
Let `rlen` be the smaller of `n` and `size() - pos`.
|
| 500 |
|
|
|
|
|
|
|
| 501 |
*Effects:* Determines `rlen`, the effective length of the string to
|
| 502 |
reference.
|
| 503 |
|
| 504 |
*Returns:* `basic_string_view(data() + pos, rlen)`.
|
| 505 |
|
| 506 |
+
*Throws:* `out_of_range` if `pos > size()`.
|
| 507 |
+
|
| 508 |
``` cpp
|
| 509 |
constexpr int compare(basic_string_view str) const noexcept;
|
| 510 |
```
|
| 511 |
|
| 512 |
Let `rlen` be the smaller of `size()` and `str.size()`.
|
| 513 |
|
| 514 |
*Effects:* Determines `rlen`, the effective length of the strings to
|
| 515 |
compare. The function then compares the two strings by calling
|
| 516 |
`traits::compare(data(), str.data(), rlen)`.
|
| 517 |
|
|
|
|
|
|
|
| 518 |
*Returns:* The nonzero result if the result of the comparison is
|
| 519 |
nonzero. Otherwise, returns a value as indicated in
|
| 520 |
[[string.view.compare]].
|
| 521 |
|
| 522 |
**Table: `compare()` results** <a id="string.view.compare">[string.view.compare]</a>
|
|
|
|
| 525 |
| ---------------------- | ------------ |
|
| 526 |
| `size() < str.size()` | `< 0` |
|
| 527 |
| `size() == str.size()` | ` 0` |
|
| 528 |
| `size() > str.size()` | `> 0` |
|
| 529 |
|
| 530 |
+
|
| 531 |
+
*Complexity:* 𝑂(`rlen`).
|
| 532 |
+
|
| 533 |
``` cpp
|
| 534 |
constexpr int compare(size_type pos1, size_type n1, basic_string_view str) const;
|
| 535 |
```
|
| 536 |
|
| 537 |
*Effects:* Equivalent to: `return substr(pos1, n1).compare(str);`
|
|
|
|
| 602 |
constexpr bool ends_with(const charT* x) const;
|
| 603 |
```
|
| 604 |
|
| 605 |
*Effects:* Equivalent to: `return ends_with(basic_string_view(x));`
|
| 606 |
|
| 607 |
+
``` cpp
|
| 608 |
+
constexpr bool contains(basic_string_view x) const noexcept;
|
| 609 |
+
constexpr bool contains(charT x) const noexcept;
|
| 610 |
+
constexpr bool contains(const charT* x) const;
|
| 611 |
+
```
|
| 612 |
+
|
| 613 |
+
*Effects:* Equivalent to: `return find(x) != npos;`
|
| 614 |
+
|
| 615 |
#### Searching <a id="string.view.find">[[string.view.find]]</a>
|
| 616 |
|
| 617 |
Member functions in this subclause have complexity
|
| 618 |
𝑂(`size() * str.size()`) at worst, although implementations should do
|
| 619 |
better.
|
|
|
|
| 741 |
*Effects:* Determines `xpos`.
|
| 742 |
|
| 743 |
*Returns:* `xpos` if the function can determine such a value for `xpos`.
|
| 744 |
Otherwise, returns `npos`.
|
| 745 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 746 |
### Non-member comparison functions <a id="string.view.comparison">[[string.view.comparison]]</a>
|
| 747 |
|
| 748 |
Let `S` be `basic_string_view<charT, traits>`, and `sv` be an instance
|
| 749 |
of `S`. Implementations shall provide sufficient additional overloads
|
| 750 |
marked `constexpr` and `noexcept` so that an object `t` with an implicit
|
|
|
|
| 802 |
template<class charT, class traits>
|
| 803 |
constexpr see below operator<=>(basic_string_view<charT, traits> lhs,
|
| 804 |
\itcorr basic_string_view<charT, traits> rhs) noexcept;
|
| 805 |
```
|
| 806 |
|
| 807 |
+
Let `R` denote the type `traits::comparison_category` if that
|
| 808 |
+
*qualified-id* is valid and denotes a type [[temp.deduct]], otherwise
|
| 809 |
+
`R` is `weak_ordering`.
|
| 810 |
+
|
| 811 |
+
*Mandates:* `R` denotes a comparison category type [[cmp.categories]].
|
| 812 |
|
| 813 |
*Returns:* `static_cast<R>(lhs.compare(rhs) <=> 0)`.
|
| 814 |
|
| 815 |
### Inserters and extractors <a id="string.view.io">[[string.view.io]]</a>
|
| 816 |
|