From Jason Turner

[string.view]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp0lk4bo80/{from.md → to.md} +80 -109
tmp/tmp0lk4bo80/{from.md → to.md} RENAMED
@@ -17,37 +17,37 @@ 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
 
22
  #include <compare> // see [compare.syn]
23
 
24
  namespace std {
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;
38
  template<class charT, class traits>
39
  constexpr see below operator<=>(basic_string_view<charT, traits> x,
40
- \itcorr basic_string_view<charT, traits> y) noexcept;
41
-
42
- // see [string.view.comparison], sufficient additional overloads of comparison functions
43
 
44
  // [string.view.io], inserters and extractors
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>;
@@ -126,36 +126,43 @@ namespace std {
126
 
127
  // [string.view.capacity], capacity
128
  constexpr size_type size() const noexcept;
129
  constexpr size_type length() const noexcept;
130
  constexpr size_type max_size() const noexcept;
131
- [[nodiscard]] constexpr bool empty() const noexcept;
132
 
133
  // [string.view.access], element access
134
  constexpr const_reference operator[](size_type pos) const;
135
- constexpr const_reference at(size_type pos) const;
136
  constexpr const_reference front() const;
137
  constexpr const_reference back() const;
138
  constexpr const_pointer data() const noexcept;
139
 
140
  // [string.view.modifiers], modifiers
141
  constexpr void remove_prefix(size_type n);
142
  constexpr void remove_suffix(size_type n);
143
  constexpr void swap(basic_string_view& s) noexcept;
144
 
145
  // [string.view.ops], string operations
146
- constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
 
147
 
148
- constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
 
 
 
149
 
150
  constexpr int compare(basic_string_view s) const noexcept;
151
- constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
 
152
  constexpr int compare(size_type pos1, size_type n1, basic_string_view s,
153
- size_type pos2, size_type n2) const;
154
  constexpr int compare(const charT* s) const;
155
- constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
156
- constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;
 
 
157
 
158
  constexpr bool starts_with(basic_string_view x) const noexcept;
159
  constexpr bool starts_with(charT x) const noexcept;
160
  constexpr bool starts_with(const charT* x) const;
161
  constexpr bool ends_with(basic_string_view x) const noexcept;
@@ -219,15 +226,14 @@ 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
@@ -237,31 +243,31 @@ otherwise specified.
237
 
238
  ``` cpp
239
  constexpr basic_string_view() noexcept;
240
  ```
241
 
242
- *Ensures:* `size_ == 0` and `data_ == nullptr`.
243
 
244
  ``` cpp
245
  constexpr basic_string_view(const charT* str);
246
  ```
247
 
248
  *Preconditions:* \[`str`, `str + traits::length(str)`) is a valid range.
249
 
250
- *Effects:* Constructs a `basic_string_view`, initializing `data_` with
251
- `str` and initializing `size_` with `traits::length(str)`.
252
 
253
  *Complexity:* 𝑂(`traits::length(str)`).
254
 
255
  ``` cpp
256
  constexpr basic_string_view(const charT* str, size_type len);
257
  ```
258
 
259
  *Preconditions:* \[`str`, `str + len`) is a valid range.
260
 
261
- *Effects:* Constructs a `basic_string_view`, initializing `data_` with
262
- `str` and initializing `size_` with `len`.
263
 
264
  ``` cpp
265
  template<class It, class End>
266
  constexpr basic_string_view(It begin, End end);
267
  ```
@@ -277,12 +283,12 @@ template<class It, class End>
277
 
278
  - \[`begin`, `end`) is a valid range.
279
  - `It` models `contiguous_iterator`.
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>
@@ -298,11 +304,11 @@ Let `d` be an lvalue of type `remove_cvref_t<R>`.
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
 
@@ -345,11 +351,11 @@ constexpr const_iterator begin() const noexcept;
345
  constexpr const_iterator cbegin() const noexcept;
346
  ```
347
 
348
  *Returns:* An iterator such that
349
 
350
- - if `!empty()`, `addressof(*begin()) == data_`,
351
  - otherwise, an unspecified value such that \[`begin()`, `end()`) is a
352
  valid range.
353
 
354
  ``` cpp
355
  constexpr const_iterator end() const noexcept;
@@ -377,74 +383,73 @@ constexpr const_reverse_iterator crend() const noexcept;
377
  ``` cpp
378
  constexpr size_type size() const noexcept;
379
  constexpr size_type length() const noexcept;
380
  ```
381
 
382
- *Returns:* `size_`.
383
 
384
  ``` cpp
385
  constexpr size_type max_size() const noexcept;
386
  ```
387
 
388
  *Returns:* The largest possible number of char-like objects that can be
389
  referred to by a `basic_string_view`.
390
 
391
  ``` cpp
392
- [[nodiscard]] constexpr bool empty() const noexcept;
393
  ```
394
 
395
- *Returns:* `size_ == 0`.
396
 
397
  #### Element access <a id="string.view.access">[[string.view.access]]</a>
398
 
399
  ``` cpp
400
  constexpr const_reference operator[](size_type pos) const;
401
  ```
402
 
403
- *Preconditions:* `pos < size()`.
404
 
405
- *Returns:* `data_[pos]`.
 
 
 
406
 
407
  *Throws:* Nothing.
408
 
409
- [*Note 1*: Unlike `basic_string::operator[]`,
410
- `basic_string_view::operator[](size())` has undefined behavior instead
411
- of returning `charT()`. — *end note*]
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()`.
426
 
427
- *Returns:* `data_[0]`.
428
 
429
  *Throws:* Nothing.
430
 
431
  ``` cpp
432
  constexpr const_reference back() const;
433
  ```
434
 
435
- *Preconditions:* `!empty()`.
436
 
437
- *Returns:* `data_[size() - 1]`.
438
 
439
  *Throws:* Nothing.
440
 
441
  ``` cpp
442
  constexpr const_pointer data() const noexcept;
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
@@ -454,21 +459,21 @@ string. — *end note*]
454
 
455
  ``` cpp
456
  constexpr void remove_prefix(size_type n);
457
  ```
458
 
459
- *Preconditions:* `n <= size()`.
460
 
461
- *Effects:* Equivalent to: `data_ += n; size_ -= n;`
462
 
463
  ``` cpp
464
  constexpr void remove_suffix(size_type n);
465
  ```
466
 
467
- *Preconditions:* `n <= size()`.
468
 
469
- *Effects:* Equivalent to: `size_ -= n;`
470
 
471
  ``` cpp
472
  constexpr void swap(basic_string_view& s) noexcept;
473
  ```
474
 
@@ -492,10 +497,11 @@ Let `rlen` be the smaller of `n` and `size() - pos`.
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
@@ -566,11 +572,13 @@ constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2
566
 
567
  ``` cpp
568
  constexpr bool starts_with(basic_string_view x) const noexcept;
569
  ```
570
 
571
- *Effects:* Equivalent to: `return substr(0, x.size()) == x;`
 
 
572
 
573
  ``` cpp
574
  constexpr bool starts_with(charT x) const noexcept;
575
  ```
576
 
@@ -584,14 +592,16 @@ constexpr bool starts_with(const charT* x) const;
584
 
585
  ``` cpp
586
  constexpr bool ends_with(basic_string_view x) const noexcept;
587
  ```
588
 
 
 
589
  *Effects:* Equivalent to:
590
 
591
  ``` cpp
592
- return size() >= x.size() && compare(size() - x.size(), npos, x) == 0;
593
  ```
594
 
595
  ``` cpp
596
  constexpr bool ends_with(charT x) const noexcept;
597
  ```
@@ -648,12 +658,12 @@ constexpr size_type find(basic_string_view str, size_type pos = 0) const noexcep
648
  Let `xpos` be the lowest position, if possible, such that the following
649
  conditions hold:
650
 
651
  - `pos <= xpos`
652
  - `xpos + str.size() <= size()`
653
- - `traits::eq(at(xpos + I), str.at(I))` for all elements `I` of the
654
- string referenced by `str`.
655
 
656
  *Effects:* Determines `xpos`.
657
 
658
  *Returns:* `xpos` if the function can determine such a value for `xpos`.
659
  Otherwise, returns `npos`.
@@ -665,12 +675,12 @@ constexpr size_type rfind(basic_string_view str, size_type pos = npos) const noe
665
  Let `xpos` be the highest position, if possible, such that the following
666
  conditions hold:
667
 
668
  - `xpos <= pos`
669
  - `xpos + str.size() <= size()`
670
- - `traits::eq(at(xpos + I), str.at(I))` for all elements `I` of the
671
- string referenced by `str`.
672
 
673
  *Effects:* Determines `xpos`.
674
 
675
  *Returns:* `xpos` if the function can determine such a value for `xpos`.
676
  Otherwise, returns `npos`.
@@ -682,12 +692,12 @@ constexpr size_type find_first_of(basic_string_view str, size_type pos = 0) cons
682
  Let `xpos` be the lowest position, if possible, such that the following
683
  conditions hold:
684
 
685
  - `pos <= xpos`
686
  - `xpos < size()`
687
- - `traits::eq(at(xpos), str.at(I))` for some element `I` of the string
688
- referenced by `str`.
689
 
690
  *Effects:* Determines `xpos`.
691
 
692
  *Returns:* `xpos` if the function can determine such a value for `xpos`.
693
  Otherwise, returns `npos`.
@@ -699,12 +709,12 @@ constexpr size_type find_last_of(basic_string_view str, size_type pos = npos) co
699
  Let `xpos` be the highest position, if possible, such that the following
700
  conditions hold:
701
 
702
  - `xpos <= pos`
703
  - `xpos < size()`
704
- - `traits::eq(at(xpos), str.at(I))` for some element `I` of the string
705
- referenced by `str`.
706
 
707
  *Effects:* Determines `xpos`.
708
 
709
  *Returns:* `xpos` if the function can determine such a value for `xpos`.
710
  Otherwise, returns `npos`.
@@ -716,12 +726,12 @@ constexpr size_type find_first_not_of(basic_string_view str, size_type pos = 0)
716
  Let `xpos` be the lowest position, if possible, such that the following
717
  conditions hold:
718
 
719
  - `pos <= xpos`
720
  - `xpos < size()`
721
- - `traits::eq(at(xpos), str.at(I))` for no element `I` of the string
722
- referenced by `str`.
723
 
724
  *Effects:* Determines `xpos`.
725
 
726
  *Returns:* `xpos` if the function can determine such a value for `xpos`.
727
  Otherwise, returns `npos`.
@@ -733,87 +743,48 @@ constexpr size_type find_last_not_of(basic_string_view str, size_type pos = npos
733
  Let `xpos` be the highest position, if possible, such that the following
734
  conditions hold:
735
 
736
  - `xpos <= pos`
737
  - `xpos < size()`
738
- - `traits::eq(at(xpos), str.at(I))` for no element `I` of the string
739
- referenced by `str`.
740
 
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
751
- conversion to `S` can be compared according to
752
- [[string.view.comparison.overloads]].
753
-
754
- **Table: Additional `basic_string_view` comparison overloads** <a id="string.view.comparison.overloads">[string.view.comparison.overloads]</a>
755
-
756
- | Expression | Equivalent to |
757
- | ---------- | ------------- |
758
- | `t == sv` | `S(t) == sv` |
759
- | `sv == t` | `sv == S(t)` |
760
- | `t != sv` | `S(t) != sv` |
761
- | `sv != t` | `sv != S(t)` |
762
- | `t < sv` | `S(t) < sv` |
763
- | `sv < t` | `sv < S(t)` |
764
- | `t > sv` | `S(t) > sv` |
765
- | `sv > t` | `sv > S(t)` |
766
- | `t <= sv` | `S(t) <= sv` |
767
- | `sv <= t` | `sv <= S(t)` |
768
- | `t >= sv` | `S(t) >= sv` |
769
- | `sv >= t` | `sv >= S(t)` |
770
- | `t <=> sv` | `S(t) <=> sv` |
771
- | `sv <=> t` | `sv <=> S(t)` |
772
-
773
-
774
- [*Example 1*:
775
-
776
- A sample conforming implementation for `operator==` would be:
777
-
778
  ``` cpp
779
  template<class charT, class traits>
780
  constexpr bool operator==(basic_string_view<charT, traits> lhs,
781
- basic_string_view<charT, traits> rhs) noexcept {
782
- return lhs.compare(rhs) == 0;
783
- }
784
- template<class charT, class traits>
785
- constexpr bool operator==(basic_string_view<charT, traits> lhs,
786
- type_identity_t<basic_string_view<charT, traits>> rhs) noexcept {
787
- return lhs.compare(rhs) == 0;
788
- }
789
- ```
790
-
791
- — *end example*]
792
-
793
- ``` cpp
794
- template<class charT, class traits>
795
- constexpr bool operator==(basic_string_view<charT, traits> lhs,
796
- basic_string_view<charT, traits> rhs) noexcept;
797
  ```
798
 
799
  *Returns:* `lhs.compare(rhs) == 0`.
800
 
801
  ``` cpp
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
 
817
  ``` cpp
818
  template<class charT, class traits>
819
  basic_ostream<charT, traits>&
@@ -826,11 +797,11 @@ sequence `seq`, initially consisting of the elements defined by the
826
  range \[`str.begin()`, `str.end()`). Determines padding for `seq` as
827
  described in  [[ostream.formatted.reqmts]]. Then inserts `seq` as if by
828
  calling `os.rdbuf()->sputn(seq, n)`, where `n` is the larger of
829
  `os.width()` and `str.size()`; then calls `os.width(0)`.
830
 
831
- *Returns:* `os`
832
 
833
  ### Hash support <a id="string.view.hash">[[string.view.hash]]</a>
834
 
835
  ``` cpp
836
  template<> struct hash<string_view>;
 
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
22
+ // mostly freestanding
23
  #include <compare> // see [compare.syn]
24
 
25
  namespace std {
26
  // [string.view.template], class template basic_string_view
27
  template<class charT, class traits = char_traits<charT>>
28
+ class basic_string_view; // partially freestanding
29
 
30
  template<class charT, class traits>
31
+ constexpr bool ranges::\libspec{enable_view}{basic_string_view}<basic_string_view<charT, traits>> = true;
32
  template<class charT, class traits>
33
+ constexpr bool ranges::\libspec{enable_borrowed_range}{basic_string_view}<basic_string_view<charT, traits>> = true;
34
 
35
  // [string.view.comparison], non-member comparison functions
36
  template<class charT, class traits>
37
  constexpr bool operator==(basic_string_view<charT, traits> x,
38
+ type_identity_t<basic_string_view<charT, traits>> y) noexcept;
39
  template<class charT, class traits>
40
  constexpr see below operator<=>(basic_string_view<charT, traits> x,
41
+ \itcorr type_identity_t<basic_string_view<charT,
42
+ \itcorr traits>> y) noexcept;
 
43
 
44
  // [string.view.io], inserters and extractors
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); // hosted
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>;
 
126
 
127
  // [string.view.capacity], capacity
128
  constexpr size_type size() const noexcept;
129
  constexpr size_type length() const noexcept;
130
  constexpr size_type max_size() const noexcept;
131
+ constexpr bool empty() const noexcept;
132
 
133
  // [string.view.access], element access
134
  constexpr const_reference operator[](size_type pos) const;
135
+ constexpr const_reference at(size_type pos) const; // freestanding-deleted
136
  constexpr const_reference front() const;
137
  constexpr const_reference back() const;
138
  constexpr const_pointer data() const noexcept;
139
 
140
  // [string.view.modifiers], modifiers
141
  constexpr void remove_prefix(size_type n);
142
  constexpr void remove_suffix(size_type n);
143
  constexpr void swap(basic_string_view& s) noexcept;
144
 
145
  // [string.view.ops], string operations
146
+ constexpr size_type copy(charT* s, size_type n,
147
+ size_type pos = 0) const; // freestanding-deleted
148
 
149
+ constexpr basic_string_view substr(size_type pos = 0,
150
+ size_type n = npos) const; // freestanding-deleted
151
+ constexpr basic_string_view subview(size_type pos = 0,
152
+ size_type n = npos) const; // freestanding-deleted
153
 
154
  constexpr int compare(basic_string_view s) const noexcept;
155
+ constexpr int compare(size_type pos1, size_type n1,
156
+ basic_string_view s) const; // freestanding-deleted
157
  constexpr int compare(size_type pos1, size_type n1, basic_string_view s,
158
+ size_type pos2, size_type n2) const; // freestanding-deleted
159
  constexpr int compare(const charT* s) const;
160
+ constexpr int compare(size_type pos1, size_type n1,
161
+ const charT* s) const; // freestanding-deleted
162
+ constexpr int compare(size_type pos1, size_type n1, const charT* s,
163
+ size_type n2) const; // freestanding-deleted
164
 
165
  constexpr bool starts_with(basic_string_view x) const noexcept;
166
  constexpr bool starts_with(charT x) const noexcept;
167
  constexpr bool starts_with(const charT* x) const;
168
  constexpr bool ends_with(basic_string_view x) const noexcept;
 
226
 
227
  For a `basic_string_view str`, any operation that invalidates a pointer
228
  in the range
229
 
230
  ``` cpp
231
+ {[}str.data(), str.data() + str.size(){)}
232
  ```
233
 
234
+ invalidates pointers, iterators, and references to elements of `str`.
 
235
 
236
  The complexity of `basic_string_view` member functions is 𝑂(1) unless
237
  otherwise specified.
238
 
239
  `basic_string_view<charT, traits>` is a trivially copyable type
 
243
 
244
  ``` cpp
245
  constexpr basic_string_view() noexcept;
246
  ```
247
 
248
+ *Ensures:* *`size_`*` == 0` and *`data_`*` == nullptr`.
249
 
250
  ``` cpp
251
  constexpr basic_string_view(const charT* str);
252
  ```
253
 
254
  *Preconditions:* \[`str`, `str + traits::length(str)`) is a valid range.
255
 
256
+ *Effects:* Constructs a `basic_string_view`, initializing *data\_* with
257
+ `str` and initializing *size\_* with `traits::length(str)`.
258
 
259
  *Complexity:* 𝑂(`traits::length(str)`).
260
 
261
  ``` cpp
262
  constexpr basic_string_view(const charT* str, size_type len);
263
  ```
264
 
265
  *Preconditions:* \[`str`, `str + len`) is a valid range.
266
 
267
+ *Effects:* Constructs a `basic_string_view`, initializing *data\_* with
268
+ `str` and initializing *size\_* with `len`.
269
 
270
  ``` cpp
271
  template<class It, class End>
272
  constexpr basic_string_view(It begin, End end);
273
  ```
 
283
 
284
  - \[`begin`, `end`) is a valid range.
285
  - `It` models `contiguous_iterator`.
286
  - `End` models `sized_sentinel_for<It>`.
287
 
288
+ *Effects:* Initializes *data\_* with `to_address(begin)` and initializes
289
+ *size\_* with `end - begin`.
290
 
291
  *Throws:* When and what `end - begin` throws.
292
 
293
  ``` cpp
294
  template<class R>
 
304
  - `is_same_v<ranges::range_value_t<R>, charT>` is `true`,
305
  - `is_convertible_v<R, const charT*>` is `false`, and
306
  - `d.operator ::std::basic_string_view<charT, traits>()` is not a valid
307
  expression.
308
 
309
+ *Effects:* Initializes *data\_* with `ranges::data(r)` and *size\_* with
310
  `ranges::size(r)`.
311
 
312
  *Throws:* Any exception thrown by `ranges::data(r)` and
313
  `ranges::size(r)`.
314
 
 
351
  constexpr const_iterator cbegin() const noexcept;
352
  ```
353
 
354
  *Returns:* An iterator such that
355
 
356
+ - if `!empty()`, `addressof(*begin()) == `*`data_`*,
357
  - otherwise, an unspecified value such that \[`begin()`, `end()`) is a
358
  valid range.
359
 
360
  ``` cpp
361
  constexpr const_iterator end() const noexcept;
 
383
  ``` cpp
384
  constexpr size_type size() const noexcept;
385
  constexpr size_type length() const noexcept;
386
  ```
387
 
388
+ *Returns:* *size\_*.
389
 
390
  ``` cpp
391
  constexpr size_type max_size() const noexcept;
392
  ```
393
 
394
  *Returns:* The largest possible number of char-like objects that can be
395
  referred to by a `basic_string_view`.
396
 
397
  ``` cpp
398
+ constexpr bool empty() const noexcept;
399
  ```
400
 
401
+ *Returns:* *`size_`*` == 0`.
402
 
403
  #### Element access <a id="string.view.access">[[string.view.access]]</a>
404
 
405
  ``` cpp
406
  constexpr const_reference operator[](size_type pos) const;
407
  ```
408
 
409
+ `pos < size()` is `true`.
410
 
411
+ [*Note 1*: This precondition is stronger than the one on
412
+ `basic_string::operator[]`. — *end note*]
413
+
414
+ *Returns:* *`data_`*`[pos]`.
415
 
416
  *Throws:* Nothing.
417
 
 
 
 
 
418
  ``` cpp
419
  constexpr const_reference at(size_type pos) const;
420
  ```
421
 
422
+ *Returns:* *`data_`*`[pos]`.
423
 
424
  *Throws:* `out_of_range` if `pos >= size()`.
425
 
426
  ``` cpp
427
  constexpr const_reference front() const;
428
  ```
429
 
430
+ `empty()` is `false`.
431
 
432
+ *Returns:* *`data_`*`[0]`.
433
 
434
  *Throws:* Nothing.
435
 
436
  ``` cpp
437
  constexpr const_reference back() const;
438
  ```
439
 
440
+ `empty()` is `false`.
441
 
442
+ *Returns:* *`data_`*`[size() - 1]`.
443
 
444
  *Throws:* Nothing.
445
 
446
  ``` cpp
447
  constexpr const_pointer data() const noexcept;
448
  ```
449
 
450
+ *Returns:* *data\_*.
451
 
452
  [*Note 2*: Unlike `basic_string::data()` and *string-literal*s,
453
  `data()` can return a pointer to a buffer that is not null-terminated.
454
  Therefore it is typically a mistake to pass `data()` to a function that
455
  takes just a `const charT*` and expects a null-terminated
 
459
 
460
  ``` cpp
461
  constexpr void remove_prefix(size_type n);
462
  ```
463
 
464
+ `n <= size()` is `true`.
465
 
466
+ *Effects:* Equivalent to: *`data_`*` += n; `*`size_`*` -= n;`
467
 
468
  ``` cpp
469
  constexpr void remove_suffix(size_type n);
470
  ```
471
 
472
+ `n <= size()` is `true`.
473
 
474
+ *Effects:* Equivalent to: *`size_`*` -= n;`
475
 
476
  ``` cpp
477
  constexpr void swap(basic_string_view& s) noexcept;
478
  ```
479
 
 
497
 
498
  *Complexity:* 𝑂(`rlen`).
499
 
500
  ``` cpp
501
  constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
502
+ constexpr basic_string_view subview(size_type pos = 0, size_type n = npos) const;
503
  ```
504
 
505
  Let `rlen` be the smaller of `n` and `size() - pos`.
506
 
507
  *Effects:* Determines `rlen`, the effective length of the string to
 
572
 
573
  ``` cpp
574
  constexpr bool starts_with(basic_string_view x) const noexcept;
575
  ```
576
 
577
+ Let `rlen` be the smaller of `size()` and `x.size()`.
578
+
579
+ *Effects:* Equivalent to: `return basic_string_view(data(), rlen) == x;`
580
 
581
  ``` cpp
582
  constexpr bool starts_with(charT x) const noexcept;
583
  ```
584
 
 
592
 
593
  ``` cpp
594
  constexpr bool ends_with(basic_string_view x) const noexcept;
595
  ```
596
 
597
+ Let `rlen` be the smaller of `size()` and `x.size()`.
598
+
599
  *Effects:* Equivalent to:
600
 
601
  ``` cpp
602
+ return basic_string_view(data() + (size() - rlen), rlen) == x;
603
  ```
604
 
605
  ``` cpp
606
  constexpr bool ends_with(charT x) const noexcept;
607
  ```
 
658
  Let `xpos` be the lowest position, if possible, such that the following
659
  conditions hold:
660
 
661
  - `pos <= xpos`
662
  - `xpos + str.size() <= size()`
663
+ - `traits::eq(`*`data_`*`[xpos + I], str[I])` for all elements `I` of
664
+ the string referenced by `str`.
665
 
666
  *Effects:* Determines `xpos`.
667
 
668
  *Returns:* `xpos` if the function can determine such a value for `xpos`.
669
  Otherwise, returns `npos`.
 
675
  Let `xpos` be the highest position, if possible, such that the following
676
  conditions hold:
677
 
678
  - `xpos <= pos`
679
  - `xpos + str.size() <= size()`
680
+ - `traits::eq(`*`data_`*`[xpos + I], str[I])` for all elements `I` of
681
+ the string referenced by `str`.
682
 
683
  *Effects:* Determines `xpos`.
684
 
685
  *Returns:* `xpos` if the function can determine such a value for `xpos`.
686
  Otherwise, returns `npos`.
 
692
  Let `xpos` be the lowest position, if possible, such that the following
693
  conditions hold:
694
 
695
  - `pos <= xpos`
696
  - `xpos < size()`
697
+ - `traits::eq(`*`data_`*`[xpos], str[I])` for some element `I` of the
698
+ string referenced by `str`.
699
 
700
  *Effects:* Determines `xpos`.
701
 
702
  *Returns:* `xpos` if the function can determine such a value for `xpos`.
703
  Otherwise, returns `npos`.
 
709
  Let `xpos` be the highest position, if possible, such that the following
710
  conditions hold:
711
 
712
  - `xpos <= pos`
713
  - `xpos < size()`
714
+ - `traits::eq(`*`data_`*`[xpos], str[I])` for some element `I` of the
715
+ string referenced by `str`.
716
 
717
  *Effects:* Determines `xpos`.
718
 
719
  *Returns:* `xpos` if the function can determine such a value for `xpos`.
720
  Otherwise, returns `npos`.
 
726
  Let `xpos` be the lowest position, if possible, such that the following
727
  conditions hold:
728
 
729
  - `pos <= xpos`
730
  - `xpos < size()`
731
+ - `traits::eq(`*`data_`*`[xpos], str[I])` for no element `I` of the
732
+ string referenced by `str`.
733
 
734
  *Effects:* Determines `xpos`.
735
 
736
  *Returns:* `xpos` if the function can determine such a value for `xpos`.
737
  Otherwise, returns `npos`.
 
743
  Let `xpos` be the highest position, if possible, such that the following
744
  conditions hold:
745
 
746
  - `xpos <= pos`
747
  - `xpos < size()`
748
+ - `traits::eq(`*`data_`*`[xpos], str[I])` for no element `I` of the
749
+ string referenced by `str`.
750
 
751
  *Effects:* Determines `xpos`.
752
 
753
  *Returns:* `xpos` if the function can determine such a value for `xpos`.
754
  Otherwise, returns `npos`.
755
 
756
  ### Non-member comparison functions <a id="string.view.comparison">[[string.view.comparison]]</a>
757
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
758
  ``` cpp
759
  template<class charT, class traits>
760
  constexpr bool operator==(basic_string_view<charT, traits> lhs,
761
+ type_identity_t<basic_string_view<charT, traits>> rhs) noexcept;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
762
  ```
763
 
764
  *Returns:* `lhs.compare(rhs) == 0`.
765
 
766
  ``` cpp
767
  template<class charT, class traits>
768
  constexpr see below operator<=>(basic_string_view<charT, traits> lhs,
769
+ \itcorr type_identity_t<basic_string_view<charT, traits>> rhs) noexcept;
770
  ```
771
 
772
  Let `R` denote the type `traits::comparison_category` if that
773
  *qualified-id* is valid and denotes a type [[temp.deduct]], otherwise
774
  `R` is `weak_ordering`.
775
 
776
  *Mandates:* `R` denotes a comparison category type [[cmp.categories]].
777
 
778
  *Returns:* `static_cast<R>(lhs.compare(rhs) <=> 0)`.
779
 
780
+ [*Note 1*: The usage of `type_identity_t` as parameter ensures that an
781
+ object of type `basic_string_view<charT, traits>` can always be compared
782
+ with an object of a type `T` with an implicit conversion to
783
+ `basic_string_view<charT, traits>`, and vice versa, as per
784
+ [[over.match.oper]]. — *end note*]
785
+
786
  ### Inserters and extractors <a id="string.view.io">[[string.view.io]]</a>
787
 
788
  ``` cpp
789
  template<class charT, class traits>
790
  basic_ostream<charT, traits>&
 
797
  range \[`str.begin()`, `str.end()`). Determines padding for `seq` as
798
  described in  [[ostream.formatted.reqmts]]. Then inserts `seq` as if by
799
  calling `os.rdbuf()->sputn(seq, n)`, where `n` is the larger of
800
  `os.width()` and `str.size()`; then calls `os.width(0)`.
801
 
802
+ *Returns:* `os`.
803
 
804
  ### Hash support <a id="string.view.hash">[[string.view.hash]]</a>
805
 
806
  ``` cpp
807
  template<> struct hash<string_view>;