From Jason Turner

[strings]

Large diff (104.7 KB) - rendering may be slow on some devices

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpfixp5gba/{from.md → to.md} +1177 -945
tmp/tmpfixp5gba/{from.md → to.md} RENAMED
@@ -1,32 +1,35 @@
1
  # Strings library <a id="strings">[[strings]]</a>
2
 
3
  ## General <a id="strings.general">[[strings.general]]</a>
4
 
5
  This Clause describes components for manipulating sequences of any
6
- non-array trivial standard-layout [[basic.types]] type. Such types are
7
- called *char-like types*, and objects of char-like types are called
8
- *char-like objects* or simply *characters*.
9
 
10
  The following subclauses describe a character traits class, string
11
  classes, and null-terminated sequence utilities, as summarized in
12
  [[strings.summary]].
13
 
14
  ## Character traits <a id="char.traits">[[char.traits]]</a>
15
 
16
- This subclause defines requirements on classes representing *character
17
- traits*, and defines a class template `char_traits<charT>`, along with
18
- five specializations, `char_traits<char>`, `char_traits<char8_t>`,
19
- `char_traits<char16_t>`, `char_traits<char32_t>`, and
20
- `char_traits<wchar_t>`, that meet those requirements.
 
 
 
21
 
22
  Most classes specified in [[string.classes]], [[string.view]], and
23
  [[input.output]] need a set of related types and functions to complete
24
  the definition of their semantics. These types and functions are
25
  provided as a set of member *typedef-name*s and functions in the
26
- template parameter `traits` used by each such template. This subclause
27
- defines the semantics of these members.
28
 
29
  To specialize those templates to generate a string, string view, or
30
  iostream class to handle a particular character container type
31
  [[defns.character.container]] `C`, that and its related character traits
32
  class `X` are passed as a pair of parameters to the string, string view,
@@ -38,12 +41,13 @@ or iostream template as parameters `charT` and `traits`. If
38
  In [[char.traits.req]], `X` denotes a traits class defining types and
39
  functions for the character container type `C`; `c` and `d` denote
40
  values of type `C`; `p` and `q` denote values of type `const C*`; `s`
41
  denotes a value of type `C*`; `n`, `i` and `j` denote values of type
42
  `size_t`; `e` and `f` denote values of type `X::int_type`; `pos` denotes
43
- a value of type `X::pos_type`; and `r` denotes an lvalue of type `C`.
44
- Operations on `X` shall not throw exceptions.
 
45
 
46
  The class template
47
 
48
  ``` cpp
49
  template<class charT> struct char_traits;
@@ -72,10 +76,12 @@ using state_type = see below;
72
  ([[cpp17.copyconstructible]]), and *Cpp17DefaultConstructible*
73
  ([[cpp17.defaultconstructible]]) requirements.
74
 
75
  ### `char_traits` specializations <a id="char.traits.specializations">[[char.traits.specializations]]</a>
76
 
 
 
77
  ``` cpp
78
  namespace std {
79
  template<> struct char_traits<char>;
80
  template<> struct char_traits<char8_t>;
81
  template<> struct char_traits<char16_t>;
@@ -166,11 +172,11 @@ namespace std {
166
  ```
167
 
168
  The two-argument members `assign`, `eq`, and `lt` are defined
169
  identically to the built-in operators `=`, `==`, and `<` respectively.
170
 
171
- The member `eof()` returns an implementation-defined constant that
172
  cannot appear as a valid UTF-8 code unit.
173
 
174
  #### `struct char_traits<char16_t>` <a id="char.traits.specializations.char16.t">[[char.traits.specializations.char16.t]]</a>
175
 
176
  ``` cpp
@@ -285,12 +291,894 @@ namespace std {
285
  The two-argument members `assign`, `eq`, and `lt` are defined
286
  identically to the built-in operators `=`, `==`, and `<`, respectively.
287
 
288
  The member `eof()` returns `WEOF`.
289
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  ## String classes <a id="string.classes">[[string.classes]]</a>
291
 
 
 
292
  The header `<string>` defines the `basic_string` class template for
293
  manipulating varying-length sequences of char-like objects and five
294
  *typedef-name*s, `string`, `u8string`, `u16string`, `u32string`, and
295
  `wstring`, that name the specializations `basic_string<char>`,
296
  `basic_string<char8_t>`, `basic_string<char16_t>`,
@@ -420,11 +1308,11 @@ namespace std {
420
  erase(basic_string<charT, traits, Allocator>& c, const U& value);
421
  template<class charT, class traits, class Allocator, class Predicate>
422
  constexpr typename basic_string<charT, traits, Allocator>::size_type
423
  erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred);
424
 
425
- // basic_string typedef names
426
  using string = basic_string<char>;
427
  using u8string = basic_string<char8_t>;
428
  using u16string = basic_string<char16_t>;
429
  using u32string = basic_string<char32_t>;
430
  using wstring = basic_string<wchar_t>;
@@ -477,20 +1365,15 @@ namespace std {
477
  using wstring = basic_string<wchar_t>;
478
  }
479
 
480
  // [basic.string.hash], hash support
481
  template<class T> struct hash;
482
- template<> struct hash<string>;
483
- template<> struct hash<u8string>;
484
- template<> struct hash<u16string>;
485
- template<> struct hash<u32string>;
486
- template<> struct hash<wstring>;
487
- template<> struct hash<pmr::string>;
488
- template<> struct hash<pmr::u8string>;
489
- template<> struct hash<pmr::u16string>;
490
- template<> struct hash<pmr::u32string>;
491
- template<> struct hash<pmr::wstring>;
492
 
493
  inline namespace literals {
494
  inline namespace string_literals {
495
  // [basic.string.literals], suffix for basic_string literals
496
  constexpr string operator""s(const char* str, size_t len);
@@ -503,20 +1386,22 @@ namespace std {
503
  }
504
  ```
505
 
506
  ### Class template `basic_string` <a id="basic.string">[[basic.string]]</a>
507
 
 
 
508
  The class template `basic_string` describes objects that can store a
509
  sequence consisting of a varying number of arbitrary char-like objects
510
  with the first element of the sequence at position zero. Such a sequence
511
  is also called a “string” if the type of the char-like objects that it
512
- holds is clear from context. In the rest of this Clause, the type of the
513
- char-like objects held in a `basic_string` object is designated by
514
- `charT`.
515
 
516
  A specialization of `basic_string` is a contiguous container
517
- [[container.requirements.general]].
518
 
519
  In all cases, \[`data()`, `data() + size()`\] is a valid range,
520
  `data() + size()` points at an object with value `charT()` (a “null
521
  terminator”), and `size() <= capacity()` is `true`.
522
 
@@ -539,32 +1424,39 @@ namespace std {
539
 
540
  using iterator = implementation-defined // type of basic_string::iterator; // see [container.requirements]
541
  using const_iterator = implementation-defined // type of basic_string::const_iterator; // see [container.requirements]
542
  using reverse_iterator = std::reverse_iterator<iterator>;
543
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
544
- static const size_type npos = -1;
545
 
546
  // [string.cons], construct/copy/destroy
547
  constexpr basic_string() noexcept(noexcept(Allocator())) : basic_string(Allocator()) { }
548
  constexpr explicit basic_string(const Allocator& a) noexcept;
549
  constexpr basic_string(const basic_string& str);
550
  constexpr basic_string(basic_string&& str) noexcept;
551
  constexpr basic_string(const basic_string& str, size_type pos,
552
  const Allocator& a = Allocator());
553
  constexpr basic_string(const basic_string& str, size_type pos, size_type n,
554
  const Allocator& a = Allocator());
 
 
 
 
555
  template<class T>
556
  constexpr basic_string(const T& t, size_type pos, size_type n,
557
  const Allocator& a = Allocator());
558
  template<class T>
559
  constexpr explicit basic_string(const T& t, const Allocator& a = Allocator());
560
  constexpr basic_string(const charT* s, size_type n, const Allocator& a = Allocator());
561
  constexpr basic_string(const charT* s, const Allocator& a = Allocator());
 
562
  constexpr basic_string(size_type n, charT c, const Allocator& a = Allocator());
563
  template<class InputIterator>
564
  constexpr basic_string(InputIterator begin, InputIterator end,
565
  const Allocator& a = Allocator());
 
 
566
  constexpr basic_string(initializer_list<charT>, const Allocator& = Allocator());
567
  constexpr basic_string(const basic_string&, const Allocator&);
568
  constexpr basic_string(basic_string&&, const Allocator&);
569
  constexpr ~basic_string();
570
 
@@ -573,10 +1465,11 @@ namespace std {
573
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
574
  allocator_traits<Allocator>::is_always_equal::value);
575
  template<class T>
576
  constexpr basic_string& operator=(const T& t);
577
  constexpr basic_string& operator=(const charT* s);
 
578
  constexpr basic_string& operator=(charT c);
579
  constexpr basic_string& operator=(initializer_list<charT>);
580
 
581
  // [string.iterators], iterators
582
  constexpr iterator begin() noexcept;
@@ -598,10 +1491,11 @@ namespace std {
598
  constexpr size_type size() const noexcept;
599
  constexpr size_type length() const noexcept;
600
  constexpr size_type max_size() const noexcept;
601
  constexpr void resize(size_type n, charT c);
602
  constexpr void resize(size_type n);
 
603
  constexpr size_type capacity() const noexcept;
604
  constexpr void reserve(size_type res_arg);
605
  constexpr void shrink_to_fit();
606
  constexpr void clear() noexcept;
607
  [[nodiscard]] constexpr bool empty() const noexcept;
@@ -633,10 +1527,12 @@ namespace std {
633
  constexpr basic_string& append(const charT* s, size_type n);
634
  constexpr basic_string& append(const charT* s);
635
  constexpr basic_string& append(size_type n, charT c);
636
  template<class InputIterator>
637
  constexpr basic_string& append(InputIterator first, InputIterator last);
 
 
638
  constexpr basic_string& append(initializer_list<charT>);
639
 
640
  constexpr void push_back(charT c);
641
 
642
  constexpr basic_string& assign(const basic_string& str);
@@ -651,10 +1547,12 @@ namespace std {
651
  constexpr basic_string& assign(const charT* s, size_type n);
652
  constexpr basic_string& assign(const charT* s);
653
  constexpr basic_string& assign(size_type n, charT c);
654
  template<class InputIterator>
655
  constexpr basic_string& assign(InputIterator first, InputIterator last);
 
 
656
  constexpr basic_string& assign(initializer_list<charT>);
657
 
658
  constexpr basic_string& insert(size_type pos, const basic_string& str);
659
  constexpr basic_string& insert(size_type pos1, const basic_string& str,
660
  size_type pos2, size_type n = npos);
@@ -668,10 +1566,12 @@ namespace std {
668
  constexpr basic_string& insert(size_type pos, size_type n, charT c);
669
  constexpr iterator insert(const_iterator p, charT c);
670
  constexpr iterator insert(const_iterator p, size_type n, charT c);
671
  template<class InputIterator>
672
  constexpr iterator insert(const_iterator p, InputIterator first, InputIterator last);
 
 
673
  constexpr iterator insert(const_iterator p, initializer_list<charT>);
674
 
675
  constexpr basic_string& erase(size_type pos = 0, size_type n = npos);
676
  constexpr iterator erase(const_iterator p);
677
  constexpr iterator erase(const_iterator first, const_iterator last);
@@ -698,10 +1598,12 @@ namespace std {
698
  constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
699
  constexpr basic_string& replace(const_iterator i1, const_iterator i2, size_type n, charT c);
700
  template<class InputIterator>
701
  constexpr basic_string& replace(const_iterator i1, const_iterator i2,
702
  InputIterator j1, InputIterator j2);
 
 
703
  constexpr basic_string& replace(const_iterator, const_iterator, initializer_list<charT>);
704
 
705
  constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
706
 
707
  constexpr void swap(basic_string& str)
@@ -758,11 +1660,12 @@ namespace std {
758
  size_type pos = npos) const noexcept;
759
  constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
760
  constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
761
  constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
762
 
763
- constexpr basic_string substr(size_type pos = 0, size_type n = npos) const;
 
764
 
765
  template<class T>
766
  constexpr int compare(const T& t) const noexcept(see below);
767
  template<class T>
768
  constexpr int compare(size_type pos1, size_type n1, const T& t) const;
@@ -781,19 +1684,29 @@ namespace std {
781
  constexpr bool starts_with(charT x) const noexcept;
782
  constexpr bool starts_with(const charT* x) const;
783
  constexpr bool ends_with(basic_string_view<charT, traits> x) const noexcept;
784
  constexpr bool ends_with(charT x) const noexcept;
785
  constexpr bool ends_with(const charT* x) const;
 
 
 
 
786
  };
787
 
788
  template<class InputIterator,
789
  class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
790
  basic_string(InputIterator, InputIterator, Allocator = Allocator())
791
  -> basic_string<typename iterator_traits<InputIterator>::value_type,
792
  char_traits<typename iterator_traits<InputIterator>::value_type>,
793
  Allocator>;
794
 
 
 
 
 
 
 
795
  template<class charT,
796
  class traits,
797
  class Allocator = allocator<charT>>
798
  explicit basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator())
799
  -> basic_string<charT, traits, Allocator>;
@@ -810,10 +1723,13 @@ namespace std {
810
 
811
  A `size_type` parameter type in a `basic_string` deduction guide refers
812
  to the `size_type` member type of the type deduced by the deduction
813
  guide.
814
 
 
 
 
815
  #### General requirements <a id="string.require">[[string.require]]</a>
816
 
817
  If any operation would cause `size()` to exceed `max_size()`, that
818
  operation throws an exception object of type `length_error`.
819
 
@@ -829,19 +1745,24 @@ as `charT`. Every object of type
829
  objects as needed. The `Allocator` object used is obtained as described
830
  in [[container.requirements.general]]. In every specialization
831
  `basic_string<charT, traits, Allocator>`, the type `traits` shall meet
832
  the character traits requirements [[char.traits]].
833
 
834
- [*Note 1*: The program is ill-formed if `traits::char_type` is not the
 
 
 
 
 
835
  same type as `charT`. — *end note*]
836
 
837
  References, pointers, and iterators referring to the elements of a
838
  `basic_string` sequence may be invalidated by the following uses of that
839
  `basic_string` object:
840
 
841
  - Passing as an argument to any standard library function taking a
842
- reference to non-const `basic_string` as an argument.[^2]
843
  - Calling non-const member functions, except `operator[]`, `at`, `data`,
844
  `front`, `back`, `begin`, `rbegin`, `end`, and `rend`.
845
 
846
  #### Constructors and assignment operators <a id="string.cons">[[string.cons]]</a>
847
 
@@ -865,17 +1786,33 @@ state.
865
  ``` cpp
866
  constexpr basic_string(const basic_string& str, size_type pos,
867
  const Allocator& a = Allocator());
868
  constexpr basic_string(const basic_string& str, size_type pos, size_type n,
869
  const Allocator& a = Allocator());
 
 
 
 
870
  ```
871
 
872
- *Effects:* Let `n` be `npos` for the first overload. Equivalent to:
873
 
874
- ``` cpp
875
- basic_string(basic_string_view<charT, traits>(str).substr(pos, n), a)
876
- ```
 
 
 
 
 
 
 
 
 
 
 
 
877
 
878
  ``` cpp
879
  template<class T>
880
  constexpr basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator());
881
  ```
@@ -950,11 +1887,19 @@ template<class InputIterator>
950
 
951
  *Constraints:* `InputIterator` is a type that qualifies as an input
952
  iterator [[container.requirements.general]].
953
 
954
  *Effects:* Constructs a string from the values in the range \[`begin`,
955
- `end`), as indicated in [[container.seq.req]].
 
 
 
 
 
 
 
 
956
 
957
  ``` cpp
958
  constexpr basic_string(initializer_list<charT> il, const Allocator& a = Allocator());
959
  ```
960
 
@@ -1140,10 +2085,45 @@ constexpr void resize(size_type n, charT c);
1140
  constexpr void resize(size_type n);
1141
  ```
1142
 
1143
  *Effects:* Equivalent to `resize(n, charT())`.
1144
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1145
  ``` cpp
1146
  constexpr size_type capacity() const noexcept;
1147
  ```
1148
 
1149
  *Returns:* The size of the allocated storage in the string.
@@ -1220,14 +2200,14 @@ undefined behavior.
1220
  ``` cpp
1221
  constexpr const_reference at(size_type pos) const;
1222
  constexpr reference at(size_type pos);
1223
  ```
1224
 
1225
- *Throws:* `out_of_range` if `pos >= size()`.
1226
-
1227
  *Returns:* `operator[](pos)`.
1228
 
 
 
1229
  ``` cpp
1230
  constexpr const charT& front() const;
1231
  constexpr charT& front();
1232
  ```
1233
 
@@ -1377,10 +2357,18 @@ template<class InputIterator>
1377
  iterator [[container.requirements.general]].
1378
 
1379
  *Effects:* Equivalent to:
1380
  `return append(basic_string(first, last, get_allocator()));`
1381
 
 
 
 
 
 
 
 
 
1382
  ``` cpp
1383
  constexpr basic_string& append(initializer_list<charT> il);
1384
  ```
1385
 
1386
  *Effects:* Equivalent to: `return append(il.begin(), il.size());`
@@ -1497,10 +2485,18 @@ template<class InputIterator>
1497
  iterator [[container.requirements.general]].
1498
 
1499
  *Effects:* Equivalent to:
1500
  `return assign(basic_string(first, last, get_allocator()));`
1501
 
 
 
 
 
 
 
 
 
1502
  ##### `basic_string::insert` <a id="string.insert">[[string.insert]]</a>
1503
 
1504
  ``` cpp
1505
  constexpr basic_string& insert(size_type pos, const basic_string& str);
1506
  ```
@@ -1559,22 +2555,22 @@ return insert(pos1, sv.substr(pos2, n));
1559
  constexpr basic_string& insert(size_type pos, const charT* s, size_type n);
1560
  ```
1561
 
1562
  *Preconditions:* \[`s`, `s + n`) is a valid range.
1563
 
1564
- *Throws:*
1565
-
1566
- - `out_of_range` if `pos > size()`,
1567
- - `length_error` if `n > max_size() - size()`, or
1568
- - any exceptions thrown by `allocator_traits<Allocator>::allocate`.
1569
-
1570
  *Effects:* Inserts a copy of the range \[`s`, `s + n`) immediately
1571
  before the character at position `pos` if `pos < size()`, or otherwise
1572
  at the end of the string.
1573
 
1574
  *Returns:* `*this`.
1575
 
 
 
 
 
 
 
1576
  ``` cpp
1577
  constexpr basic_string& insert(size_type pos, const charT* s);
1578
  ```
1579
 
1580
  *Effects:* Equivalent to: `return insert(pos, s, traits::length(s));`
@@ -1629,10 +2625,23 @@ iterator [[container.requirements.general]].
1629
  `insert(p - begin(), basic_string(first, last, get_allocator()))`.
1630
 
1631
  *Returns:* An iterator which refers to the first inserted character, or
1632
  `p` if `first == last`.
1633
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1634
  ``` cpp
1635
  constexpr iterator insert(const_iterator p, initializer_list<charT> il);
1636
  ```
1637
 
1638
  *Effects:* Equivalent to: `return insert(p, il.begin(), il.end());`
@@ -1641,57 +2650,57 @@ constexpr iterator insert(const_iterator p, initializer_list<charT> il);
1641
 
1642
  ``` cpp
1643
  constexpr basic_string& erase(size_type pos = 0, size_type n = npos);
1644
  ```
1645
 
1646
- *Throws:* `out_of_range` if `pos` `> size()`.
1647
-
1648
  *Effects:* Determines the effective length `xlen` of the string to be
1649
  removed as the smaller of `n` and `size() - pos`. Removes the characters
1650
  in the range \[`begin() + pos`, `begin() + pos + xlen`).
1651
 
1652
  *Returns:* `*this`.
1653
 
 
 
1654
  ``` cpp
1655
  constexpr iterator erase(const_iterator p);
1656
  ```
1657
 
1658
  *Preconditions:* `p` is a valid dereferenceable iterator on `*this`.
1659
 
1660
- *Throws:* Nothing.
1661
-
1662
  *Effects:* Removes the character referred to by `p`.
1663
 
1664
  *Returns:* An iterator which points to the element immediately following
1665
  `p` prior to the element being erased. If no such element exists,
1666
  `end()` is returned.
1667
 
 
 
1668
  ``` cpp
1669
  constexpr iterator erase(const_iterator first, const_iterator last);
1670
  ```
1671
 
1672
  *Preconditions:* `first` and `last` are valid iterators on `*this`.
1673
  \[`first`, `last`) is a valid range.
1674
 
1675
- *Throws:* Nothing.
1676
-
1677
  *Effects:* Removes the characters in the range `[first, last)`.
1678
 
1679
  *Returns:* An iterator which points to the element pointed to by `last`
1680
  prior to the other elements being erased. If no such element exists,
1681
  `end()` is returned.
1682
 
 
 
1683
  ``` cpp
1684
  constexpr void pop_back();
1685
  ```
1686
 
1687
  *Preconditions:* `!empty()`.
1688
 
1689
- *Throws:* Nothing.
1690
-
1691
  *Effects:* Equivalent to `erase(end() - 1)`.
1692
 
 
 
1693
  ##### `basic_string::replace` <a id="string.replace">[[string.replace]]</a>
1694
 
1695
  ``` cpp
1696
  constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
1697
  ```
@@ -1751,25 +2760,25 @@ return replace(pos1, n1, sv.substr(pos2, n2));
1751
  constexpr basic_string& replace(size_type pos1, size_type n1, const charT* s, size_type n2);
1752
  ```
1753
 
1754
  *Preconditions:* \[`s`, `s + n2`) is a valid range.
1755
 
1756
- *Throws:*
1757
-
1758
- - `out_of_range` if `pos1 > size()`,
1759
- - `length_error` if the length of the resulting string would exceed
1760
- `max_size()` (see below), or
1761
- - any exceptions thrown by `allocator_traits<Allocator>::allocate`.
1762
-
1763
  *Effects:* Determines the effective length `xlen` of the string to be
1764
  removed as the smaller of `n1` and `size() - pos1`. If
1765
  `size() - xlen >= max_size() - n2` throws `length_error`. Otherwise, the
1766
  function replaces the characters in the range \[`begin() + pos1`,
1767
  `begin() + pos1 + xlen`) with a copy of the range \[`s`, `s + n2`).
1768
 
1769
  *Returns:* `*this`.
1770
 
 
 
 
 
 
 
 
1771
  ``` cpp
1772
  constexpr basic_string& replace(size_type pos, size_type n, const charT* s);
1773
  ```
1774
 
1775
  *Effects:* Equivalent to:
@@ -1777,25 +2786,25 @@ constexpr basic_string& replace(size_type pos, size_type n, const charT* s);
1777
 
1778
  ``` cpp
1779
  constexpr basic_string& replace(size_type pos1, size_type n1, size_type n2, charT c);
1780
  ```
1781
 
1782
- *Throws:*
1783
-
1784
- - `out_of_range` if `pos1 > size()`,
1785
- - `length_error` if the length of the resulting string would exceed
1786
- `max_size()` (see below), or
1787
- - any exceptions thrown by `allocator_traits<Allocator>::allocate.`
1788
-
1789
  *Effects:* Determines the effective length `xlen` of the string to be
1790
  removed as the smaller of `n1` and `size() - pos1`. If
1791
  `size() - xlen >=` `max_size() - n2` throws `length_error`. Otherwise,
1792
  the function replaces the characters in the range \[`begin() + pos1`,
1793
  `begin() + pos1 + xlen`) with `n2` copies of `c`.
1794
 
1795
  *Returns:* `*this`.
1796
 
 
 
 
 
 
 
 
1797
  ``` cpp
1798
  constexpr basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
1799
  ```
1800
 
1801
  *Effects:* Equivalent to:
@@ -1853,10 +2862,21 @@ template<class InputIterator>
1853
  iterator [[container.requirements.general]].
1854
 
1855
  *Effects:* Equivalent to:
1856
  `return replace(i1, i2, basic_string(j1, j2, get_allocator()));`
1857
 
 
 
 
 
 
 
 
 
 
 
 
1858
  ``` cpp
1859
  constexpr basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<charT> il);
1860
  ```
1861
 
1862
  *Effects:* Equivalent to:
@@ -1999,25 +3019,27 @@ template<class T>
1999
  ``` cpp
2000
  basic_string_view<charT, traits> s = *this, sv = t;
2001
  return s.G(sv, pos);
2002
  ```
2003
 
2004
- *Remarks:* The expression inside `noexcept` is equivalent to
2005
  `is_nothrow_convertible_v<const T&, basic_string_view<charT, traits>>`.
2006
 
2007
  ##### `basic_string::substr` <a id="string.substr">[[string.substr]]</a>
2008
 
2009
  ``` cpp
2010
- constexpr basic_string substr(size_type pos = 0, size_type n = npos) const;
2011
  ```
2012
 
2013
- *Throws:* `out_of_range` if `pos > size()`.
2014
 
2015
- *Effects:* Determines the effective length `rlen` of the string to copy
2016
- as the smaller of `n` and `size() - pos`.
 
2017
 
2018
- *Returns:* `basic_string(data()+pos, rlen)`.
 
2019
 
2020
  ##### `basic_string::compare` <a id="string.compare">[[string.compare]]</a>
2021
 
2022
  ``` cpp
2023
  template<class T>
@@ -2031,11 +3053,11 @@ template<class T>
2031
  - `is_convertible_v<const T&, const charT*>` is `false`.
2032
 
2033
  *Effects:* Equivalent to:
2034
  `return basic_string_view<charT, traits>(*this).compare(t);`
2035
 
2036
- *Remarks:* The expression inside `noexcept` is equivalent to
2037
  `is_nothrow_convertible_v<const T&, basic_string_view<charT, traits>>`.
2038
 
2039
  ``` cpp
2040
  template<class T>
2041
  constexpr int compare(size_type pos1, size_type n1, const T& t) const;
@@ -2144,10 +3166,24 @@ constexpr bool ends_with(const charT* x) const;
2144
 
2145
  ``` cpp
2146
  return basic_string_view<charT, traits>(data(), size()).ends_with(x);
2147
  ```
2148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2149
  ### Non-member functions <a id="string.nonmembers">[[string.nonmembers]]</a>
2150
 
2151
  #### `operator+` <a id="string.op.plus">[[string.op.plus]]</a>
2152
 
2153
  ``` cpp
@@ -2201,11 +3237,11 @@ return std::move(lhs);
2201
 
2202
  except that both `lhs` and `rhs` are left in valid but unspecified
2203
  states.
2204
 
2205
  [*Note 1*: If `lhs` and `rhs` have equal allocators, the implementation
2206
- may move from either. — *end note*]
2207
 
2208
  ``` cpp
2209
  template<class charT, class traits, class Allocator>
2210
  constexpr basic_string<charT, traits, Allocator>
2211
  operator+(const basic_string<charT, traits, Allocator>& lhs,
@@ -2288,11 +3324,11 @@ template<class charT, class traits, class Allocator>
2288
  ``` cpp
2289
  lhs.push_back(rhs);
2290
  return std::move(lhs);
2291
  ```
2292
 
2293
- #### Non-member comparison functions <a id="string.cmp">[[string.cmp]]</a>
2294
 
2295
  ``` cpp
2296
  template<class charT, class traits, class Allocator>
2297
  constexpr bool
2298
  operator==(const basic_string<charT, traits, Allocator>& lhs,
@@ -2335,28 +3371,27 @@ template<class charT, class traits, class Allocator>
2335
  operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
2336
  ```
2337
 
2338
  *Effects:* Behaves as a formatted input
2339
  function [[istream.formatted.reqmts]]. After constructing a `sentry`
2340
- object, if the sentry converts to `true`, calls `str.erase()` and then
2341
- extracts characters from `is` and appends them to `str` as if by calling
2342
- `str.append(1, c)`. If `is.width()` is greater than zero, the maximum
2343
- number `n` of characters appended is `is.width()`; otherwise `n` is
2344
- `str.max_size()`. Characters are extracted and appended until any of the
2345
- following occurs:
2346
 
2347
  - *n* characters are stored;
2348
  - end-of-file occurs on the input sequence;
2349
  - `isspace(c, is.getloc())` is `true` for the next available input
2350
  character *c*.
2351
 
2352
  After the last character (if any) is extracted, `is.width(0)` is called
2353
  and the `sentry` object is destroyed.
2354
 
2355
- If the function extracts no characters, it calls
2356
- `is.setstate(ios_base::failbit)`, which may throw `ios_base::failure`
2357
- [[iostate.flags]].
2358
 
2359
  *Returns:* `is`.
2360
 
2361
  ``` cpp
2362
  template<class charT, class traits, class Allocator>
@@ -2382,28 +3417,26 @@ template<class charT, class traits, class Allocator>
2382
  ```
2383
 
2384
  *Effects:* Behaves as an unformatted input
2385
  function [[istream.unformatted]], except that it does not affect the
2386
  value returned by subsequent calls to `basic_istream<>::gcount()`. After
2387
- constructing a `sentry` object, if the sentry converts to `true`, calls
2388
- `str.erase()` and then extracts characters from `is` and appends them to
2389
- `str` as if by calling `str.append(1, c)` until any of the following
2390
- occurs:
2391
 
2392
- - end-of-file occurs on the input sequence (in which case, the `getline`
2393
- function calls `is.setstate(ios_base::eofbit)`).
2394
  - `traits::eq(c, delim)` for the next available input character *c* (in
2395
- which case, *c* is extracted but not appended) [[iostate.flags]]
2396
- - `str.max_size()` characters are stored (in which case, the function
2397
- calls `is.setstate(ios_base::failbit))` [[iostate.flags]]
2398
 
2399
  The conditions are tested in the order shown. In any case, after the
2400
  last character is extracted, the `sentry` object is destroyed.
2401
 
2402
- If the function extracts no characters, it calls
2403
- `is.setstate(ios_base::failbit)` which may throw `ios_base::failure`
2404
- [[iostate.flags]].
2405
 
2406
  *Returns:* `is`.
2407
 
2408
  ``` cpp
2409
  template<class charT, class traits, class Allocator>
@@ -2465,17 +3498,17 @@ unsigned long long stoull(const string& str, size_t* idx = nullptr, int base = 1
2465
  `strtoul(str.c_str(), ptr, base)`, `strtoll(str.c_str(), ptr, base)`,
2466
  and `strtoull(str.c_str(), ptr, base)`, respectively. Each function
2467
  returns the converted result, if any. The argument `ptr` designates a
2468
  pointer to an object internal to the function that is used to determine
2469
  what to store at `*idx`. If the function does not throw an exception and
2470
- `idx != 0`, the function stores in `*idx` the index of the first
2471
  unconverted element of `str`.
2472
 
2473
  *Returns:* The converted result.
2474
 
2475
  *Throws:* `invalid_argument` if `strtol`, `strtoul`, `strtoll`, or
2476
- `strtoull` reports that no conversion could be performed. Throws
2477
  `out_of_range` if `strtol`, `strtoul`, `strtoll` or `strtoull` sets
2478
  `errno` to `ERANGE`, or if the converted value is outside the range of
2479
  representable values for the return type.
2480
 
2481
  ``` cpp
@@ -2487,20 +3520,19 @@ long double stold(const string& str, size_t* idx = nullptr);
2487
  *Effects:* These functions call `strtof(str.c_str(), ptr)`,
2488
  `strtod(str.c_str(), ptr)`, and `strtold(str.c_str(), ptr)`,
2489
  respectively. Each function returns the converted result, if any. The
2490
  argument `ptr` designates a pointer to an object internal to the
2491
  function that is used to determine what to store at `*idx`. If the
2492
- function does not throw an exception and `idx != 0`, the function stores
2493
- in `*idx` the index of the first unconverted element of `str`.
2494
 
2495
  *Returns:* The converted result.
2496
 
2497
  *Throws:* `invalid_argument` if `strtof`, `strtod`, or `strtold` reports
2498
- that no conversion could be performed. Throws `out_of_range` if
2499
- `strtof`, `strtod`, or `strtold` sets `errno` to `ERANGE` or if the
2500
- converted value is outside the range of representable values for the
2501
- return type.
2502
 
2503
  ``` cpp
2504
  string to_string(int val);
2505
  string to_string(unsigned val);
2506
  string to_string(long val);
@@ -2532,17 +3564,17 @@ unsigned long long stoull(const wstring& str, size_t* idx = nullptr, int base =
2532
  `wcstoul(str.c_str(), ptr, base)`, `wcstoll(str.c_str(), ptr, base)`,
2533
  and `wcstoull(str.c_str(), ptr, base)`, respectively. Each function
2534
  returns the converted result, if any. The argument `ptr` designates a
2535
  pointer to an object internal to the function that is used to determine
2536
  what to store at `*idx`. If the function does not throw an exception and
2537
- `idx != 0`, the function stores in `*idx` the index of the first
2538
  unconverted element of `str`.
2539
 
2540
  *Returns:* The converted result.
2541
 
2542
  *Throws:* `invalid_argument` if `wcstol`, `wcstoul`, `wcstoll`, or
2543
- `wcstoull` reports that no conversion could be performed. Throws
2544
  `out_of_range` if the converted value is outside the range of
2545
  representable values for the return type.
2546
 
2547
  ``` cpp
2548
  float stof(const wstring& str, size_t* idx = nullptr);
@@ -2553,18 +3585,18 @@ long double stold(const wstring& str, size_t* idx = nullptr);
2553
  *Effects:* These functions call `wcstof(str.c_str(), ptr)`,
2554
  `wcstod(str.c_str(), ptr)`, and `wcstold(str.c_str(), ptr)`,
2555
  respectively. Each function returns the converted result, if any. The
2556
  argument `ptr` designates a pointer to an object internal to the
2557
  function that is used to determine what to store at `*idx`. If the
2558
- function does not throw an exception and `idx != 0`, the function stores
2559
- in `*idx` the index of the first unconverted element of `str`.
2560
 
2561
  *Returns:* The converted result.
2562
 
2563
  *Throws:* `invalid_argument` if `wcstof`, `wcstod`, or `wcstold` reports
2564
- that no conversion could be performed. Throws `out_of_range` if
2565
- `wcstof`, `wcstod`, or `wcstold` sets `errno` to `ERANGE`.
2566
 
2567
  ``` cpp
2568
  wstring to_wstring(int val);
2569
  wstring to_wstring(unsigned val);
2570
  wstring to_wstring(long val);
@@ -2584,20 +3616,15 @@ specifier of `L"%d"`, `L"%u"`, `L"%ld"`, `L"%lu"`, `L"%lld"`, `L"%llu"`,
2584
  internal character buffer of sufficient size `buffsz`.
2585
 
2586
  ### Hash support <a id="basic.string.hash">[[basic.string.hash]]</a>
2587
 
2588
  ``` cpp
2589
- template<> struct hash<string>;
2590
- template<> struct hash<u8string>;
2591
- template<> struct hash<u16string>;
2592
- template<> struct hash<u32string>;
2593
- template<> struct hash<wstring>;
2594
- template<> struct hash<pmr::string>;
2595
- template<> struct hash<pmr::u8string>;
2596
- template<> struct hash<pmr::u16string>;
2597
- template<> struct hash<pmr::u32string>;
2598
- template<> struct hash<pmr::wstring>;
2599
  ```
2600
 
2601
  If `S` is one of these string types, `SV` is the corresponding string
2602
  view type, and `s` is an object of type `S`, then
2603
  `hash<S>()(s) == hash<SV>()(SV(s))`.
@@ -2637,822 +3664,10 @@ constexpr wstring operator""s(const wchar_t* str, size_t len);
2637
  [*Note 1*: The same suffix `s` is used for `chrono::duration` literals
2638
  denoting seconds but there is no conflict, since duration suffixes apply
2639
  to numbers and string literal suffixes apply to character array
2640
  literals. — *end note*]
2641
 
2642
- ## String view classes <a id="string.view">[[string.view]]</a>
2643
-
2644
- The class template `basic_string_view` describes an object that can
2645
- refer to a constant contiguous sequence of char-like [[strings.general]]
2646
- objects with the first element of the sequence at position zero. In the
2647
- rest of this subclause, the type of the char-like objects held in a
2648
- `basic_string_view` object is designated by `charT`.
2649
-
2650
- [*Note 1*: The library provides implicit conversions from
2651
- `const charT*` and `std::basic_string<charT, ...>` to
2652
- `std::basic_string_view<charT, ...>` so that user code can accept just
2653
- `std::basic_string_view<charT>` as a non-templated parameter wherever a
2654
- sequence of characters is expected. User-defined types should define
2655
- their own implicit conversions to `std::basic_string_view` in order to
2656
- interoperate with these functions. — *end note*]
2657
-
2658
- ### Header `<string_view>` synopsis <a id="string.view.synop">[[string.view.synop]]</a>
2659
-
2660
- ``` cpp
2661
- #include <compare> // see [compare.syn]
2662
-
2663
- namespace std {
2664
- // [string.view.template], class template basic_string_view
2665
- template<class charT, class traits = char_traits<charT>>
2666
- class basic_string_view;
2667
-
2668
- template<class charT, class traits>
2669
- inline constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true;
2670
- template<class charT, class traits>
2671
- inline constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true;
2672
-
2673
- // [string.view.comparison], non-member comparison functions
2674
- template<class charT, class traits>
2675
- constexpr bool operator==(basic_string_view<charT, traits> x,
2676
- basic_string_view<charT, traits> y) noexcept;
2677
- template<class charT, class traits>
2678
- constexpr see below operator<=>(basic_string_view<charT, traits> x,
2679
- \itcorr basic_string_view<charT, traits> y) noexcept;
2680
-
2681
- // see [string.view.comparison], sufficient additional overloads of comparison functions
2682
-
2683
- // [string.view.io], inserters and extractors
2684
- template<class charT, class traits>
2685
- basic_ostream<charT, traits>&
2686
- operator<<(basic_ostream<charT, traits>& os,
2687
- basic_string_view<charT, traits> str);
2688
-
2689
- // basic_string_view typedef names
2690
- using string_view = basic_string_view<char>;
2691
- using u8string_view = basic_string_view<char8_t>;
2692
- using u16string_view = basic_string_view<char16_t>;
2693
- using u32string_view = basic_string_view<char32_t>;
2694
- using wstring_view = basic_string_view<wchar_t>;
2695
-
2696
- // [string.view.hash], hash support
2697
- template<class T> struct hash;
2698
- template<> struct hash<string_view>;
2699
- template<> struct hash<u8string_view>;
2700
- template<> struct hash<u16string_view>;
2701
- template<> struct hash<u32string_view>;
2702
- template<> struct hash<wstring_view>;
2703
-
2704
- inline namespace literals {
2705
- inline namespace string_view_literals {
2706
- // [string.view.literals], suffix for basic_string_view literals
2707
- constexpr string_view operator""sv(const char* str, size_t len) noexcept;
2708
- constexpr u8string_view operator""sv(const char8_t* str, size_t len) noexcept;
2709
- constexpr u16string_view operator""sv(const char16_t* str, size_t len) noexcept;
2710
- constexpr u32string_view operator""sv(const char32_t* str, size_t len) noexcept;
2711
- constexpr wstring_view operator""sv(const wchar_t* str, size_t len) noexcept;
2712
- }
2713
- }
2714
- }
2715
- ```
2716
-
2717
- The function templates defined in [[utility.swap]] and
2718
- [[iterator.range]] are available when `<string_view>` is included.
2719
-
2720
- ### Class template `basic_string_view` <a id="string.view.template">[[string.view.template]]</a>
2721
-
2722
- ``` cpp
2723
- template<class charT, class traits = char_traits<charT>>
2724
- class basic_string_view {
2725
- public:
2726
- // types
2727
- using traits_type = traits;
2728
- using value_type = charT;
2729
- using pointer = value_type*;
2730
- using const_pointer = const value_type*;
2731
- using reference = value_type&;
2732
- using const_reference = const value_type&;
2733
- using const_iterator = implementation-defined // type of basic_string_view::const_iterator; // see [string.view.iterators]
2734
- using iterator = const_iterator;\footnote{Because basic_string_view refers to a constant sequence, iterator and const_iterator are the same type.}
2735
- using const_reverse_iterator = reverse_iterator<const_iterator>;
2736
- using reverse_iterator = const_reverse_iterator;
2737
- using size_type = size_t;
2738
- using difference_type = ptrdiff_t;
2739
- static constexpr size_type npos = size_type(-1);
2740
-
2741
- // [string.view.cons], construction and assignment
2742
- constexpr basic_string_view() noexcept;
2743
- constexpr basic_string_view(const basic_string_view&) noexcept = default;
2744
- constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default;
2745
- constexpr basic_string_view(const charT* str);
2746
- constexpr basic_string_view(const charT* str, size_type len);
2747
- template<class It, class End>
2748
- constexpr basic_string_view(It begin, End end);
2749
-
2750
- // [string.view.iterators], iterator support
2751
- constexpr const_iterator begin() const noexcept;
2752
- constexpr const_iterator end() const noexcept;
2753
- constexpr const_iterator cbegin() const noexcept;
2754
- constexpr const_iterator cend() const noexcept;
2755
- constexpr const_reverse_iterator rbegin() const noexcept;
2756
- constexpr const_reverse_iterator rend() const noexcept;
2757
- constexpr const_reverse_iterator crbegin() const noexcept;
2758
- constexpr const_reverse_iterator crend() const noexcept;
2759
-
2760
- // [string.view.capacity], capacity
2761
- constexpr size_type size() const noexcept;
2762
- constexpr size_type length() const noexcept;
2763
- constexpr size_type max_size() const noexcept;
2764
- [[nodiscard]] constexpr bool empty() const noexcept;
2765
-
2766
- // [string.view.access], element access
2767
- constexpr const_reference operator[](size_type pos) const;
2768
- constexpr const_reference at(size_type pos) const;
2769
- constexpr const_reference front() const;
2770
- constexpr const_reference back() const;
2771
- constexpr const_pointer data() const noexcept;
2772
-
2773
- // [string.view.modifiers], modifiers
2774
- constexpr void remove_prefix(size_type n);
2775
- constexpr void remove_suffix(size_type n);
2776
- constexpr void swap(basic_string_view& s) noexcept;
2777
-
2778
- // [string.view.ops], string operations
2779
- constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
2780
-
2781
- constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
2782
-
2783
- constexpr int compare(basic_string_view s) const noexcept;
2784
- constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
2785
- constexpr int compare(size_type pos1, size_type n1, basic_string_view s,
2786
- size_type pos2, size_type n2) const;
2787
- constexpr int compare(const charT* s) const;
2788
- constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
2789
- constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;
2790
-
2791
- constexpr bool starts_with(basic_string_view x) const noexcept;
2792
- constexpr bool starts_with(charT x) const noexcept;
2793
- constexpr bool starts_with(const charT* x) const;
2794
- constexpr bool ends_with(basic_string_view x) const noexcept;
2795
- constexpr bool ends_with(charT x) const noexcept;
2796
- constexpr bool ends_with(const charT* x) const;
2797
-
2798
- // [string.view.find], searching
2799
- constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
2800
- constexpr size_type find(charT c, size_type pos = 0) const noexcept;
2801
- constexpr size_type find(const charT* s, size_type pos, size_type n) const;
2802
- constexpr size_type find(const charT* s, size_type pos = 0) const;
2803
- constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
2804
- constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
2805
- constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
2806
- constexpr size_type rfind(const charT* s, size_type pos = npos) const;
2807
-
2808
- constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
2809
- constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
2810
- constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
2811
- constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
2812
- constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
2813
- constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
2814
- constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const;
2815
- constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;
2816
- constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
2817
- constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
2818
- constexpr size_type find_first_not_of(const charT* s, size_type pos,
2819
- size_type n) const;
2820
- constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const;
2821
- constexpr size_type find_last_not_of(basic_string_view s,
2822
- size_type pos = npos) const noexcept;
2823
- constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
2824
- constexpr size_type find_last_not_of(const charT* s, size_type pos,
2825
- size_type n) const;
2826
- constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
2827
-
2828
- private:
2829
- const_pointer data_; // exposition only
2830
- size_type size_; // exposition only
2831
- };
2832
-
2833
- // [string.view.deduct], deduction guide
2834
- template<class It, class End>
2835
- basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
2836
- ```
2837
-
2838
- In every specialization `basic_string_view<charT, traits>`, the type
2839
- `traits` shall meet the character traits requirements [[char.traits]].
2840
-
2841
- [*Note 1*: The program is ill-formed if `traits::char_type` is not the
2842
- same type as `charT`. — *end note*]
2843
-
2844
- For a `basic_string_view str`, any operation that invalidates a pointer
2845
- in the range \[`str.data()`, `str.data() + str.size()`) invalidates
2846
- pointers, iterators, and references returned from `str`’s member
2847
- functions.
2848
-
2849
- The complexity of `basic_string_view` member functions is 𝑂(1) unless
2850
- otherwise specified.
2851
-
2852
- #### Construction and assignment <a id="string.view.cons">[[string.view.cons]]</a>
2853
-
2854
- ``` cpp
2855
- constexpr basic_string_view() noexcept;
2856
- ```
2857
-
2858
- *Ensures:* `size_ == 0` and `data_ == nullptr`.
2859
-
2860
- ``` cpp
2861
- constexpr basic_string_view(const charT* str);
2862
- ```
2863
-
2864
- *Preconditions:* \[`str`, `str + traits::length(str)`) is a valid range.
2865
-
2866
- *Effects:* Constructs a `basic_string_view`, initializing `data_` with
2867
- `str` and initializing `size_` with `traits::length(str)`.
2868
-
2869
- *Complexity:* 𝑂(`traits::length(str)`).
2870
-
2871
- ``` cpp
2872
- constexpr basic_string_view(const charT* str, size_type len);
2873
- ```
2874
-
2875
- *Preconditions:* \[`str`, `str + len`) is a valid range.
2876
-
2877
- *Effects:* Constructs a `basic_string_view`, initializing `data_` with
2878
- `str` and initializing `size_` with `len`.
2879
-
2880
- ``` cpp
2881
- template<class It, class End>
2882
- constexpr basic_string_view(It begin, End end);
2883
- ```
2884
-
2885
- *Constraints:*
2886
-
2887
- - `It` satisfies `contiguous_iterator`.
2888
- - `End` satisfies `sized_sentinel_for<It>`.
2889
- - `is_same_v<iter_value_t<It>, charT>` is `true`.
2890
- - `is_convertible_v<End, size_type>` is `false`.
2891
-
2892
- *Preconditions:*
2893
-
2894
- - \[`begin`, `end`) is a valid range.
2895
- - `It` models `contiguous_iterator`.
2896
- - `End` models `sized_sentinel_for<It>`.
2897
-
2898
- *Effects:* Initializes `data_` with `to_address(begin)` and initializes
2899
- `size_` with `end - begin`.
2900
-
2901
- #### Iterator support <a id="string.view.iterators">[[string.view.iterators]]</a>
2902
-
2903
- ``` cpp
2904
- using const_iterator = implementation-defined // type of basic_string_view::const_iterator;
2905
- ```
2906
-
2907
- A type that meets the requirements of a constant
2908
- *Cpp17RandomAccessIterator*[[random.access.iterators]], models
2909
- `contiguous_iterator` [[iterator.concept.contiguous]], and meets the
2910
- constexpr iterator requirements [[iterator.requirements.general]], whose
2911
- `value_type` is the template parameter `charT`.
2912
-
2913
- All requirements on container iterators [[container.requirements]] apply
2914
- to `basic_string_view::const_iterator` as well.
2915
-
2916
- ``` cpp
2917
- constexpr const_iterator begin() const noexcept;
2918
- constexpr const_iterator cbegin() const noexcept;
2919
- ```
2920
-
2921
- *Returns:* An iterator such that
2922
-
2923
- - if `!empty()`, `addressof(*begin()) == data_`,
2924
- - otherwise, an unspecified value such that \[`begin()`, `end()`) is a
2925
- valid range.
2926
-
2927
- ``` cpp
2928
- constexpr const_iterator end() const noexcept;
2929
- constexpr const_iterator cend() const noexcept;
2930
- ```
2931
-
2932
- *Returns:* `begin() + size()`.
2933
-
2934
- ``` cpp
2935
- constexpr const_reverse_iterator rbegin() const noexcept;
2936
- constexpr const_reverse_iterator crbegin() const noexcept;
2937
- ```
2938
-
2939
- *Returns:* `const_reverse_iterator(end())`.
2940
-
2941
- ``` cpp
2942
- constexpr const_reverse_iterator rend() const noexcept;
2943
- constexpr const_reverse_iterator crend() const noexcept;
2944
- ```
2945
-
2946
- *Returns:* `const_reverse_iterator(begin())`.
2947
-
2948
- #### Capacity <a id="string.view.capacity">[[string.view.capacity]]</a>
2949
-
2950
- ``` cpp
2951
- constexpr size_type size() const noexcept;
2952
- constexpr size_type length() const noexcept;
2953
- ```
2954
-
2955
- *Returns:* `size_`.
2956
-
2957
- ``` cpp
2958
- constexpr size_type max_size() const noexcept;
2959
- ```
2960
-
2961
- *Returns:* The largest possible number of char-like objects that can be
2962
- referred to by a `basic_string_view`.
2963
-
2964
- ``` cpp
2965
- [[nodiscard]] constexpr bool empty() const noexcept;
2966
- ```
2967
-
2968
- *Returns:* `size_ == 0`.
2969
-
2970
- #### Element access <a id="string.view.access">[[string.view.access]]</a>
2971
-
2972
- ``` cpp
2973
- constexpr const_reference operator[](size_type pos) const;
2974
- ```
2975
-
2976
- *Preconditions:* `pos < size()`.
2977
-
2978
- *Returns:* `data_[pos]`.
2979
-
2980
- *Throws:* Nothing.
2981
-
2982
- [*Note 1*: Unlike `basic_string::operator[]`,
2983
- `basic_string_view::operator[](size())` has undefined behavior instead
2984
- of returning `charT()`. — *end note*]
2985
-
2986
- ``` cpp
2987
- constexpr const_reference at(size_type pos) const;
2988
- ```
2989
-
2990
- *Throws:* `out_of_range` if `pos >= size()`.
2991
-
2992
- *Returns:* `data_[pos]`.
2993
-
2994
- ``` cpp
2995
- constexpr const_reference front() const;
2996
- ```
2997
-
2998
- *Preconditions:* `!empty()`.
2999
-
3000
- *Returns:* `data_[0]`.
3001
-
3002
- *Throws:* Nothing.
3003
-
3004
- ``` cpp
3005
- constexpr const_reference back() const;
3006
- ```
3007
-
3008
- *Preconditions:* `!empty()`.
3009
-
3010
- *Returns:* `data_[size() - 1]`.
3011
-
3012
- *Throws:* Nothing.
3013
-
3014
- ``` cpp
3015
- constexpr const_pointer data() const noexcept;
3016
- ```
3017
-
3018
- *Returns:* `data_`.
3019
-
3020
- [*Note 2*: Unlike `basic_string::data()` and *string-literal*s,
3021
- `data()` may return a pointer to a buffer that is not null-terminated.
3022
- Therefore it is typically a mistake to pass `data()` to a function that
3023
- takes just a `const charT*` and expects a null-terminated
3024
- string. — *end note*]
3025
-
3026
- #### Modifiers <a id="string.view.modifiers">[[string.view.modifiers]]</a>
3027
-
3028
- ``` cpp
3029
- constexpr void remove_prefix(size_type n);
3030
- ```
3031
-
3032
- *Preconditions:* `n <= size()`.
3033
-
3034
- *Effects:* Equivalent to: `data_ += n; size_ -= n;`
3035
-
3036
- ``` cpp
3037
- constexpr void remove_suffix(size_type n);
3038
- ```
3039
-
3040
- *Preconditions:* `n <= size()`.
3041
-
3042
- *Effects:* Equivalent to: `size_ -= n;`
3043
-
3044
- ``` cpp
3045
- constexpr void swap(basic_string_view& s) noexcept;
3046
- ```
3047
-
3048
- *Effects:* Exchanges the values of `*this` and `s`.
3049
-
3050
- #### String operations <a id="string.view.ops">[[string.view.ops]]</a>
3051
-
3052
- ``` cpp
3053
- constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
3054
- ```
3055
-
3056
- Let `rlen` be the smaller of `n` and `size() - pos`.
3057
-
3058
- *Throws:* `out_of_range` if `pos > size()`.
3059
-
3060
- *Preconditions:* \[`s`, `s + rlen`) is a valid range.
3061
-
3062
- *Effects:* Equivalent to `traits::copy(s, data() + pos, rlen)`.
3063
-
3064
- *Returns:* `rlen`.
3065
-
3066
- *Complexity:* 𝑂(`rlen`).
3067
-
3068
- ``` cpp
3069
- constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
3070
- ```
3071
-
3072
- Let `rlen` be the smaller of `n` and `size() - pos`.
3073
-
3074
- *Throws:* `out_of_range` if `pos > size()`.
3075
-
3076
- *Effects:* Determines `rlen`, the effective length of the string to
3077
- reference.
3078
-
3079
- *Returns:* `basic_string_view(data() + pos, rlen)`.
3080
-
3081
- ``` cpp
3082
- constexpr int compare(basic_string_view str) const noexcept;
3083
- ```
3084
-
3085
- Let `rlen` be the smaller of `size()` and `str.size()`.
3086
-
3087
- *Effects:* Determines `rlen`, the effective length of the strings to
3088
- compare. The function then compares the two strings by calling
3089
- `traits::compare(data(), str.data(), rlen)`.
3090
-
3091
- *Complexity:* 𝑂(`rlen`).
3092
-
3093
- *Returns:* The nonzero result if the result of the comparison is
3094
- nonzero. Otherwise, returns a value as indicated in
3095
- [[string.view.compare]].
3096
-
3097
- **Table: `compare()` results** <a id="string.view.compare">[string.view.compare]</a>
3098
-
3099
- | Condition | Return Value |
3100
- | ---------------------- | ------------ |
3101
- | `size() < str.size()` | `< 0` |
3102
- | `size() == str.size()` | ` 0` |
3103
- | `size() > str.size()` | `> 0` |
3104
-
3105
- ``` cpp
3106
- constexpr int compare(size_type pos1, size_type n1, basic_string_view str) const;
3107
- ```
3108
-
3109
- *Effects:* Equivalent to: `return substr(pos1, n1).compare(str);`
3110
-
3111
- ``` cpp
3112
- constexpr int compare(size_type pos1, size_type n1, basic_string_view str,
3113
- size_type pos2, size_type n2) const;
3114
- ```
3115
-
3116
- *Effects:* Equivalent to:
3117
- `return substr(pos1, n1).compare(str.substr(pos2, n2));`
3118
-
3119
- ``` cpp
3120
- constexpr int compare(const charT* s) const;
3121
- ```
3122
-
3123
- *Effects:* Equivalent to: `return compare(basic_string_view(s));`
3124
-
3125
- ``` cpp
3126
- constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
3127
- ```
3128
-
3129
- *Effects:* Equivalent to:
3130
- `return substr(pos1, n1).compare(basic_string_view(s));`
3131
-
3132
- ``` cpp
3133
- constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;
3134
- ```
3135
-
3136
- *Effects:* Equivalent to:
3137
- `return substr(pos1, n1).compare(basic_string_view(s, n2));`
3138
-
3139
- ``` cpp
3140
- constexpr bool starts_with(basic_string_view x) const noexcept;
3141
- ```
3142
-
3143
- *Effects:* Equivalent to: `return substr(0, x.size()) == x;`
3144
-
3145
- ``` cpp
3146
- constexpr bool starts_with(charT x) const noexcept;
3147
- ```
3148
-
3149
- *Effects:* Equivalent to: `return !empty() && traits::eq(front(), x);`
3150
-
3151
- ``` cpp
3152
- constexpr bool starts_with(const charT* x) const;
3153
- ```
3154
-
3155
- *Effects:* Equivalent to: `return starts_with(basic_string_view(x));`
3156
-
3157
- ``` cpp
3158
- constexpr bool ends_with(basic_string_view x) const noexcept;
3159
- ```
3160
-
3161
- *Effects:* Equivalent to:
3162
-
3163
- ``` cpp
3164
- return size() >= x.size() && compare(size() - x.size(), npos, x) == 0;
3165
- ```
3166
-
3167
- ``` cpp
3168
- constexpr bool ends_with(charT x) const noexcept;
3169
- ```
3170
-
3171
- *Effects:* Equivalent to: `return !empty() && traits::eq(back(), x);`
3172
-
3173
- ``` cpp
3174
- constexpr bool ends_with(const charT* x) const;
3175
- ```
3176
-
3177
- *Effects:* Equivalent to: `return ends_with(basic_string_view(x));`
3178
-
3179
- #### Searching <a id="string.view.find">[[string.view.find]]</a>
3180
-
3181
- Member functions in this subclause have complexity
3182
- 𝑂(`size() * str.size()`) at worst, although implementations should do
3183
- better.
3184
-
3185
- Let *F* be one of `find`, `rfind`, `find_first_of`, `find_last_of`,
3186
- `find_first_not_of`, and `find_last_not_of`.
3187
-
3188
- - Each member function of the form
3189
- ``` cpp
3190
- constexpr return-type F(const charT* s, size_type pos) const;
3191
- ```
3192
-
3193
- has effects equivalent to: `return F(basic_string_view(s), pos);`
3194
- - Each member function of the form
3195
- ``` cpp
3196
- constexpr return-type F(const charT* s, size_type pos, size_type n) const;
3197
- ```
3198
-
3199
- has effects equivalent to: `return F(basic_string_view(s, n), pos);`
3200
- - Each member function of the form
3201
- ``` cpp
3202
- constexpr return-type F(charT c, size_type pos) const noexcept;
3203
- ```
3204
-
3205
- has effects equivalent to:
3206
- `return F(basic_string_view(addressof(c), 1), pos);`
3207
-
3208
- ``` cpp
3209
- constexpr size_type find(basic_string_view str, size_type pos = 0) const noexcept;
3210
- ```
3211
-
3212
- Let `xpos` be the lowest position, if possible, such that the following
3213
- conditions hold:
3214
-
3215
- - `pos <= xpos`
3216
- - `xpos + str.size() <= size()`
3217
- - `traits::eq(at(xpos + I), str.at(I))` for all elements `I` of the
3218
- string referenced by `str`.
3219
-
3220
- *Effects:* Determines `xpos`.
3221
-
3222
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
3223
- Otherwise, returns `npos`.
3224
-
3225
- ``` cpp
3226
- constexpr size_type rfind(basic_string_view str, size_type pos = npos) const noexcept;
3227
- ```
3228
-
3229
- Let `xpos` be the highest position, if possible, such that the following
3230
- conditions hold:
3231
-
3232
- - `xpos <= pos`
3233
- - `xpos + str.size() <= size()`
3234
- - `traits::eq(at(xpos + I), str.at(I))` for all elements `I` of the
3235
- string referenced by `str`.
3236
-
3237
- *Effects:* Determines `xpos`.
3238
-
3239
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
3240
- Otherwise, returns `npos`.
3241
-
3242
- ``` cpp
3243
- constexpr size_type find_first_of(basic_string_view str, size_type pos = 0) const noexcept;
3244
- ```
3245
-
3246
- Let `xpos` be the lowest position, if possible, such that the following
3247
- conditions hold:
3248
-
3249
- - `pos <= xpos`
3250
- - `xpos < size()`
3251
- - `traits::eq(at(xpos), str.at(I))` for some element `I` of the string
3252
- referenced by `str`.
3253
-
3254
- *Effects:* Determines `xpos`.
3255
-
3256
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
3257
- Otherwise, returns `npos`.
3258
-
3259
- ``` cpp
3260
- constexpr size_type find_last_of(basic_string_view str, size_type pos = npos) const noexcept;
3261
- ```
3262
-
3263
- Let `xpos` be the highest position, if possible, such that the following
3264
- conditions hold:
3265
-
3266
- - `xpos <= pos`
3267
- - `xpos < size()`
3268
- - `traits::eq(at(xpos), str.at(I))` for some element `I` of the string
3269
- referenced by `str`.
3270
-
3271
- *Effects:* Determines `xpos`.
3272
-
3273
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
3274
- Otherwise, returns `npos`.
3275
-
3276
- ``` cpp
3277
- constexpr size_type find_first_not_of(basic_string_view str, size_type pos = 0) const noexcept;
3278
- ```
3279
-
3280
- Let `xpos` be the lowest position, if possible, such that the following
3281
- conditions hold:
3282
-
3283
- - `pos <= xpos`
3284
- - `xpos < size()`
3285
- - `traits::eq(at(xpos), str.at(I))` for no element `I` of the string
3286
- referenced by `str`.
3287
-
3288
- *Effects:* Determines `xpos`.
3289
-
3290
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
3291
- Otherwise, returns `npos`.
3292
-
3293
- ``` cpp
3294
- constexpr size_type find_last_not_of(basic_string_view str, size_type pos = npos) const noexcept;
3295
- ```
3296
-
3297
- Let `xpos` be the highest position, if possible, such that the following
3298
- conditions hold:
3299
-
3300
- - `xpos <= pos`
3301
- - `xpos < size()`
3302
- - `traits::eq(at(xpos), str.at(I))` for no element `I` of the string
3303
- referenced by `str`.
3304
-
3305
- *Effects:* Determines `xpos`.
3306
-
3307
- *Returns:* `xpos` if the function can determine such a value for `xpos`.
3308
- Otherwise, returns `npos`.
3309
-
3310
- ### Deduction guide <a id="string.view.deduct">[[string.view.deduct]]</a>
3311
-
3312
- ``` cpp
3313
- template<class It, class End>
3314
- basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
3315
- ```
3316
-
3317
- *Constraints:*
3318
-
3319
- - `It` satisfies `contiguous_iterator`.
3320
- - `End` satisfies `sized_sentinel_for<It>`.
3321
-
3322
- ### Non-member comparison functions <a id="string.view.comparison">[[string.view.comparison]]</a>
3323
-
3324
- Let `S` be `basic_string_view<charT, traits>`, and `sv` be an instance
3325
- of `S`. Implementations shall provide sufficient additional overloads
3326
- marked `constexpr` and `noexcept` so that an object `t` with an implicit
3327
- conversion to `S` can be compared according to
3328
- [[string.view.comparison.overloads]].
3329
-
3330
- **Table: Additional `basic_string_view` comparison overloads** <a id="string.view.comparison.overloads">[string.view.comparison.overloads]</a>
3331
-
3332
- | Expression | Equivalent to |
3333
- | ---------- | ------------- |
3334
- | `t == sv` | `S(t) == sv` |
3335
- | `sv == t` | `sv == S(t)` |
3336
- | `t != sv` | `S(t) != sv` |
3337
- | `sv != t` | `sv != S(t)` |
3338
- | `t < sv` | `S(t) < sv` |
3339
- | `sv < t` | `sv < S(t)` |
3340
- | `t > sv` | `S(t) > sv` |
3341
- | `sv > t` | `sv > S(t)` |
3342
- | `t <= sv` | `S(t) <= sv` |
3343
- | `sv <= t` | `sv <= S(t)` |
3344
- | `t >= sv` | `S(t) >= sv` |
3345
- | `sv >= t` | `sv >= S(t)` |
3346
- | `t <=> sv` | `S(t) <=> sv` |
3347
- | `sv <=> t` | `sv <=> S(t)` |
3348
-
3349
-
3350
- [*Example 1*:
3351
-
3352
- A sample conforming implementation for `operator==` would be:
3353
-
3354
- ``` cpp
3355
- template<class charT, class traits>
3356
- constexpr bool operator==(basic_string_view<charT, traits> lhs,
3357
- basic_string_view<charT, traits> rhs) noexcept {
3358
- return lhs.compare(rhs) == 0;
3359
- }
3360
- template<class charT, class traits>
3361
- constexpr bool operator==(basic_string_view<charT, traits> lhs,
3362
- type_identity_t<basic_string_view<charT, traits>> rhs) noexcept {
3363
- return lhs.compare(rhs) == 0;
3364
- }
3365
- ```
3366
-
3367
- — *end example*]
3368
-
3369
- ``` cpp
3370
- template<class charT, class traits>
3371
- constexpr bool operator==(basic_string_view<charT, traits> lhs,
3372
- basic_string_view<charT, traits> rhs) noexcept;
3373
- ```
3374
-
3375
- *Returns:* `lhs.compare(rhs) == 0`.
3376
-
3377
- ``` cpp
3378
- template<class charT, class traits>
3379
- constexpr see below operator<=>(basic_string_view<charT, traits> lhs,
3380
- \itcorr basic_string_view<charT, traits> rhs) noexcept;
3381
- ```
3382
-
3383
- Let `R` denote the type `traits::comparison_category` if it exists,
3384
- otherwise `R` is `weak_ordering`.
3385
-
3386
- *Returns:* `static_cast<R>(lhs.compare(rhs) <=> 0)`.
3387
-
3388
- ### Inserters and extractors <a id="string.view.io">[[string.view.io]]</a>
3389
-
3390
- ``` cpp
3391
- template<class charT, class traits>
3392
- basic_ostream<charT, traits>&
3393
- operator<<(basic_ostream<charT, traits>& os, basic_string_view<charT, traits> str);
3394
- ```
3395
-
3396
- *Effects:* Behaves as a formatted output
3397
- function [[ostream.formatted.reqmts]] of `os`. Forms a character
3398
- sequence `seq`, initially consisting of the elements defined by the
3399
- range \[`str.begin()`, `str.end()`). Determines padding for `seq` as
3400
- described in  [[ostream.formatted.reqmts]]. Then inserts `seq` as if by
3401
- calling `os.rdbuf()->sputn(seq, n)`, where `n` is the larger of
3402
- `os.width()` and `str.size()`; then calls `os.width(0)`.
3403
-
3404
- *Returns:* `os`
3405
-
3406
- ### Hash support <a id="string.view.hash">[[string.view.hash]]</a>
3407
-
3408
- ``` cpp
3409
- template<> struct hash<string_view>;
3410
- template<> struct hash<u8string_view>;
3411
- template<> struct hash<u16string_view>;
3412
- template<> struct hash<u32string_view>;
3413
- template<> struct hash<wstring_view>;
3414
- ```
3415
-
3416
- The specialization is enabled [[unord.hash]].
3417
-
3418
- [*Note 1*: The hash value of a string view object is equal to the hash
3419
- value of the corresponding string
3420
- object [[basic.string.hash]]. — *end note*]
3421
-
3422
- ### Suffix for `basic_string_view` literals <a id="string.view.literals">[[string.view.literals]]</a>
3423
-
3424
- ``` cpp
3425
- constexpr string_view operator""sv(const char* str, size_t len) noexcept;
3426
- ```
3427
-
3428
- *Returns:* `string_view{str, len}`.
3429
-
3430
- ``` cpp
3431
- constexpr u8string_view operator""sv(const char8_t* str, size_t len) noexcept;
3432
- ```
3433
-
3434
- *Returns:* `u8string_view{str, len}`.
3435
-
3436
- ``` cpp
3437
- constexpr u16string_view operator""sv(const char16_t* str, size_t len) noexcept;
3438
- ```
3439
-
3440
- *Returns:* `u16string_view{str, len}`.
3441
-
3442
- ``` cpp
3443
- constexpr u32string_view operator""sv(const char32_t* str, size_t len) noexcept;
3444
- ```
3445
-
3446
- *Returns:* `u32string_view{str, len}`.
3447
-
3448
- ``` cpp
3449
- constexpr wstring_view operator""sv(const wchar_t* str, size_t len) noexcept;
3450
- ```
3451
-
3452
- *Returns:* `wstring_view{str, len}`.
3453
-
3454
  ## Null-terminated sequence utilities <a id="c.strings">[[c.strings]]</a>
3455
 
3456
  ### Header `<cctype>` synopsis <a id="cctype.syn">[[cctype.syn]]</a>
3457
 
3458
  ``` cpp
@@ -3633,11 +3848,11 @@ namespace std {
3633
  wchar_t* wcstok(wchar_t* s1, const wchar_t* s2, wchar_t** ptr);
3634
  const wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n); // see [library.c]
3635
  wchar_t* wmemchr(wchar_t* s, wchar_t c, size_t n); // see [library.c]
3636
  size_t wcslen(const wchar_t* s);
3637
  wchar_t* wmemset(wchar_t* s, wchar_t c, size_t n);
3638
- size_t wcsftime(wchar_t* s, size_t maxsize, const wchar_t* format, const struct tm* timeptr);
3639
  wint_t btowc(int c);
3640
  int wctob(wint_t c);
3641
 
3642
  // [c.mb.wcs], multibyte / wide string and character conversion functions
3643
  int mbsinit(const mbstate_t* ps);
@@ -3748,22 +3963,24 @@ next multibyte character is complete and valid, it determines the values
3748
  of the corresponding UTF-8 code units and then, if `pc8` is not a null
3749
  pointer, stores the value of the first (or only) such code unit in the
3750
  object pointed to by `pc8`. Subsequent calls will store successive UTF-8
3751
  code units without consuming any additional input until all the code
3752
  units have been stored. If the corresponding Unicode character is
3753
- U+0000, the resulting state described is the initial conversion state.
 
3754
 
3755
  *Returns:* The first of the following that applies (given the current
3756
  conversion state):
3757
 
3758
  - `0`, if the next `n` or fewer bytes complete the multibyte character
3759
- that corresponds to the U+0000 Unicode character (which is the value
3760
- stored).
3761
  - between `1` and `n` (inclusive), if the next n or fewer bytes complete
3762
- a valid multibyte character (which is the value stored); the value
3763
- returned is the number of bytes that complete the multibyte character.
3764
- - `(size_t)(-3)`, if the next character resulting from a previous call
 
3765
  has been stored (no bytes from the input have been consumed by this
3766
  call).
3767
  - `(size_t)(-2)`, if the next `n` bytes contribute to an incomplete (but
3768
  potentially valid) multibyte character, and all `n` bytes have been
3769
  processed (no value is stored).
@@ -3796,62 +4013,69 @@ conversion state is unspecified.
3796
  *Remarks:* Calls to `c8rtomb` with a null pointer argument for `s` may
3797
  introduce a data race [[res.on.data.races]] with other calls to
3798
  `c8rtomb` with a null pointer argument for `s`.
3799
 
3800
  <!-- Link reference definitions -->
 
3801
  [basic.string]: #basic.string
 
3802
  [basic.string.hash]: #basic.string.hash
3803
  [basic.string.literals]: #basic.string.literals
3804
- [basic.types]: basic.md#basic.types
3805
  [c.mb.wcs]: #c.mb.wcs
3806
  [c.strings]: #c.strings
3807
  [cctype.syn]: #cctype.syn
3808
  [char.traits]: #char.traits
 
3809
  [char.traits.req]: #char.traits.req
3810
  [char.traits.require]: #char.traits.require
3811
  [char.traits.specializations]: #char.traits.specializations
3812
  [char.traits.specializations.char]: #char.traits.specializations.char
3813
  [char.traits.specializations.char16.t]: #char.traits.specializations.char16.t
3814
  [char.traits.specializations.char32.t]: #char.traits.specializations.char32.t
3815
  [char.traits.specializations.char8.t]: #char.traits.specializations.char8.t
 
3816
  [char.traits.specializations.wchar.t]: #char.traits.specializations.wchar.t
3817
  [char.traits.typedefs]: #char.traits.typedefs
 
 
3818
  [container.requirements]: containers.md#container.requirements
3819
  [container.requirements.general]: containers.md#container.requirements.general
3820
- [container.seq.req]: containers.md#container.seq.req
3821
  [cpp17.copyassignable]: #cpp17.copyassignable
3822
  [cpp17.copyconstructible]: #cpp17.copyconstructible
3823
  [cpp17.defaultconstructible]: #cpp17.defaultconstructible
3824
  [cpp17.destructible]: #cpp17.destructible
3825
  [cstring.syn]: #cstring.syn
3826
  [cuchar.syn]: #cuchar.syn
3827
  [cwchar.syn]: #cwchar.syn
3828
  [cwctype.syn]: #cwctype.syn
3829
- [defns.character.container]: library.md#defns.character.container
3830
  [input.output]: input.md#input.output
3831
  [intro.object]: basic.md#intro.object
3832
- [iostate.flags]: input.md#iostate.flags
3833
  [iostream.forward]: input.md#iostream.forward
3834
  [iostreams.limits.pos]: input.md#iostreams.limits.pos
3835
  [istream.formatted.reqmts]: input.md#istream.formatted.reqmts
3836
  [istream.unformatted]: input.md#istream.unformatted
3837
  [iterator.concept.contiguous]: iterators.md#iterator.concept.contiguous
 
3838
  [iterator.range]: iterators.md#iterator.range
3839
  [iterator.requirements.general]: iterators.md#iterator.requirements.general
3840
  [library.c]: library.md#library.c
3841
  [ostream.formatted.reqmts]: input.md#ostream.formatted.reqmts
3842
  [random.access.iterators]: iterators.md#random.access.iterators
3843
  [res.on.data.races]: library.md#res.on.data.races
 
3844
  [string.access]: #string.access
3845
  [string.accessors]: #string.accessors
3846
  [string.append]: #string.append
3847
  [string.assign]: #string.assign
3848
  [string.capacity]: #string.capacity
3849
  [string.classes]: #string.classes
 
3850
  [string.cmp]: #string.cmp
3851
  [string.compare]: #string.compare
3852
  [string.cons]: #string.cons
 
3853
  [string.conversions]: #string.conversions
3854
  [string.copy]: #string.copy
3855
  [string.ends.with]: #string.ends.with
3856
  [string.erase]: #string.erase
3857
  [string.erasure]: #string.erasure
@@ -3878,26 +4102,34 @@ introduce a data race [[res.on.data.races]] with other calls to
3878
  [string.view.comparison]: #string.view.comparison
3879
  [string.view.comparison.overloads]: #string.view.comparison.overloads
3880
  [string.view.cons]: #string.view.cons
3881
  [string.view.deduct]: #string.view.deduct
3882
  [string.view.find]: #string.view.find
 
3883
  [string.view.hash]: #string.view.hash
3884
  [string.view.io]: #string.view.io
3885
  [string.view.iterators]: #string.view.iterators
3886
  [string.view.literals]: #string.view.literals
3887
  [string.view.modifiers]: #string.view.modifiers
3888
  [string.view.ops]: #string.view.ops
3889
  [string.view.synop]: #string.view.synop
3890
  [string.view.template]: #string.view.template
 
3891
  [strings]: #strings
3892
  [strings.general]: #strings.general
3893
  [strings.summary]: #strings.summary
3894
  [support.signal]: support.md#support.signal
 
 
 
3895
  [unord.hash]: utilities.md#unord.hash
3896
  [utility.swap]: utilities.md#utility.swap
3897
 
3898
  [^1]: If `eof()` can be held in `char_type` then some iostreams
3899
  operations can give surprising results.
3900
 
3901
- [^2]: For example, as an argument to non-member functions `swap()`
 
 
 
3902
  [[string.special]], `operator>{}>()` [[string.io]], and `getline()`
3903
  [[string.io]], or as an argument to `basic_string::swap()`.
 
1
  # Strings library <a id="strings">[[strings]]</a>
2
 
3
  ## General <a id="strings.general">[[strings.general]]</a>
4
 
5
  This Clause describes components for manipulating sequences of any
6
+ non-array trivial standard-layout [[term.standard.layout.type]] type.
7
+ Such types are called *char-like types*, and objects of char-like types
8
+ are called *char-like objects* or simply *characters*.
9
 
10
  The following subclauses describe a character traits class, string
11
  classes, and null-terminated sequence utilities, as summarized in
12
  [[strings.summary]].
13
 
14
  ## Character traits <a id="char.traits">[[char.traits]]</a>
15
 
16
+ ### General <a id="char.traits.general">[[char.traits.general]]</a>
17
+
18
+ Subclause [[char.traits]] defines requirements on classes representing
19
+ *character traits*, and defines a class template `char_traits<charT>`,
20
+ along with five specializations, `char_traits<char>`,
21
+ `char_traits<char8_t>`, `char_traits<char16_t>`,
22
+ `char_traits<char32_t>`, and `char_traits<wchar_t>`, that meet those
23
+ requirements.
24
 
25
  Most classes specified in [[string.classes]], [[string.view]], and
26
  [[input.output]] need a set of related types and functions to complete
27
  the definition of their semantics. These types and functions are
28
  provided as a set of member *typedef-name*s and functions in the
29
+ template parameter `traits` used by each such template. Subclause
30
+ [[char.traits]] defines the semantics of these members.
31
 
32
  To specialize those templates to generate a string, string view, or
33
  iostream class to handle a particular character container type
34
  [[defns.character.container]] `C`, that and its related character traits
35
  class `X` are passed as a pair of parameters to the string, string view,
 
41
  In [[char.traits.req]], `X` denotes a traits class defining types and
42
  functions for the character container type `C`; `c` and `d` denote
43
  values of type `C`; `p` and `q` denote values of type `const C*`; `s`
44
  denotes a value of type `C*`; `n`, `i` and `j` denote values of type
45
  `size_t`; `e` and `f` denote values of type `X::int_type`; `pos` denotes
46
+ a value of type `X::pos_type`; and `r` denotes an lvalue of type `C`. No
47
+ expression which is part of the character traits requirements specified
48
+ in this subclause [[char.traits.require]] shall exit via an exception.
49
 
50
  The class template
51
 
52
  ``` cpp
53
  template<class charT> struct char_traits;
 
76
  ([[cpp17.copyconstructible]]), and *Cpp17DefaultConstructible*
77
  ([[cpp17.defaultconstructible]]) requirements.
78
 
79
  ### `char_traits` specializations <a id="char.traits.specializations">[[char.traits.specializations]]</a>
80
 
81
+ #### General <a id="char.traits.specializations.general">[[char.traits.specializations.general]]</a>
82
+
83
  ``` cpp
84
  namespace std {
85
  template<> struct char_traits<char>;
86
  template<> struct char_traits<char8_t>;
87
  template<> struct char_traits<char16_t>;
 
172
  ```
173
 
174
  The two-argument members `assign`, `eq`, and `lt` are defined
175
  identically to the built-in operators `=`, `==`, and `<` respectively.
176
 
177
+ The member `eof()` returns an *implementation-defined* constant that
178
  cannot appear as a valid UTF-8 code unit.
179
 
180
  #### `struct char_traits<char16_t>` <a id="char.traits.specializations.char16.t">[[char.traits.specializations.char16.t]]</a>
181
 
182
  ``` cpp
 
291
  The two-argument members `assign`, `eq`, and `lt` are defined
292
  identically to the built-in operators `=`, `==`, and `<`, respectively.
293
 
294
  The member `eof()` returns `WEOF`.
295
 
296
+ ## String view classes <a id="string.view">[[string.view]]</a>
297
+
298
+ ### General <a id="string.view.general">[[string.view.general]]</a>
299
+
300
+ The class template `basic_string_view` describes an object that can
301
+ refer to a constant contiguous sequence of char-like [[strings.general]]
302
+ objects with the first element of the sequence at position zero. In the
303
+ rest of [[string.view]], the type of the char-like objects held in a
304
+ `basic_string_view` object is designated by `charT`.
305
+
306
+ [*Note 1*: The library provides implicit conversions from
307
+ `const charT*` and `std::basic_string<charT, ...>` to
308
+ `std::basic_string_view<charT, ...>` so that user code can accept just
309
+ `std::basic_string_view<charT>` as a non-templated parameter wherever a
310
+ sequence of characters is expected. User-defined types can define their
311
+ own implicit conversions to `std::basic_string_view<charT>` in order to
312
+ interoperate with these functions. — *end note*]
313
+
314
+ ### Header `<string_view>` synopsis <a id="string.view.synop">[[string.view.synop]]</a>
315
+
316
+ ``` cpp
317
+ #include <compare> // see [compare.syn]
318
+
319
+ namespace std {
320
+ // [string.view.template], class template basic_string_view
321
+ template<class charT, class traits = char_traits<charT>>
322
+ class basic_string_view;
323
+
324
+ template<class charT, class traits>
325
+ constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true;
326
+ template<class charT, class traits>
327
+ constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true;
328
+
329
+ // [string.view.comparison], non-member comparison functions
330
+ template<class charT, class traits>
331
+ constexpr bool operator==(basic_string_view<charT, traits> x,
332
+ basic_string_view<charT, traits> y) noexcept;
333
+ template<class charT, class traits>
334
+ constexpr see below operator<=>(basic_string_view<charT, traits> x,
335
+ \itcorr basic_string_view<charT, traits> y) noexcept;
336
+
337
+ // see [string.view.comparison], sufficient additional overloads of comparison functions
338
+
339
+ // [string.view.io], inserters and extractors
340
+ template<class charT, class traits>
341
+ basic_ostream<charT, traits>&
342
+ operator<<(basic_ostream<charT, traits>& os,
343
+ basic_string_view<charT, traits> str);
344
+
345
+ // basic_string_view typedef-names
346
+ using string_view = basic_string_view<char>;
347
+ using u8string_view = basic_string_view<char8_t>;
348
+ using u16string_view = basic_string_view<char16_t>;
349
+ using u32string_view = basic_string_view<char32_t>;
350
+ using wstring_view = basic_string_view<wchar_t>;
351
+
352
+ // [string.view.hash], hash support
353
+ template<class T> struct hash;
354
+ template<> struct hash<string_view>;
355
+ template<> struct hash<u8string_view>;
356
+ template<> struct hash<u16string_view>;
357
+ template<> struct hash<u32string_view>;
358
+ template<> struct hash<wstring_view>;
359
+
360
+ inline namespace literals {
361
+ inline namespace string_view_literals {
362
+ // [string.view.literals], suffix for basic_string_view literals
363
+ constexpr string_view operator""sv(const char* str, size_t len) noexcept;
364
+ constexpr u8string_view operator""sv(const char8_t* str, size_t len) noexcept;
365
+ constexpr u16string_view operator""sv(const char16_t* str, size_t len) noexcept;
366
+ constexpr u32string_view operator""sv(const char32_t* str, size_t len) noexcept;
367
+ constexpr wstring_view operator""sv(const wchar_t* str, size_t len) noexcept;
368
+ }
369
+ }
370
+ }
371
+ ```
372
+
373
+ The function templates defined in [[utility.swap]] and
374
+ [[iterator.range]] are available when `<string_view>` is included.
375
+
376
+ ### Class template `basic_string_view` <a id="string.view.template">[[string.view.template]]</a>
377
+
378
+ #### General <a id="string.view.template.general">[[string.view.template.general]]</a>
379
+
380
+ ``` cpp
381
+ namespace std {
382
+ template<class charT, class traits = char_traits<charT>>
383
+ class basic_string_view {
384
+ public:
385
+ // types
386
+ using traits_type = traits;
387
+ using value_type = charT;
388
+ using pointer = value_type*;
389
+ using const_pointer = const value_type*;
390
+ using reference = value_type&;
391
+ using const_reference = const value_type&;
392
+ using const_iterator = implementation-defined // type of basic_string_view::const_iterator; // see [string.view.iterators]
393
+ using iterator = const_iterator;
394
+ using const_reverse_iterator = reverse_iterator<const_iterator>;
395
+ using reverse_iterator = const_reverse_iterator;
396
+ using size_type = size_t;
397
+ using difference_type = ptrdiff_t;
398
+ static constexpr size_type npos = size_type(-1);
399
+
400
+ // [string.view.cons], construction and assignment
401
+ constexpr basic_string_view() noexcept;
402
+ constexpr basic_string_view(const basic_string_view&) noexcept = default;
403
+ constexpr basic_string_view& operator=(const basic_string_view&) noexcept = default;
404
+ constexpr basic_string_view(const charT* str);
405
+ basic_string_view(nullptr_t) = delete;
406
+ constexpr basic_string_view(const charT* str, size_type len);
407
+ template<class It, class End>
408
+ constexpr basic_string_view(It begin, End end);
409
+ template<class R>
410
+ constexpr explicit basic_string_view(R&& r);
411
+
412
+ // [string.view.iterators], iterator support
413
+ constexpr const_iterator begin() const noexcept;
414
+ constexpr const_iterator end() const noexcept;
415
+ constexpr const_iterator cbegin() const noexcept;
416
+ constexpr const_iterator cend() const noexcept;
417
+ constexpr const_reverse_iterator rbegin() const noexcept;
418
+ constexpr const_reverse_iterator rend() const noexcept;
419
+ constexpr const_reverse_iterator crbegin() const noexcept;
420
+ constexpr const_reverse_iterator crend() const noexcept;
421
+
422
+ // [string.view.capacity], capacity
423
+ constexpr size_type size() const noexcept;
424
+ constexpr size_type length() const noexcept;
425
+ constexpr size_type max_size() const noexcept;
426
+ [[nodiscard]] constexpr bool empty() const noexcept;
427
+
428
+ // [string.view.access], element access
429
+ constexpr const_reference operator[](size_type pos) const;
430
+ constexpr const_reference at(size_type pos) const;
431
+ constexpr const_reference front() const;
432
+ constexpr const_reference back() const;
433
+ constexpr const_pointer data() const noexcept;
434
+
435
+ // [string.view.modifiers], modifiers
436
+ constexpr void remove_prefix(size_type n);
437
+ constexpr void remove_suffix(size_type n);
438
+ constexpr void swap(basic_string_view& s) noexcept;
439
+
440
+ // [string.view.ops], string operations
441
+ constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
442
+
443
+ constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
444
+
445
+ constexpr int compare(basic_string_view s) const noexcept;
446
+ constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
447
+ constexpr int compare(size_type pos1, size_type n1, basic_string_view s,
448
+ size_type pos2, size_type n2) const;
449
+ constexpr int compare(const charT* s) const;
450
+ constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
451
+ constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;
452
+
453
+ constexpr bool starts_with(basic_string_view x) const noexcept;
454
+ constexpr bool starts_with(charT x) const noexcept;
455
+ constexpr bool starts_with(const charT* x) const;
456
+ constexpr bool ends_with(basic_string_view x) const noexcept;
457
+ constexpr bool ends_with(charT x) const noexcept;
458
+ constexpr bool ends_with(const charT* x) const;
459
+
460
+ constexpr bool contains(basic_string_view x) const noexcept;
461
+ constexpr bool contains(charT x) const noexcept;
462
+ constexpr bool contains(const charT* x) const;
463
+
464
+ // [string.view.find], searching
465
+ constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
466
+ constexpr size_type find(charT c, size_type pos = 0) const noexcept;
467
+ constexpr size_type find(const charT* s, size_type pos, size_type n) const;
468
+ constexpr size_type find(const charT* s, size_type pos = 0) const;
469
+ constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
470
+ constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
471
+ constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
472
+ constexpr size_type rfind(const charT* s, size_type pos = npos) const;
473
+
474
+ constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
475
+ constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
476
+ constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
477
+ constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
478
+ constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
479
+ constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
480
+ constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const;
481
+ constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;
482
+ constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
483
+ constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
484
+ constexpr size_type find_first_not_of(const charT* s, size_type pos,
485
+ size_type n) const;
486
+ constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const;
487
+ constexpr size_type find_last_not_of(basic_string_view s,
488
+ size_type pos = npos) const noexcept;
489
+ constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
490
+ constexpr size_type find_last_not_of(const charT* s, size_type pos,
491
+ size_type n) const;
492
+ constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
493
+
494
+ private:
495
+ const_pointer data_; // exposition only
496
+ size_type size_; // exposition only
497
+ };
498
+
499
+ // [string.view.deduct], deduction guides
500
+ template<class It, class End>
501
+ basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
502
+ template<class R>
503
+ basic_string_view(R&&) -> basic_string_view<ranges::range_value_t<R>>;
504
+ }
505
+ ```
506
+
507
+ [^2]
508
+
509
+ In every specialization `basic_string_view<charT, traits>`, the type
510
+ `traits` shall meet the character traits requirements [[char.traits]].
511
+
512
+ [*Note 1*: The program is ill-formed if `traits::char_type` is not the
513
+ same type as `charT`. — *end note*]
514
+
515
+ For a `basic_string_view str`, any operation that invalidates a pointer
516
+ in the range
517
+
518
+ ``` cpp
519
+ {[}str.data(), {str.data() + str.size()}{)}
520
+ ```
521
+
522
+ invalidates pointers, iterators, and references returned from `str`’s
523
+ member functions.
524
+
525
+ The complexity of `basic_string_view` member functions is 𝑂(1) unless
526
+ otherwise specified.
527
+
528
+ `basic_string_view<charT, traits>` is a trivially copyable type
529
+ [[term.trivially.copyable.type]].
530
+
531
+ #### Construction and assignment <a id="string.view.cons">[[string.view.cons]]</a>
532
+
533
+ ``` cpp
534
+ constexpr basic_string_view() noexcept;
535
+ ```
536
+
537
+ *Ensures:* `size_ == 0` and `data_ == nullptr`.
538
+
539
+ ``` cpp
540
+ constexpr basic_string_view(const charT* str);
541
+ ```
542
+
543
+ *Preconditions:* \[`str`, `str + traits::length(str)`) is a valid range.
544
+
545
+ *Effects:* Constructs a `basic_string_view`, initializing `data_` with
546
+ `str` and initializing `size_` with `traits::length(str)`.
547
+
548
+ *Complexity:* 𝑂(`traits::length(str)`).
549
+
550
+ ``` cpp
551
+ constexpr basic_string_view(const charT* str, size_type len);
552
+ ```
553
+
554
+ *Preconditions:* \[`str`, `str + len`) is a valid range.
555
+
556
+ *Effects:* Constructs a `basic_string_view`, initializing `data_` with
557
+ `str` and initializing `size_` with `len`.
558
+
559
+ ``` cpp
560
+ template<class It, class End>
561
+ constexpr basic_string_view(It begin, End end);
562
+ ```
563
+
564
+ *Constraints:*
565
+
566
+ - `It` satisfies `contiguous_iterator`.
567
+ - `End` satisfies `sized_sentinel_for<It>`.
568
+ - `is_same_v<iter_value_t<It>, charT>` is `true`.
569
+ - `is_convertible_v<End, size_type>` is `false`.
570
+
571
+ *Preconditions:*
572
+
573
+ - \[`begin`, `end`) is a valid range.
574
+ - `It` models `contiguous_iterator`.
575
+ - `End` models `sized_sentinel_for<It>`.
576
+
577
+ *Effects:* Initializes `data_` with `to_address(begin)` and initializes
578
+ `size_` with `end - begin`.
579
+
580
+ *Throws:* When and what `end - begin` throws.
581
+
582
+ ``` cpp
583
+ template<class R>
584
+ constexpr explicit basic_string_view(R&& r);
585
+ ```
586
+
587
+ Let `d` be an lvalue of type `remove_cvref_t<R>`.
588
+
589
+ *Constraints:*
590
+
591
+ - `remove_cvref_t<R>` is not the same type as `basic_string_view`,
592
+ - `R` models `ranges::contiguous_range` and `ranges::sized_range`,
593
+ - `is_same_v<ranges::range_value_t<R>, charT>` is `true`,
594
+ - `is_convertible_v<R, const charT*>` is `false`, and
595
+ - `d.operator ::std::basic_string_view<charT, traits>()` is not a valid
596
+ expression.
597
+
598
+ *Effects:* Initializes `data_` with `ranges::data(r)` and `size_` with
599
+ `ranges::size(r)`.
600
+
601
+ *Throws:* Any exception thrown by `ranges::data(r)` and
602
+ `ranges::size(r)`.
603
+
604
+ #### Deduction guides <a id="string.view.deduct">[[string.view.deduct]]</a>
605
+
606
+ ``` cpp
607
+ template<class It, class End>
608
+ basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>;
609
+ ```
610
+
611
+ *Constraints:*
612
+
613
+ - `It` satisfies `contiguous_iterator`.
614
+ - `End` satisfies `sized_sentinel_for<It>`.
615
+
616
+ ``` cpp
617
+ template<class R>
618
+ basic_string_view(R&&) -> basic_string_view<ranges::range_value_t<R>>;
619
+ ```
620
+
621
+ *Constraints:* `R` satisfies `ranges::contiguous_range`.
622
+
623
+ #### Iterator support <a id="string.view.iterators">[[string.view.iterators]]</a>
624
+
625
+ ``` cpp
626
+ using const_iterator = implementation-defined // type of basic_string_view::const_iterator;
627
+ ```
628
+
629
+ A type that meets the requirements of a constant
630
+ *Cpp17RandomAccessIterator*[[random.access.iterators]], models
631
+ `contiguous_iterator` [[iterator.concept.contiguous]], and meets the
632
+ constexpr iterator requirements [[iterator.requirements.general]], whose
633
+ `value_type` is the template parameter `charT`.
634
+
635
+ All requirements on container iterators [[container.requirements]] apply
636
+ to `basic_string_view::const_iterator` as well.
637
+
638
+ ``` cpp
639
+ constexpr const_iterator begin() const noexcept;
640
+ constexpr const_iterator cbegin() const noexcept;
641
+ ```
642
+
643
+ *Returns:* An iterator such that
644
+
645
+ - if `!empty()`, `addressof(*begin()) == data_`,
646
+ - otherwise, an unspecified value such that \[`begin()`, `end()`) is a
647
+ valid range.
648
+
649
+ ``` cpp
650
+ constexpr const_iterator end() const noexcept;
651
+ constexpr const_iterator cend() const noexcept;
652
+ ```
653
+
654
+ *Returns:* `begin() + size()`.
655
+
656
+ ``` cpp
657
+ constexpr const_reverse_iterator rbegin() const noexcept;
658
+ constexpr const_reverse_iterator crbegin() const noexcept;
659
+ ```
660
+
661
+ *Returns:* `const_reverse_iterator(end())`.
662
+
663
+ ``` cpp
664
+ constexpr const_reverse_iterator rend() const noexcept;
665
+ constexpr const_reverse_iterator crend() const noexcept;
666
+ ```
667
+
668
+ *Returns:* `const_reverse_iterator(begin())`.
669
+
670
+ #### Capacity <a id="string.view.capacity">[[string.view.capacity]]</a>
671
+
672
+ ``` cpp
673
+ constexpr size_type size() const noexcept;
674
+ constexpr size_type length() const noexcept;
675
+ ```
676
+
677
+ *Returns:* `size_`.
678
+
679
+ ``` cpp
680
+ constexpr size_type max_size() const noexcept;
681
+ ```
682
+
683
+ *Returns:* The largest possible number of char-like objects that can be
684
+ referred to by a `basic_string_view`.
685
+
686
+ ``` cpp
687
+ [[nodiscard]] constexpr bool empty() const noexcept;
688
+ ```
689
+
690
+ *Returns:* `size_ == 0`.
691
+
692
+ #### Element access <a id="string.view.access">[[string.view.access]]</a>
693
+
694
+ ``` cpp
695
+ constexpr const_reference operator[](size_type pos) const;
696
+ ```
697
+
698
+ *Preconditions:* `pos < size()`.
699
+
700
+ *Returns:* `data_[pos]`.
701
+
702
+ *Throws:* Nothing.
703
+
704
+ [*Note 1*: Unlike `basic_string::operator[]`,
705
+ `basic_string_view::operator[](size())` has undefined behavior instead
706
+ of returning `charT()`. — *end note*]
707
+
708
+ ``` cpp
709
+ constexpr const_reference at(size_type pos) const;
710
+ ```
711
+
712
+ *Returns:* `data_[pos]`.
713
+
714
+ *Throws:* `out_of_range` if `pos >= size()`.
715
+
716
+ ``` cpp
717
+ constexpr const_reference front() const;
718
+ ```
719
+
720
+ *Preconditions:* `!empty()`.
721
+
722
+ *Returns:* `data_[0]`.
723
+
724
+ *Throws:* Nothing.
725
+
726
+ ``` cpp
727
+ constexpr const_reference back() const;
728
+ ```
729
+
730
+ *Preconditions:* `!empty()`.
731
+
732
+ *Returns:* `data_[size() - 1]`.
733
+
734
+ *Throws:* Nothing.
735
+
736
+ ``` cpp
737
+ constexpr const_pointer data() const noexcept;
738
+ ```
739
+
740
+ *Returns:* `data_`.
741
+
742
+ [*Note 2*: Unlike `basic_string::data()` and *string-literal*s,
743
+ `data()` can return a pointer to a buffer that is not null-terminated.
744
+ Therefore it is typically a mistake to pass `data()` to a function that
745
+ takes just a `const charT*` and expects a null-terminated
746
+ string. — *end note*]
747
+
748
+ #### Modifiers <a id="string.view.modifiers">[[string.view.modifiers]]</a>
749
+
750
+ ``` cpp
751
+ constexpr void remove_prefix(size_type n);
752
+ ```
753
+
754
+ *Preconditions:* `n <= size()`.
755
+
756
+ *Effects:* Equivalent to: `data_ += n; size_ -= n;`
757
+
758
+ ``` cpp
759
+ constexpr void remove_suffix(size_type n);
760
+ ```
761
+
762
+ *Preconditions:* `n <= size()`.
763
+
764
+ *Effects:* Equivalent to: `size_ -= n;`
765
+
766
+ ``` cpp
767
+ constexpr void swap(basic_string_view& s) noexcept;
768
+ ```
769
+
770
+ *Effects:* Exchanges the values of `*this` and `s`.
771
+
772
+ #### String operations <a id="string.view.ops">[[string.view.ops]]</a>
773
+
774
+ ``` cpp
775
+ constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
776
+ ```
777
+
778
+ Let `rlen` be the smaller of `n` and `size() - pos`.
779
+
780
+ *Preconditions:* \[`s`, `s + rlen`) is a valid range.
781
+
782
+ *Effects:* Equivalent to `traits::copy(s, data() + pos, rlen)`.
783
+
784
+ *Returns:* `rlen`.
785
+
786
+ *Throws:* `out_of_range` if `pos > size()`.
787
+
788
+ *Complexity:* 𝑂(`rlen`).
789
+
790
+ ``` cpp
791
+ constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
792
+ ```
793
+
794
+ Let `rlen` be the smaller of `n` and `size() - pos`.
795
+
796
+ *Effects:* Determines `rlen`, the effective length of the string to
797
+ reference.
798
+
799
+ *Returns:* `basic_string_view(data() + pos, rlen)`.
800
+
801
+ *Throws:* `out_of_range` if `pos > size()`.
802
+
803
+ ``` cpp
804
+ constexpr int compare(basic_string_view str) const noexcept;
805
+ ```
806
+
807
+ Let `rlen` be the smaller of `size()` and `str.size()`.
808
+
809
+ *Effects:* Determines `rlen`, the effective length of the strings to
810
+ compare. The function then compares the two strings by calling
811
+ `traits::compare(data(), str.data(), rlen)`.
812
+
813
+ *Returns:* The nonzero result if the result of the comparison is
814
+ nonzero. Otherwise, returns a value as indicated in
815
+ [[string.view.compare]].
816
+
817
+ **Table: `compare()` results** <a id="string.view.compare">[string.view.compare]</a>
818
+
819
+ | Condition | Return Value |
820
+ | ---------------------- | ------------ |
821
+ | `size() < str.size()` | `< 0` |
822
+ | `size() == str.size()` | ` 0` |
823
+ | `size() > str.size()` | `> 0` |
824
+
825
+
826
+ *Complexity:* 𝑂(`rlen`).
827
+
828
+ ``` cpp
829
+ constexpr int compare(size_type pos1, size_type n1, basic_string_view str) const;
830
+ ```
831
+
832
+ *Effects:* Equivalent to: `return substr(pos1, n1).compare(str);`
833
+
834
+ ``` cpp
835
+ constexpr int compare(size_type pos1, size_type n1, basic_string_view str,
836
+ size_type pos2, size_type n2) const;
837
+ ```
838
+
839
+ *Effects:* Equivalent to:
840
+ `return substr(pos1, n1).compare(str.substr(pos2, n2));`
841
+
842
+ ``` cpp
843
+ constexpr int compare(const charT* s) const;
844
+ ```
845
+
846
+ *Effects:* Equivalent to: `return compare(basic_string_view(s));`
847
+
848
+ ``` cpp
849
+ constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
850
+ ```
851
+
852
+ *Effects:* Equivalent to:
853
+ `return substr(pos1, n1).compare(basic_string_view(s));`
854
+
855
+ ``` cpp
856
+ constexpr int compare(size_type pos1, size_type n1, const charT* s, size_type n2) const;
857
+ ```
858
+
859
+ *Effects:* Equivalent to:
860
+ `return substr(pos1, n1).compare(basic_string_view(s, n2));`
861
+
862
+ ``` cpp
863
+ constexpr bool starts_with(basic_string_view x) const noexcept;
864
+ ```
865
+
866
+ *Effects:* Equivalent to: `return substr(0, x.size()) == x;`
867
+
868
+ ``` cpp
869
+ constexpr bool starts_with(charT x) const noexcept;
870
+ ```
871
+
872
+ *Effects:* Equivalent to: `return !empty() && traits::eq(front(), x);`
873
+
874
+ ``` cpp
875
+ constexpr bool starts_with(const charT* x) const;
876
+ ```
877
+
878
+ *Effects:* Equivalent to: `return starts_with(basic_string_view(x));`
879
+
880
+ ``` cpp
881
+ constexpr bool ends_with(basic_string_view x) const noexcept;
882
+ ```
883
+
884
+ *Effects:* Equivalent to:
885
+
886
+ ``` cpp
887
+ return size() >= x.size() && compare(size() - x.size(), npos, x) == 0;
888
+ ```
889
+
890
+ ``` cpp
891
+ constexpr bool ends_with(charT x) const noexcept;
892
+ ```
893
+
894
+ *Effects:* Equivalent to: `return !empty() && traits::eq(back(), x);`
895
+
896
+ ``` cpp
897
+ constexpr bool ends_with(const charT* x) const;
898
+ ```
899
+
900
+ *Effects:* Equivalent to: `return ends_with(basic_string_view(x));`
901
+
902
+ ``` cpp
903
+ constexpr bool contains(basic_string_view x) const noexcept;
904
+ constexpr bool contains(charT x) const noexcept;
905
+ constexpr bool contains(const charT* x) const;
906
+ ```
907
+
908
+ *Effects:* Equivalent to: `return find(x) != npos;`
909
+
910
+ #### Searching <a id="string.view.find">[[string.view.find]]</a>
911
+
912
+ Member functions in this subclause have complexity
913
+ 𝑂(`size() * str.size()`) at worst, although implementations should do
914
+ better.
915
+
916
+ Let *F* be one of `find`, `rfind`, `find_first_of`, `find_last_of`,
917
+ `find_first_not_of`, and `find_last_not_of`.
918
+
919
+ - Each member function of the form
920
+ ``` cpp
921
+ constexpr return-type F(const charT* s, size_type pos) const;
922
+ ```
923
+
924
+ has effects equivalent to: `return F(basic_string_view(s), pos);`
925
+ - Each member function of the form
926
+ ``` cpp
927
+ constexpr return-type F(const charT* s, size_type pos, size_type n) const;
928
+ ```
929
+
930
+ has effects equivalent to: `return F(basic_string_view(s, n), pos);`
931
+ - Each member function of the form
932
+ ``` cpp
933
+ constexpr return-type F(charT c, size_type pos) const noexcept;
934
+ ```
935
+
936
+ has effects equivalent to:
937
+ `return F(basic_string_view(addressof(c), 1), pos);`
938
+
939
+ ``` cpp
940
+ constexpr size_type find(basic_string_view str, size_type pos = 0) const noexcept;
941
+ ```
942
+
943
+ Let `xpos` be the lowest position, if possible, such that the following
944
+ conditions hold:
945
+
946
+ - `pos <= xpos`
947
+ - `xpos + str.size() <= size()`
948
+ - `traits::eq(at(xpos + I), str.at(I))` for all elements `I` of the
949
+ string referenced by `str`.
950
+
951
+ *Effects:* Determines `xpos`.
952
+
953
+ *Returns:* `xpos` if the function can determine such a value for `xpos`.
954
+ Otherwise, returns `npos`.
955
+
956
+ ``` cpp
957
+ constexpr size_type rfind(basic_string_view str, size_type pos = npos) const noexcept;
958
+ ```
959
+
960
+ Let `xpos` be the highest position, if possible, such that the following
961
+ conditions hold:
962
+
963
+ - `xpos <= pos`
964
+ - `xpos + str.size() <= size()`
965
+ - `traits::eq(at(xpos + I), str.at(I))` for all elements `I` of the
966
+ string referenced by `str`.
967
+
968
+ *Effects:* Determines `xpos`.
969
+
970
+ *Returns:* `xpos` if the function can determine such a value for `xpos`.
971
+ Otherwise, returns `npos`.
972
+
973
+ ``` cpp
974
+ constexpr size_type find_first_of(basic_string_view str, size_type pos = 0) const noexcept;
975
+ ```
976
+
977
+ Let `xpos` be the lowest position, if possible, such that the following
978
+ conditions hold:
979
+
980
+ - `pos <= xpos`
981
+ - `xpos < size()`
982
+ - `traits::eq(at(xpos), str.at(I))` for some element `I` of the string
983
+ referenced by `str`.
984
+
985
+ *Effects:* Determines `xpos`.
986
+
987
+ *Returns:* `xpos` if the function can determine such a value for `xpos`.
988
+ Otherwise, returns `npos`.
989
+
990
+ ``` cpp
991
+ constexpr size_type find_last_of(basic_string_view str, size_type pos = npos) const noexcept;
992
+ ```
993
+
994
+ Let `xpos` be the highest position, if possible, such that the following
995
+ conditions hold:
996
+
997
+ - `xpos <= pos`
998
+ - `xpos < size()`
999
+ - `traits::eq(at(xpos), str.at(I))` for some element `I` of the string
1000
+ referenced by `str`.
1001
+
1002
+ *Effects:* Determines `xpos`.
1003
+
1004
+ *Returns:* `xpos` if the function can determine such a value for `xpos`.
1005
+ Otherwise, returns `npos`.
1006
+
1007
+ ``` cpp
1008
+ constexpr size_type find_first_not_of(basic_string_view str, size_type pos = 0) const noexcept;
1009
+ ```
1010
+
1011
+ Let `xpos` be the lowest position, if possible, such that the following
1012
+ conditions hold:
1013
+
1014
+ - `pos <= xpos`
1015
+ - `xpos < size()`
1016
+ - `traits::eq(at(xpos), str.at(I))` for no element `I` of the string
1017
+ referenced by `str`.
1018
+
1019
+ *Effects:* Determines `xpos`.
1020
+
1021
+ *Returns:* `xpos` if the function can determine such a value for `xpos`.
1022
+ Otherwise, returns `npos`.
1023
+
1024
+ ``` cpp
1025
+ constexpr size_type find_last_not_of(basic_string_view str, size_type pos = npos) const noexcept;
1026
+ ```
1027
+
1028
+ Let `xpos` be the highest position, if possible, such that the following
1029
+ conditions hold:
1030
+
1031
+ - `xpos <= pos`
1032
+ - `xpos < size()`
1033
+ - `traits::eq(at(xpos), str.at(I))` for no element `I` of the string
1034
+ referenced by `str`.
1035
+
1036
+ *Effects:* Determines `xpos`.
1037
+
1038
+ *Returns:* `xpos` if the function can determine such a value for `xpos`.
1039
+ Otherwise, returns `npos`.
1040
+
1041
+ ### Non-member comparison functions <a id="string.view.comparison">[[string.view.comparison]]</a>
1042
+
1043
+ Let `S` be `basic_string_view<charT, traits>`, and `sv` be an instance
1044
+ of `S`. Implementations shall provide sufficient additional overloads
1045
+ marked `constexpr` and `noexcept` so that an object `t` with an implicit
1046
+ conversion to `S` can be compared according to
1047
+ [[string.view.comparison.overloads]].
1048
+
1049
+ **Table: Additional `basic_string_view` comparison overloads** <a id="string.view.comparison.overloads">[string.view.comparison.overloads]</a>
1050
+
1051
+ | Expression | Equivalent to |
1052
+ | ---------- | ------------- |
1053
+ | `t == sv` | `S(t) == sv` |
1054
+ | `sv == t` | `sv == S(t)` |
1055
+ | `t != sv` | `S(t) != sv` |
1056
+ | `sv != t` | `sv != S(t)` |
1057
+ | `t < sv` | `S(t) < sv` |
1058
+ | `sv < t` | `sv < S(t)` |
1059
+ | `t > sv` | `S(t) > sv` |
1060
+ | `sv > t` | `sv > S(t)` |
1061
+ | `t <= sv` | `S(t) <= sv` |
1062
+ | `sv <= t` | `sv <= S(t)` |
1063
+ | `t >= sv` | `S(t) >= sv` |
1064
+ | `sv >= t` | `sv >= S(t)` |
1065
+ | `t <=> sv` | `S(t) <=> sv` |
1066
+ | `sv <=> t` | `sv <=> S(t)` |
1067
+
1068
+
1069
+ [*Example 1*:
1070
+
1071
+ A sample conforming implementation for `operator==` would be:
1072
+
1073
+ ``` cpp
1074
+ template<class charT, class traits>
1075
+ constexpr bool operator==(basic_string_view<charT, traits> lhs,
1076
+ basic_string_view<charT, traits> rhs) noexcept {
1077
+ return lhs.compare(rhs) == 0;
1078
+ }
1079
+ template<class charT, class traits>
1080
+ constexpr bool operator==(basic_string_view<charT, traits> lhs,
1081
+ type_identity_t<basic_string_view<charT, traits>> rhs) noexcept {
1082
+ return lhs.compare(rhs) == 0;
1083
+ }
1084
+ ```
1085
+
1086
+ — *end example*]
1087
+
1088
+ ``` cpp
1089
+ template<class charT, class traits>
1090
+ constexpr bool operator==(basic_string_view<charT, traits> lhs,
1091
+ basic_string_view<charT, traits> rhs) noexcept;
1092
+ ```
1093
+
1094
+ *Returns:* `lhs.compare(rhs) == 0`.
1095
+
1096
+ ``` cpp
1097
+ template<class charT, class traits>
1098
+ constexpr see below operator<=>(basic_string_view<charT, traits> lhs,
1099
+ \itcorr basic_string_view<charT, traits> rhs) noexcept;
1100
+ ```
1101
+
1102
+ Let `R` denote the type `traits::comparison_category` if that
1103
+ *qualified-id* is valid and denotes a type [[temp.deduct]], otherwise
1104
+ `R` is `weak_ordering`.
1105
+
1106
+ *Mandates:* `R` denotes a comparison category type [[cmp.categories]].
1107
+
1108
+ *Returns:* `static_cast<R>(lhs.compare(rhs) <=> 0)`.
1109
+
1110
+ ### Inserters and extractors <a id="string.view.io">[[string.view.io]]</a>
1111
+
1112
+ ``` cpp
1113
+ template<class charT, class traits>
1114
+ basic_ostream<charT, traits>&
1115
+ operator<<(basic_ostream<charT, traits>& os, basic_string_view<charT, traits> str);
1116
+ ```
1117
+
1118
+ *Effects:* Behaves as a formatted output
1119
+ function [[ostream.formatted.reqmts]] of `os`. Forms a character
1120
+ sequence `seq`, initially consisting of the elements defined by the
1121
+ range \[`str.begin()`, `str.end()`). Determines padding for `seq` as
1122
+ described in  [[ostream.formatted.reqmts]]. Then inserts `seq` as if by
1123
+ calling `os.rdbuf()->sputn(seq, n)`, where `n` is the larger of
1124
+ `os.width()` and `str.size()`; then calls `os.width(0)`.
1125
+
1126
+ *Returns:* `os`
1127
+
1128
+ ### Hash support <a id="string.view.hash">[[string.view.hash]]</a>
1129
+
1130
+ ``` cpp
1131
+ template<> struct hash<string_view>;
1132
+ template<> struct hash<u8string_view>;
1133
+ template<> struct hash<u16string_view>;
1134
+ template<> struct hash<u32string_view>;
1135
+ template<> struct hash<wstring_view>;
1136
+ ```
1137
+
1138
+ The specialization is enabled [[unord.hash]].
1139
+
1140
+ [*Note 1*: The hash value of a string view object is equal to the hash
1141
+ value of the corresponding string
1142
+ object [[basic.string.hash]]. — *end note*]
1143
+
1144
+ ### Suffix for `basic_string_view` literals <a id="string.view.literals">[[string.view.literals]]</a>
1145
+
1146
+ ``` cpp
1147
+ constexpr string_view operator""sv(const char* str, size_t len) noexcept;
1148
+ ```
1149
+
1150
+ *Returns:* `string_view{str, len}`.
1151
+
1152
+ ``` cpp
1153
+ constexpr u8string_view operator""sv(const char8_t* str, size_t len) noexcept;
1154
+ ```
1155
+
1156
+ *Returns:* `u8string_view{str, len}`.
1157
+
1158
+ ``` cpp
1159
+ constexpr u16string_view operator""sv(const char16_t* str, size_t len) noexcept;
1160
+ ```
1161
+
1162
+ *Returns:* `u16string_view{str, len}`.
1163
+
1164
+ ``` cpp
1165
+ constexpr u32string_view operator""sv(const char32_t* str, size_t len) noexcept;
1166
+ ```
1167
+
1168
+ *Returns:* `u32string_view{str, len}`.
1169
+
1170
+ ``` cpp
1171
+ constexpr wstring_view operator""sv(const wchar_t* str, size_t len) noexcept;
1172
+ ```
1173
+
1174
+ *Returns:* `wstring_view{str, len}`.
1175
+
1176
  ## String classes <a id="string.classes">[[string.classes]]</a>
1177
 
1178
+ ### General <a id="string.classes.general">[[string.classes.general]]</a>
1179
+
1180
  The header `<string>` defines the `basic_string` class template for
1181
  manipulating varying-length sequences of char-like objects and five
1182
  *typedef-name*s, `string`, `u8string`, `u16string`, `u32string`, and
1183
  `wstring`, that name the specializations `basic_string<char>`,
1184
  `basic_string<char8_t>`, `basic_string<char16_t>`,
 
1308
  erase(basic_string<charT, traits, Allocator>& c, const U& value);
1309
  template<class charT, class traits, class Allocator, class Predicate>
1310
  constexpr typename basic_string<charT, traits, Allocator>::size_type
1311
  erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred);
1312
 
1313
+ // basic_string typedef-names
1314
  using string = basic_string<char>;
1315
  using u8string = basic_string<char8_t>;
1316
  using u16string = basic_string<char16_t>;
1317
  using u32string = basic_string<char32_t>;
1318
  using wstring = basic_string<wchar_t>;
 
1365
  using wstring = basic_string<wchar_t>;
1366
  }
1367
 
1368
  // [basic.string.hash], hash support
1369
  template<class T> struct hash;
1370
+ template<class A> struct hash<basic_string<char, char_traits<char>, A>>;
1371
+ template<class A> struct hash<basic_string<char8_t, char_traits<char8_t>, A>>;
1372
+ template<class A> struct hash<basic_string<char16_t, char_traits<char16_t>, A>>;
1373
+ template<class A> struct hash<basic_string<char32_t, char_traits<char32_t>, A>>;
1374
+ template<class A> struct hash<basic_string<wchar_t, char_traits<wchar_t>, A>>;
 
 
 
 
 
1375
 
1376
  inline namespace literals {
1377
  inline namespace string_literals {
1378
  // [basic.string.literals], suffix for basic_string literals
1379
  constexpr string operator""s(const char* str, size_t len);
 
1386
  }
1387
  ```
1388
 
1389
  ### Class template `basic_string` <a id="basic.string">[[basic.string]]</a>
1390
 
1391
+ #### General <a id="basic.string.general">[[basic.string.general]]</a>
1392
+
1393
  The class template `basic_string` describes objects that can store a
1394
  sequence consisting of a varying number of arbitrary char-like objects
1395
  with the first element of the sequence at position zero. Such a sequence
1396
  is also called a “string” if the type of the char-like objects that it
1397
+ holds is clear from context. In the rest of [[basic.string]], the type
1398
+ of the char-like objects held in a `basic_string` object is designated
1399
+ by `charT`.
1400
 
1401
  A specialization of `basic_string` is a contiguous container
1402
+ [[container.reqmts]].
1403
 
1404
  In all cases, \[`data()`, `data() + size()`\] is a valid range,
1405
  `data() + size()` points at an object with value `charT()` (a “null
1406
  terminator”), and `size() <= capacity()` is `true`.
1407
 
 
1424
 
1425
  using iterator = implementation-defined // type of basic_string::iterator; // see [container.requirements]
1426
  using const_iterator = implementation-defined // type of basic_string::const_iterator; // see [container.requirements]
1427
  using reverse_iterator = std::reverse_iterator<iterator>;
1428
  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
1429
+ static constexpr size_type npos = size_type(-1);
1430
 
1431
  // [string.cons], construct/copy/destroy
1432
  constexpr basic_string() noexcept(noexcept(Allocator())) : basic_string(Allocator()) { }
1433
  constexpr explicit basic_string(const Allocator& a) noexcept;
1434
  constexpr basic_string(const basic_string& str);
1435
  constexpr basic_string(basic_string&& str) noexcept;
1436
  constexpr basic_string(const basic_string& str, size_type pos,
1437
  const Allocator& a = Allocator());
1438
  constexpr basic_string(const basic_string& str, size_type pos, size_type n,
1439
  const Allocator& a = Allocator());
1440
+ constexpr basic_string(basic_string&& str, size_type pos,
1441
+ const Allocator& a = Allocator());
1442
+ constexpr basic_string(basic_string&& str, size_type pos, size_type n,
1443
+ const Allocator& a = Allocator());
1444
  template<class T>
1445
  constexpr basic_string(const T& t, size_type pos, size_type n,
1446
  const Allocator& a = Allocator());
1447
  template<class T>
1448
  constexpr explicit basic_string(const T& t, const Allocator& a = Allocator());
1449
  constexpr basic_string(const charT* s, size_type n, const Allocator& a = Allocator());
1450
  constexpr basic_string(const charT* s, const Allocator& a = Allocator());
1451
+ basic_string(nullptr_t) = delete;
1452
  constexpr basic_string(size_type n, charT c, const Allocator& a = Allocator());
1453
  template<class InputIterator>
1454
  constexpr basic_string(InputIterator begin, InputIterator end,
1455
  const Allocator& a = Allocator());
1456
+ template<container-compatible-range<charT> R>
1457
+ constexpr basic_string(from_range_t, R&& rg, const Allocator& a = Allocator());
1458
  constexpr basic_string(initializer_list<charT>, const Allocator& = Allocator());
1459
  constexpr basic_string(const basic_string&, const Allocator&);
1460
  constexpr basic_string(basic_string&&, const Allocator&);
1461
  constexpr ~basic_string();
1462
 
 
1465
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
1466
  allocator_traits<Allocator>::is_always_equal::value);
1467
  template<class T>
1468
  constexpr basic_string& operator=(const T& t);
1469
  constexpr basic_string& operator=(const charT* s);
1470
+ basic_string& operator=(nullptr_t) = delete;
1471
  constexpr basic_string& operator=(charT c);
1472
  constexpr basic_string& operator=(initializer_list<charT>);
1473
 
1474
  // [string.iterators], iterators
1475
  constexpr iterator begin() noexcept;
 
1491
  constexpr size_type size() const noexcept;
1492
  constexpr size_type length() const noexcept;
1493
  constexpr size_type max_size() const noexcept;
1494
  constexpr void resize(size_type n, charT c);
1495
  constexpr void resize(size_type n);
1496
+ template<class Operation> constexpr void resize_and_overwrite(size_type n, Operation op);
1497
  constexpr size_type capacity() const noexcept;
1498
  constexpr void reserve(size_type res_arg);
1499
  constexpr void shrink_to_fit();
1500
  constexpr void clear() noexcept;
1501
  [[nodiscard]] constexpr bool empty() const noexcept;
 
1527
  constexpr basic_string& append(const charT* s, size_type n);
1528
  constexpr basic_string& append(const charT* s);
1529
  constexpr basic_string& append(size_type n, charT c);
1530
  template<class InputIterator>
1531
  constexpr basic_string& append(InputIterator first, InputIterator last);
1532
+ template<container-compatible-range<charT> R>
1533
+ constexpr basic_string& append_range(R&& rg);
1534
  constexpr basic_string& append(initializer_list<charT>);
1535
 
1536
  constexpr void push_back(charT c);
1537
 
1538
  constexpr basic_string& assign(const basic_string& str);
 
1547
  constexpr basic_string& assign(const charT* s, size_type n);
1548
  constexpr basic_string& assign(const charT* s);
1549
  constexpr basic_string& assign(size_type n, charT c);
1550
  template<class InputIterator>
1551
  constexpr basic_string& assign(InputIterator first, InputIterator last);
1552
+ template<container-compatible-range<charT> R>
1553
+ constexpr basic_string& assign_range(R&& rg);
1554
  constexpr basic_string& assign(initializer_list<charT>);
1555
 
1556
  constexpr basic_string& insert(size_type pos, const basic_string& str);
1557
  constexpr basic_string& insert(size_type pos1, const basic_string& str,
1558
  size_type pos2, size_type n = npos);
 
1566
  constexpr basic_string& insert(size_type pos, size_type n, charT c);
1567
  constexpr iterator insert(const_iterator p, charT c);
1568
  constexpr iterator insert(const_iterator p, size_type n, charT c);
1569
  template<class InputIterator>
1570
  constexpr iterator insert(const_iterator p, InputIterator first, InputIterator last);
1571
+ template<container-compatible-range<charT> R>
1572
+ constexpr iterator insert_range(const_iterator p, R&& rg);
1573
  constexpr iterator insert(const_iterator p, initializer_list<charT>);
1574
 
1575
  constexpr basic_string& erase(size_type pos = 0, size_type n = npos);
1576
  constexpr iterator erase(const_iterator p);
1577
  constexpr iterator erase(const_iterator first, const_iterator last);
 
1598
  constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
1599
  constexpr basic_string& replace(const_iterator i1, const_iterator i2, size_type n, charT c);
1600
  template<class InputIterator>
1601
  constexpr basic_string& replace(const_iterator i1, const_iterator i2,
1602
  InputIterator j1, InputIterator j2);
1603
+ template<container-compatible-range<charT> R>
1604
+ constexpr basic_string& replace_with_range(const_iterator i1, const_iterator i2, R&& rg);
1605
  constexpr basic_string& replace(const_iterator, const_iterator, initializer_list<charT>);
1606
 
1607
  constexpr size_type copy(charT* s, size_type n, size_type pos = 0) const;
1608
 
1609
  constexpr void swap(basic_string& str)
 
1660
  size_type pos = npos) const noexcept;
1661
  constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
1662
  constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
1663
  constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
1664
 
1665
+ constexpr basic_string substr(size_type pos = 0, size_type n = npos) const &;
1666
+ constexpr basic_string substr(size_type pos = 0, size_type n = npos) &&;
1667
 
1668
  template<class T>
1669
  constexpr int compare(const T& t) const noexcept(see below);
1670
  template<class T>
1671
  constexpr int compare(size_type pos1, size_type n1, const T& t) const;
 
1684
  constexpr bool starts_with(charT x) const noexcept;
1685
  constexpr bool starts_with(const charT* x) const;
1686
  constexpr bool ends_with(basic_string_view<charT, traits> x) const noexcept;
1687
  constexpr bool ends_with(charT x) const noexcept;
1688
  constexpr bool ends_with(const charT* x) const;
1689
+
1690
+ constexpr bool contains(basic_string_view<charT, traits> x) const noexcept;
1691
+ constexpr bool contains(charT x) const noexcept;
1692
+ constexpr bool contains(const charT* x) const;
1693
  };
1694
 
1695
  template<class InputIterator,
1696
  class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
1697
  basic_string(InputIterator, InputIterator, Allocator = Allocator())
1698
  -> basic_string<typename iterator_traits<InputIterator>::value_type,
1699
  char_traits<typename iterator_traits<InputIterator>::value_type>,
1700
  Allocator>;
1701
 
1702
+ template<ranges::input_range R,
1703
+ class Allocator = allocator<ranges::range_value_t<R>>>
1704
+ basic_string(from_range_t, R&&, Allocator = Allocator())
1705
+ -> basic_string<ranges::range_value_t<R>, char_traits<ranges::range_value_t<R>>,
1706
+ Allocator>;
1707
+
1708
  template<class charT,
1709
  class traits,
1710
  class Allocator = allocator<charT>>
1711
  explicit basic_string(basic_string_view<charT, traits>, const Allocator& = Allocator())
1712
  -> basic_string<charT, traits, Allocator>;
 
1723
 
1724
  A `size_type` parameter type in a `basic_string` deduction guide refers
1725
  to the `size_type` member type of the type deduced by the deduction
1726
  guide.
1727
 
1728
+ The types `iterator` and `const_iterator` meet the constexpr iterator
1729
+ requirements [[iterator.requirements.general]].
1730
+
1731
  #### General requirements <a id="string.require">[[string.require]]</a>
1732
 
1733
  If any operation would cause `size()` to exceed `max_size()`, that
1734
  operation throws an exception object of type `length_error`.
1735
 
 
1745
  objects as needed. The `Allocator` object used is obtained as described
1746
  in [[container.requirements.general]]. In every specialization
1747
  `basic_string<charT, traits, Allocator>`, the type `traits` shall meet
1748
  the character traits requirements [[char.traits]].
1749
 
1750
+ [*Note 1*: Every specialization
1751
+ `basic_string<charT, traits, Allocator>` is an allocator-aware
1752
+ container, but does not use the allocator’s `construct` and `destroy`
1753
+ member functions [[container.requirements.general]]. — *end note*]
1754
+
1755
+ [*Note 2*: The program is ill-formed if `traits::char_type` is not the
1756
  same type as `charT`. — *end note*]
1757
 
1758
  References, pointers, and iterators referring to the elements of a
1759
  `basic_string` sequence may be invalidated by the following uses of that
1760
  `basic_string` object:
1761
 
1762
  - Passing as an argument to any standard library function taking a
1763
+ reference to non-const `basic_string` as an argument.[^3]
1764
  - Calling non-const member functions, except `operator[]`, `at`, `data`,
1765
  `front`, `back`, `begin`, `rbegin`, `end`, and `rend`.
1766
 
1767
  #### Constructors and assignment operators <a id="string.cons">[[string.cons]]</a>
1768
 
 
1786
  ``` cpp
1787
  constexpr basic_string(const basic_string& str, size_type pos,
1788
  const Allocator& a = Allocator());
1789
  constexpr basic_string(const basic_string& str, size_type pos, size_type n,
1790
  const Allocator& a = Allocator());
1791
+ constexpr basic_string(basic_string&& str, size_type pos,
1792
+ const Allocator& a = Allocator());
1793
+ constexpr basic_string(basic_string&& str, size_type pos, size_type n,
1794
+ const Allocator& a = Allocator());
1795
  ```
1796
 
1797
+ Let
1798
 
1799
+ - `s` be the value of `str` prior to this call and
1800
+ - `rlen` be `pos + min(n, s.size() - pos)` for the overloads with
1801
+ parameter `n`, and `s.size()` otherwise.
1802
+
1803
+ *Effects:* Constructs an object whose initial value is the range
1804
+ \[`s.data() + pos`, `s.data() + rlen`).
1805
+
1806
+ *Throws:* `out_of_range` if `pos > s.size()`.
1807
+
1808
+ *Remarks:* For the overloads with a `basic_string&&` parameter, `str` is
1809
+ left in a valid but unspecified state.
1810
+
1811
+ *Recommended practice:* For the overloads with a `basic_string&&`
1812
+ parameter, implementations should avoid allocation if
1813
+ `s.get_allocator() == a` is `true`.
1814
 
1815
  ``` cpp
1816
  template<class T>
1817
  constexpr basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator());
1818
  ```
 
1887
 
1888
  *Constraints:* `InputIterator` is a type that qualifies as an input
1889
  iterator [[container.requirements.general]].
1890
 
1891
  *Effects:* Constructs a string from the values in the range \[`begin`,
1892
+ `end`), as specified in [[sequence.reqmts]].
1893
+
1894
+ ``` cpp
1895
+ template<container-compatible-range<charT> R>
1896
+ constexpr basic_string(from_range_t, R&& rg, const Allocator& = Allocator());
1897
+ ```
1898
+
1899
+ *Effects:* Constructs a string from the values in the range `rg`, as
1900
+ specified in [[sequence.reqmts]].
1901
 
1902
  ``` cpp
1903
  constexpr basic_string(initializer_list<charT> il, const Allocator& a = Allocator());
1904
  ```
1905
 
 
2085
  constexpr void resize(size_type n);
2086
  ```
2087
 
2088
  *Effects:* Equivalent to `resize(n, charT())`.
2089
 
2090
+ ``` cpp
2091
+ template<class Operation> constexpr void resize_and_overwrite(size_type n, Operation op);
2092
+ ```
2093
+
2094
+ Let
2095
+
2096
+ - `o = size()` before the call to `resize_and_overwrite`.
2097
+ - `k` be `min(o, n)`.
2098
+ - `p` be a value of type `charT*` or `charT* const`, such that the range
2099
+ \[`p`, `p + n`\] is valid and `this->compare(0, k, p, k) == 0` is
2100
+ `true` before the call. The values in the range \[`p + k`, `p + n`\]
2101
+ may be indeterminate [[basic.indet]].
2102
+ - `m` be a value of type `size_type` or `const size_type` equal to `n`.
2103
+ - *`OP`* be the expression `std::move(op)(p, m)`.
2104
+ - `r` = *`OP`*.
2105
+
2106
+ *Mandates:* *`OP`* has an integer-like type [[iterator.concept.winc]].
2107
+
2108
+ *Preconditions:*
2109
+
2110
+ - *`OP`* does not throw an exception or modify `p` or `m`.
2111
+ - `r` ≥ 0.
2112
+ - `r` ≤ `m`.
2113
+ - After evaluating *`OP`* there are no indeterminate values in the range
2114
+ \[`p`, `p + r`).
2115
+
2116
+ *Effects:* Evaluates *`OP`*, replaces the contents of `*this` with
2117
+ \[`p`, `p + r`), and invalidates all pointers and references to the
2118
+ range \[`p`, `p + n`\].
2119
+
2120
+ *Recommended practice:* Implementations should avoid unnecessary copies
2121
+ and allocations by, for example, making `p` a pointer into internal
2122
+ storage and by restoring `*(p + r)` to `charT()` after evaluating
2123
+ *`OP`*.
2124
+
2125
  ``` cpp
2126
  constexpr size_type capacity() const noexcept;
2127
  ```
2128
 
2129
  *Returns:* The size of the allocated storage in the string.
 
2200
  ``` cpp
2201
  constexpr const_reference at(size_type pos) const;
2202
  constexpr reference at(size_type pos);
2203
  ```
2204
 
 
 
2205
  *Returns:* `operator[](pos)`.
2206
 
2207
+ *Throws:* `out_of_range` if `pos >= size()`.
2208
+
2209
  ``` cpp
2210
  constexpr const charT& front() const;
2211
  constexpr charT& front();
2212
  ```
2213
 
 
2357
  iterator [[container.requirements.general]].
2358
 
2359
  *Effects:* Equivalent to:
2360
  `return append(basic_string(first, last, get_allocator()));`
2361
 
2362
+ ``` cpp
2363
+ template<container-compatible-range<charT> R>
2364
+ constexpr basic_string& append_range(R&& rg);
2365
+ ```
2366
+
2367
+ *Effects:* Equivalent to:
2368
+ `return append(basic_string(from_range, std::forward<R>(rg), get_allocator()));`
2369
+
2370
  ``` cpp
2371
  constexpr basic_string& append(initializer_list<charT> il);
2372
  ```
2373
 
2374
  *Effects:* Equivalent to: `return append(il.begin(), il.size());`
 
2485
  iterator [[container.requirements.general]].
2486
 
2487
  *Effects:* Equivalent to:
2488
  `return assign(basic_string(first, last, get_allocator()));`
2489
 
2490
+ ``` cpp
2491
+ template<container-compatible-range<charT> R>
2492
+ constexpr basic_string& assign_range(R&& rg);
2493
+ ```
2494
+
2495
+ *Effects:* Equivalent to:
2496
+ `return assign(basic_string(from_range, std::forward<R>(rg), get_allocator()));`
2497
+
2498
  ##### `basic_string::insert` <a id="string.insert">[[string.insert]]</a>
2499
 
2500
  ``` cpp
2501
  constexpr basic_string& insert(size_type pos, const basic_string& str);
2502
  ```
 
2555
  constexpr basic_string& insert(size_type pos, const charT* s, size_type n);
2556
  ```
2557
 
2558
  *Preconditions:* \[`s`, `s + n`) is a valid range.
2559
 
 
 
 
 
 
 
2560
  *Effects:* Inserts a copy of the range \[`s`, `s + n`) immediately
2561
  before the character at position `pos` if `pos < size()`, or otherwise
2562
  at the end of the string.
2563
 
2564
  *Returns:* `*this`.
2565
 
2566
+ *Throws:*
2567
+
2568
+ - `out_of_range` if `pos > size()`,
2569
+ - `length_error` if `n > max_size() - size()`, or
2570
+ - any exceptions thrown by `allocator_traits<Allocator>::allocate`.
2571
+
2572
  ``` cpp
2573
  constexpr basic_string& insert(size_type pos, const charT* s);
2574
  ```
2575
 
2576
  *Effects:* Equivalent to: `return insert(pos, s, traits::length(s));`
 
2625
  `insert(p - begin(), basic_string(first, last, get_allocator()))`.
2626
 
2627
  *Returns:* An iterator which refers to the first inserted character, or
2628
  `p` if `first == last`.
2629
 
2630
+ ``` cpp
2631
+ template<container-compatible-range<charT> R>
2632
+ constexpr iterator insert_range(const_iterator p, R&& rg);
2633
+ ```
2634
+
2635
+ *Preconditions:* `p` is a valid iterator on `*this`.
2636
+
2637
+ *Effects:* Equivalent to
2638
+ `insert(p - begin(), basic_string(from_range, std::forward<R>(rg), get_allocator()))`.
2639
+
2640
+ *Returns:* An iterator which refers to the first inserted character, or
2641
+ `p` if `rg` is empty.
2642
+
2643
  ``` cpp
2644
  constexpr iterator insert(const_iterator p, initializer_list<charT> il);
2645
  ```
2646
 
2647
  *Effects:* Equivalent to: `return insert(p, il.begin(), il.end());`
 
2650
 
2651
  ``` cpp
2652
  constexpr basic_string& erase(size_type pos = 0, size_type n = npos);
2653
  ```
2654
 
 
 
2655
  *Effects:* Determines the effective length `xlen` of the string to be
2656
  removed as the smaller of `n` and `size() - pos`. Removes the characters
2657
  in the range \[`begin() + pos`, `begin() + pos + xlen`).
2658
 
2659
  *Returns:* `*this`.
2660
 
2661
+ *Throws:* `out_of_range` if `pos` `> size()`.
2662
+
2663
  ``` cpp
2664
  constexpr iterator erase(const_iterator p);
2665
  ```
2666
 
2667
  *Preconditions:* `p` is a valid dereferenceable iterator on `*this`.
2668
 
 
 
2669
  *Effects:* Removes the character referred to by `p`.
2670
 
2671
  *Returns:* An iterator which points to the element immediately following
2672
  `p` prior to the element being erased. If no such element exists,
2673
  `end()` is returned.
2674
 
2675
+ *Throws:* Nothing.
2676
+
2677
  ``` cpp
2678
  constexpr iterator erase(const_iterator first, const_iterator last);
2679
  ```
2680
 
2681
  *Preconditions:* `first` and `last` are valid iterators on `*this`.
2682
  \[`first`, `last`) is a valid range.
2683
 
 
 
2684
  *Effects:* Removes the characters in the range `[first, last)`.
2685
 
2686
  *Returns:* An iterator which points to the element pointed to by `last`
2687
  prior to the other elements being erased. If no such element exists,
2688
  `end()` is returned.
2689
 
2690
+ *Throws:* Nothing.
2691
+
2692
  ``` cpp
2693
  constexpr void pop_back();
2694
  ```
2695
 
2696
  *Preconditions:* `!empty()`.
2697
 
 
 
2698
  *Effects:* Equivalent to `erase(end() - 1)`.
2699
 
2700
+ *Throws:* Nothing.
2701
+
2702
  ##### `basic_string::replace` <a id="string.replace">[[string.replace]]</a>
2703
 
2704
  ``` cpp
2705
  constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
2706
  ```
 
2760
  constexpr basic_string& replace(size_type pos1, size_type n1, const charT* s, size_type n2);
2761
  ```
2762
 
2763
  *Preconditions:* \[`s`, `s + n2`) is a valid range.
2764
 
 
 
 
 
 
 
 
2765
  *Effects:* Determines the effective length `xlen` of the string to be
2766
  removed as the smaller of `n1` and `size() - pos1`. If
2767
  `size() - xlen >= max_size() - n2` throws `length_error`. Otherwise, the
2768
  function replaces the characters in the range \[`begin() + pos1`,
2769
  `begin() + pos1 + xlen`) with a copy of the range \[`s`, `s + n2`).
2770
 
2771
  *Returns:* `*this`.
2772
 
2773
+ *Throws:*
2774
+
2775
+ - `out_of_range` if `pos1 > size()`,
2776
+ - `length_error` if the length of the resulting string would exceed
2777
+ `max_size()`, or
2778
+ - any exceptions thrown by `allocator_traits<Allocator>::allocate`.
2779
+
2780
  ``` cpp
2781
  constexpr basic_string& replace(size_type pos, size_type n, const charT* s);
2782
  ```
2783
 
2784
  *Effects:* Equivalent to:
 
2786
 
2787
  ``` cpp
2788
  constexpr basic_string& replace(size_type pos1, size_type n1, size_type n2, charT c);
2789
  ```
2790
 
 
 
 
 
 
 
 
2791
  *Effects:* Determines the effective length `xlen` of the string to be
2792
  removed as the smaller of `n1` and `size() - pos1`. If
2793
  `size() - xlen >=` `max_size() - n2` throws `length_error`. Otherwise,
2794
  the function replaces the characters in the range \[`begin() + pos1`,
2795
  `begin() + pos1 + xlen`) with `n2` copies of `c`.
2796
 
2797
  *Returns:* `*this`.
2798
 
2799
+ *Throws:*
2800
+
2801
+ - `out_of_range` if `pos1 > size()`,
2802
+ - `length_error` if the length of the resulting string would
2803
+ exceed`max_size()`, or
2804
+ - any exceptions thrown by `allocator_traits<Allocator>::allocate.`
2805
+
2806
  ``` cpp
2807
  constexpr basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
2808
  ```
2809
 
2810
  *Effects:* Equivalent to:
 
2862
  iterator [[container.requirements.general]].
2863
 
2864
  *Effects:* Equivalent to:
2865
  `return replace(i1, i2, basic_string(j1, j2, get_allocator()));`
2866
 
2867
+ ``` cpp
2868
+ template<container-compatible-range<charT> R>
2869
+ constexpr basic_string& replace_with_range(const_iterator i1, const_iterator i2, R&& rg);
2870
+ ```
2871
+
2872
+ *Effects:* Equivalent to:
2873
+
2874
+ ``` cpp
2875
+ return replace(i1, i2, basic_string(from_range, std::forward<R>(rg), get_allocator()));
2876
+ ```
2877
+
2878
  ``` cpp
2879
  constexpr basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<charT> il);
2880
  ```
2881
 
2882
  *Effects:* Equivalent to:
 
3019
  ``` cpp
3020
  basic_string_view<charT, traits> s = *this, sv = t;
3021
  return s.G(sv, pos);
3022
  ```
3023
 
3024
+ *Remarks:* The exception specification is equivalent to
3025
  `is_nothrow_convertible_v<const T&, basic_string_view<charT, traits>>`.
3026
 
3027
  ##### `basic_string::substr` <a id="string.substr">[[string.substr]]</a>
3028
 
3029
  ``` cpp
3030
+ constexpr basic_string substr(size_type pos = 0, size_type n = npos) const &;
3031
  ```
3032
 
3033
+ *Effects:* Equivalent to: `return basic_string(*this, pos, n);`
3034
 
3035
+ ``` cpp
3036
+ constexpr basic_string substr(size_type pos = 0, size_type n = npos) &&;
3037
+ ```
3038
 
3039
+ *Effects:* Equivalent to:
3040
+ `return basic_string(std::move(*this), pos, n);`
3041
 
3042
  ##### `basic_string::compare` <a id="string.compare">[[string.compare]]</a>
3043
 
3044
  ``` cpp
3045
  template<class T>
 
3053
  - `is_convertible_v<const T&, const charT*>` is `false`.
3054
 
3055
  *Effects:* Equivalent to:
3056
  `return basic_string_view<charT, traits>(*this).compare(t);`
3057
 
3058
+ *Remarks:* The exception specification is equivalent to
3059
  `is_nothrow_convertible_v<const T&, basic_string_view<charT, traits>>`.
3060
 
3061
  ``` cpp
3062
  template<class T>
3063
  constexpr int compare(size_type pos1, size_type n1, const T& t) const;
 
3166
 
3167
  ``` cpp
3168
  return basic_string_view<charT, traits>(data(), size()).ends_with(x);
3169
  ```
3170
 
3171
+ ##### `basic_string::contains` <a id="string.contains">[[string.contains]]</a>
3172
+
3173
+ ``` cpp
3174
+ constexpr bool contains(basic_string_view<charT, traits> x) const noexcept;
3175
+ constexpr bool contains(charT x) const noexcept;
3176
+ constexpr bool contains(const charT* x) const;
3177
+ ```
3178
+
3179
+ *Effects:* Equivalent to:
3180
+
3181
+ ``` cpp
3182
+ return basic_string_view<charT, traits>(data(), size()).contains(x);
3183
+ ```
3184
+
3185
  ### Non-member functions <a id="string.nonmembers">[[string.nonmembers]]</a>
3186
 
3187
  #### `operator+` <a id="string.op.plus">[[string.op.plus]]</a>
3188
 
3189
  ``` cpp
 
3237
 
3238
  except that both `lhs` and `rhs` are left in valid but unspecified
3239
  states.
3240
 
3241
  [*Note 1*: If `lhs` and `rhs` have equal allocators, the implementation
3242
+ can move from either. — *end note*]
3243
 
3244
  ``` cpp
3245
  template<class charT, class traits, class Allocator>
3246
  constexpr basic_string<charT, traits, Allocator>
3247
  operator+(const basic_string<charT, traits, Allocator>& lhs,
 
3324
  ``` cpp
3325
  lhs.push_back(rhs);
3326
  return std::move(lhs);
3327
  ```
3328
 
3329
+ #### Non-member comparison operator functions <a id="string.cmp">[[string.cmp]]</a>
3330
 
3331
  ``` cpp
3332
  template<class charT, class traits, class Allocator>
3333
  constexpr bool
3334
  operator==(const basic_string<charT, traits, Allocator>& lhs,
 
3371
  operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
3372
  ```
3373
 
3374
  *Effects:* Behaves as a formatted input
3375
  function [[istream.formatted.reqmts]]. After constructing a `sentry`
3376
+ object, if the `sentry` object returns `true` when converted to a value
3377
+ of type `bool`, calls `str.erase()` and then extracts characters from
3378
+ `is` and appends them to `str` as if by calling `str.append(1, c)`. If
3379
+ `is.width()` is greater than zero, the maximum number `n` of characters
3380
+ appended is `is.width()`; otherwise `n` is `str.max_size()`. Characters
3381
+ are extracted and appended until any of the following occurs:
3382
 
3383
  - *n* characters are stored;
3384
  - end-of-file occurs on the input sequence;
3385
  - `isspace(c, is.getloc())` is `true` for the next available input
3386
  character *c*.
3387
 
3388
  After the last character (if any) is extracted, `is.width(0)` is called
3389
  and the `sentry` object is destroyed.
3390
 
3391
+ If the function extracts no characters, `ios_base::failbit` is set in
3392
+ the input function’s local error state before `setstate` is called.
 
3393
 
3394
  *Returns:* `is`.
3395
 
3396
  ``` cpp
3397
  template<class charT, class traits, class Allocator>
 
3417
  ```
3418
 
3419
  *Effects:* Behaves as an unformatted input
3420
  function [[istream.unformatted]], except that it does not affect the
3421
  value returned by subsequent calls to `basic_istream<>::gcount()`. After
3422
+ constructing a `sentry` object, if the `sentry` object returns `true`
3423
+ when converted to a value of type `bool`, calls `str.erase()` and then
3424
+ extracts characters from `is` and appends them to `str` as if by calling
3425
+ `str.append(1, c)` until any of the following occurs:
3426
 
3427
+ - end-of-file occurs on the input sequence;
 
3428
  - `traits::eq(c, delim)` for the next available input character *c* (in
3429
+ which case, *c* is extracted but not appended);
3430
+ - `str.max_size()` characters are stored (in which case,
3431
+ `ios_base::failbit` is set in the input function’s local error state).
3432
 
3433
  The conditions are tested in the order shown. In any case, after the
3434
  last character is extracted, the `sentry` object is destroyed.
3435
 
3436
+ If the function extracts no characters, `ios_base::failbit` is set in
3437
+ the input function’s local error state before `setstate` is called.
 
3438
 
3439
  *Returns:* `is`.
3440
 
3441
  ``` cpp
3442
  template<class charT, class traits, class Allocator>
 
3498
  `strtoul(str.c_str(), ptr, base)`, `strtoll(str.c_str(), ptr, base)`,
3499
  and `strtoull(str.c_str(), ptr, base)`, respectively. Each function
3500
  returns the converted result, if any. The argument `ptr` designates a
3501
  pointer to an object internal to the function that is used to determine
3502
  what to store at `*idx`. If the function does not throw an exception and
3503
+ `idx != nullptr`, the function stores in `*idx` the index of the first
3504
  unconverted element of `str`.
3505
 
3506
  *Returns:* The converted result.
3507
 
3508
  *Throws:* `invalid_argument` if `strtol`, `strtoul`, `strtoll`, or
3509
+ `strtoull` reports that no conversion can be performed. Throws
3510
  `out_of_range` if `strtol`, `strtoul`, `strtoll` or `strtoull` sets
3511
  `errno` to `ERANGE`, or if the converted value is outside the range of
3512
  representable values for the return type.
3513
 
3514
  ``` cpp
 
3520
  *Effects:* These functions call `strtof(str.c_str(), ptr)`,
3521
  `strtod(str.c_str(), ptr)`, and `strtold(str.c_str(), ptr)`,
3522
  respectively. Each function returns the converted result, if any. The
3523
  argument `ptr` designates a pointer to an object internal to the
3524
  function that is used to determine what to store at `*idx`. If the
3525
+ function does not throw an exception and `idx != nullptr`, the function
3526
+ stores in `*idx` the index of the first unconverted element of `str`.
3527
 
3528
  *Returns:* The converted result.
3529
 
3530
  *Throws:* `invalid_argument` if `strtof`, `strtod`, or `strtold` reports
3531
+ that no conversion can be performed. Throws `out_of_range` if `strtof`,
3532
+ `strtod`, or `strtold` sets `errno` to `ERANGE` or if the converted
3533
+ value is outside the range of representable values for the return type.
 
3534
 
3535
  ``` cpp
3536
  string to_string(int val);
3537
  string to_string(unsigned val);
3538
  string to_string(long val);
 
3564
  `wcstoul(str.c_str(), ptr, base)`, `wcstoll(str.c_str(), ptr, base)`,
3565
  and `wcstoull(str.c_str(), ptr, base)`, respectively. Each function
3566
  returns the converted result, if any. The argument `ptr` designates a
3567
  pointer to an object internal to the function that is used to determine
3568
  what to store at `*idx`. If the function does not throw an exception and
3569
+ `idx != nullptr`, the function stores in `*idx` the index of the first
3570
  unconverted element of `str`.
3571
 
3572
  *Returns:* The converted result.
3573
 
3574
  *Throws:* `invalid_argument` if `wcstol`, `wcstoul`, `wcstoll`, or
3575
+ `wcstoull` reports that no conversion can be performed. Throws
3576
  `out_of_range` if the converted value is outside the range of
3577
  representable values for the return type.
3578
 
3579
  ``` cpp
3580
  float stof(const wstring& str, size_t* idx = nullptr);
 
3585
  *Effects:* These functions call `wcstof(str.c_str(), ptr)`,
3586
  `wcstod(str.c_str(), ptr)`, and `wcstold(str.c_str(), ptr)`,
3587
  respectively. Each function returns the converted result, if any. The
3588
  argument `ptr` designates a pointer to an object internal to the
3589
  function that is used to determine what to store at `*idx`. If the
3590
+ function does not throw an exception and `idx != nullptr`, the function
3591
+ stores in `*idx` the index of the first unconverted element of `str`.
3592
 
3593
  *Returns:* The converted result.
3594
 
3595
  *Throws:* `invalid_argument` if `wcstof`, `wcstod`, or `wcstold` reports
3596
+ that no conversion can be performed. Throws `out_of_range` if `wcstof`,
3597
+ `wcstod`, or `wcstold` sets `errno` to `ERANGE`.
3598
 
3599
  ``` cpp
3600
  wstring to_wstring(int val);
3601
  wstring to_wstring(unsigned val);
3602
  wstring to_wstring(long val);
 
3616
  internal character buffer of sufficient size `buffsz`.
3617
 
3618
  ### Hash support <a id="basic.string.hash">[[basic.string.hash]]</a>
3619
 
3620
  ``` cpp
3621
+ template<class A> struct hash<basic_string<char, char_traits<char>, A>>;
3622
+ template<class A> struct hash<basic_string<char8_t, char_traits<char8_t>, A>>;
3623
+ template<class A> struct hash<basic_string<char16_t, char_traits<char16_t>, A>>;
3624
+ template<class A> struct hash<basic_string<char32_t, char_traits<char32_t>, A>>;
3625
+ template<class A> struct hash<basic_string<wchar_t, char_traits<wchar_t>, A>>;
 
 
 
 
 
3626
  ```
3627
 
3628
  If `S` is one of these string types, `SV` is the corresponding string
3629
  view type, and `s` is an object of type `S`, then
3630
  `hash<S>()(s) == hash<SV>()(SV(s))`.
 
3664
  [*Note 1*: The same suffix `s` is used for `chrono::duration` literals
3665
  denoting seconds but there is no conflict, since duration suffixes apply
3666
  to numbers and string literal suffixes apply to character array
3667
  literals. — *end note*]
3668
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3669
  ## Null-terminated sequence utilities <a id="c.strings">[[c.strings]]</a>
3670
 
3671
  ### Header `<cctype>` synopsis <a id="cctype.syn">[[cctype.syn]]</a>
3672
 
3673
  ``` cpp
 
3848
  wchar_t* wcstok(wchar_t* s1, const wchar_t* s2, wchar_t** ptr);
3849
  const wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n); // see [library.c]
3850
  wchar_t* wmemchr(wchar_t* s, wchar_t c, size_t n); // see [library.c]
3851
  size_t wcslen(const wchar_t* s);
3852
  wchar_t* wmemset(wchar_t* s, wchar_t c, size_t n);
3853
+ size_t wcsftime(wchar_t* s, size_t maxsize, const wchar_t* format, const tm* timeptr);
3854
  wint_t btowc(int c);
3855
  int wctob(wint_t c);
3856
 
3857
  // [c.mb.wcs], multibyte / wide string and character conversion functions
3858
  int mbsinit(const mbstate_t* ps);
 
3963
  of the corresponding UTF-8 code units and then, if `pc8` is not a null
3964
  pointer, stores the value of the first (or only) such code unit in the
3965
  object pointed to by `pc8`. Subsequent calls will store successive UTF-8
3966
  code units without consuming any additional input until all the code
3967
  units have been stored. If the corresponding Unicode character is
3968
+ U+0000 (null), the resulting state described is the initial conversion
3969
+ state.
3970
 
3971
  *Returns:* The first of the following that applies (given the current
3972
  conversion state):
3973
 
3974
  - `0`, if the next `n` or fewer bytes complete the multibyte character
3975
+ that corresponds to the U+0000 (null) Unicode character (which is the
3976
+ value stored).
3977
  - between `1` and `n` (inclusive), if the next n or fewer bytes complete
3978
+ a valid multibyte character (whose first (or only) code unit is
3979
+ stored); the value returned is the number of bytes that complete the
3980
+ multibyte character.
3981
+ - `(size_t)(-3)`, if the next code unit resulting from a previous call
3982
  has been stored (no bytes from the input have been consumed by this
3983
  call).
3984
  - `(size_t)(-2)`, if the next `n` bytes contribute to an incomplete (but
3985
  potentially valid) multibyte character, and all `n` bytes have been
3986
  processed (no value is stored).
 
4013
  *Remarks:* Calls to `c8rtomb` with a null pointer argument for `s` may
4014
  introduce a data race [[res.on.data.races]] with other calls to
4015
  `c8rtomb` with a null pointer argument for `s`.
4016
 
4017
  <!-- Link reference definitions -->
4018
+ [basic.indet]: basic.md#basic.indet
4019
  [basic.string]: #basic.string
4020
+ [basic.string.general]: #basic.string.general
4021
  [basic.string.hash]: #basic.string.hash
4022
  [basic.string.literals]: #basic.string.literals
 
4023
  [c.mb.wcs]: #c.mb.wcs
4024
  [c.strings]: #c.strings
4025
  [cctype.syn]: #cctype.syn
4026
  [char.traits]: #char.traits
4027
+ [char.traits.general]: #char.traits.general
4028
  [char.traits.req]: #char.traits.req
4029
  [char.traits.require]: #char.traits.require
4030
  [char.traits.specializations]: #char.traits.specializations
4031
  [char.traits.specializations.char]: #char.traits.specializations.char
4032
  [char.traits.specializations.char16.t]: #char.traits.specializations.char16.t
4033
  [char.traits.specializations.char32.t]: #char.traits.specializations.char32.t
4034
  [char.traits.specializations.char8.t]: #char.traits.specializations.char8.t
4035
+ [char.traits.specializations.general]: #char.traits.specializations.general
4036
  [char.traits.specializations.wchar.t]: #char.traits.specializations.wchar.t
4037
  [char.traits.typedefs]: #char.traits.typedefs
4038
+ [cmp.categories]: support.md#cmp.categories
4039
+ [container.reqmts]: containers.md#container.reqmts
4040
  [container.requirements]: containers.md#container.requirements
4041
  [container.requirements.general]: containers.md#container.requirements.general
 
4042
  [cpp17.copyassignable]: #cpp17.copyassignable
4043
  [cpp17.copyconstructible]: #cpp17.copyconstructible
4044
  [cpp17.defaultconstructible]: #cpp17.defaultconstructible
4045
  [cpp17.destructible]: #cpp17.destructible
4046
  [cstring.syn]: #cstring.syn
4047
  [cuchar.syn]: #cuchar.syn
4048
  [cwchar.syn]: #cwchar.syn
4049
  [cwctype.syn]: #cwctype.syn
4050
+ [defns.character.container]: intro.md#defns.character.container
4051
  [input.output]: input.md#input.output
4052
  [intro.object]: basic.md#intro.object
 
4053
  [iostream.forward]: input.md#iostream.forward
4054
  [iostreams.limits.pos]: input.md#iostreams.limits.pos
4055
  [istream.formatted.reqmts]: input.md#istream.formatted.reqmts
4056
  [istream.unformatted]: input.md#istream.unformatted
4057
  [iterator.concept.contiguous]: iterators.md#iterator.concept.contiguous
4058
+ [iterator.concept.winc]: iterators.md#iterator.concept.winc
4059
  [iterator.range]: iterators.md#iterator.range
4060
  [iterator.requirements.general]: iterators.md#iterator.requirements.general
4061
  [library.c]: library.md#library.c
4062
  [ostream.formatted.reqmts]: input.md#ostream.formatted.reqmts
4063
  [random.access.iterators]: iterators.md#random.access.iterators
4064
  [res.on.data.races]: library.md#res.on.data.races
4065
+ [sequence.reqmts]: containers.md#sequence.reqmts
4066
  [string.access]: #string.access
4067
  [string.accessors]: #string.accessors
4068
  [string.append]: #string.append
4069
  [string.assign]: #string.assign
4070
  [string.capacity]: #string.capacity
4071
  [string.classes]: #string.classes
4072
+ [string.classes.general]: #string.classes.general
4073
  [string.cmp]: #string.cmp
4074
  [string.compare]: #string.compare
4075
  [string.cons]: #string.cons
4076
+ [string.contains]: #string.contains
4077
  [string.conversions]: #string.conversions
4078
  [string.copy]: #string.copy
4079
  [string.ends.with]: #string.ends.with
4080
  [string.erase]: #string.erase
4081
  [string.erasure]: #string.erasure
 
4102
  [string.view.comparison]: #string.view.comparison
4103
  [string.view.comparison.overloads]: #string.view.comparison.overloads
4104
  [string.view.cons]: #string.view.cons
4105
  [string.view.deduct]: #string.view.deduct
4106
  [string.view.find]: #string.view.find
4107
+ [string.view.general]: #string.view.general
4108
  [string.view.hash]: #string.view.hash
4109
  [string.view.io]: #string.view.io
4110
  [string.view.iterators]: #string.view.iterators
4111
  [string.view.literals]: #string.view.literals
4112
  [string.view.modifiers]: #string.view.modifiers
4113
  [string.view.ops]: #string.view.ops
4114
  [string.view.synop]: #string.view.synop
4115
  [string.view.template]: #string.view.template
4116
+ [string.view.template.general]: #string.view.template.general
4117
  [strings]: #strings
4118
  [strings.general]: #strings.general
4119
  [strings.summary]: #strings.summary
4120
  [support.signal]: support.md#support.signal
4121
+ [temp.deduct]: temp.md#temp.deduct
4122
+ [term.standard.layout.type]: basic.md#term.standard.layout.type
4123
+ [term.trivially.copyable.type]: basic.md#term.trivially.copyable.type
4124
  [unord.hash]: utilities.md#unord.hash
4125
  [utility.swap]: utilities.md#utility.swap
4126
 
4127
  [^1]: If `eof()` can be held in `char_type` then some iostreams
4128
  operations can give surprising results.
4129
 
4130
+ [^2]: Because `basic_string_view` refers to a constant sequence,
4131
+ `iterator` and `const_iterator` are the same type.
4132
+
4133
+ [^3]: For example, as an argument to non-member functions `swap()`
4134
  [[string.special]], `operator>{}>()` [[string.io]], and `getline()`
4135
  [[string.io]], or as an argument to `basic_string::swap()`.