From Jason Turner

[basic.string]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpp8m1gihc/{from.md → to.md} +47 -40
tmp/tmpp8m1gihc/{from.md → to.md} RENAMED
@@ -25,14 +25,14 @@ namespace std {
25
  public:
26
  // types
27
  using traits_type = traits;
28
  using value_type = charT;
29
  using allocator_type = Allocator;
30
- using size_type = typename allocator_traits<Allocator>::size_type;
31
- using difference_type = typename allocator_traits<Allocator>::difference_type;
32
- using pointer = typename allocator_traits<Allocator>::pointer;
33
- using const_pointer = typename allocator_traits<Allocator>::const_pointer;
34
  using reference = value_type&;
35
  using const_reference = const value_type&;
36
 
37
  using iterator = implementation-defined // type of basic_string::iterator; // see [container.requirements]
38
  using const_iterator = implementation-defined // type of basic_string::const_iterator; // see [container.requirements]
@@ -108,11 +108,11 @@ namespace std {
108
  template<class Operation> constexpr void resize_and_overwrite(size_type n, Operation op);
109
  constexpr size_type capacity() const noexcept;
110
  constexpr void reserve(size_type res_arg);
111
  constexpr void shrink_to_fit();
112
  constexpr void clear() noexcept;
113
- [[nodiscard]] constexpr bool empty() const noexcept;
114
 
115
  // [string.access], element access
116
  constexpr const_reference operator[](size_type pos) const;
117
  constexpr reference operator[](size_type pos);
118
  constexpr const_reference at(size_type n) const;
@@ -274,10 +274,12 @@ namespace std {
274
  constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
275
  constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
276
 
277
  constexpr basic_string substr(size_type pos = 0, size_type n = npos) const &;
278
  constexpr basic_string substr(size_type pos = 0, size_type n = npos) &&;
 
 
279
 
280
  template<class T>
281
  constexpr int compare(const T& t) const noexcept(see below);
282
  template<class T>
283
  constexpr int compare(size_type pos1, size_type n1, const T& t) const;
@@ -347,24 +349,23 @@ operation throws an exception object of type `length_error`.
347
 
348
  If any member function or operator of `basic_string` throws an
349
  exception, that function or operator has no other effect on the
350
  `basic_string` object.
351
 
352
- In every specialization `basic_string<charT, traits, Allocator>`, the
353
- type `allocator_traits<Allocator>::value_type` shall name the same type
354
- as `charT`. Every object of type
355
- `basic_string<charT, traits, Allocator>` uses an object of type
356
- `Allocator` to allocate and free storage for the contained `charT`
357
- objects as needed. The `Allocator` object used is obtained as described
358
- in [[container.requirements.general]]. In every specialization
359
  `basic_string<charT, traits, Allocator>`, the type `traits` shall meet
360
  the character traits requirements [[char.traits]].
361
 
362
  [*Note 1*: Every specialization
363
- `basic_string<charT, traits, Allocator>` is an allocator-aware
364
- container, but does not use the allocator’s `construct` and `destroy`
365
- member functions [[container.requirements.general]]. — *end note*]
 
 
366
 
367
  [*Note 2*: The program is ill-formed if `traits::char_type` is not the
368
  same type as `charT`. — *end note*]
369
 
370
  References, pointers, and iterators referring to the elements of a
@@ -470,11 +471,11 @@ is equal to `0`.
470
  ``` cpp
471
  constexpr basic_string(const charT* s, const Allocator& a = Allocator());
472
  ```
473
 
474
  *Constraints:* `Allocator` is a type that qualifies as an
475
- allocator [[container.requirements.general]].
476
 
477
  [*Note 1*: This affects class template argument
478
  deduction. — *end note*]
479
 
480
  *Effects:* Equivalent to: `basic_string(s, traits::length(s), a)`.
@@ -482,11 +483,11 @@ deduction. — *end note*]
482
  ``` cpp
483
  constexpr basic_string(size_type n, charT c, const Allocator& a = Allocator());
484
  ```
485
 
486
  *Constraints:* `Allocator` is a type that qualifies as an
487
- allocator [[container.requirements.general]].
488
 
489
  [*Note 2*: This affects class template argument
490
  deduction. — *end note*]
491
 
492
  *Effects:* Constructs an object whose value consists of `n` copies of
@@ -496,11 +497,11 @@ deduction. — *end note*]
496
  template<class InputIterator>
497
  constexpr basic_string(InputIterator begin, InputIterator end, const Allocator& a = Allocator());
498
  ```
499
 
500
  *Constraints:* `InputIterator` is a type that qualifies as an input
501
- iterator [[container.requirements.general]].
502
 
503
  *Effects:* Constructs a string from the values in the range \[`begin`,
504
  `end`), as specified in [[sequence.reqmts]].
505
 
506
  ``` cpp
@@ -538,11 +539,11 @@ template<class InputIterator,
538
  Allocator>;
539
  ```
540
 
541
  *Constraints:* `InputIterator` is a type that qualifies as an input
542
  iterator, and `Allocator` is a type that qualifies as an
543
- allocator [[container.requirements.general]].
544
 
545
  ``` cpp
546
  template<class charT,
547
  class traits,
548
  class Allocator = allocator<charT>>
@@ -557,11 +558,11 @@ template<class charT,
557
  const Allocator& = Allocator())
558
  -> basic_string<charT, traits, Allocator>;
559
  ```
560
 
561
  *Constraints:* `Allocator` is a type that qualifies as an
562
- allocator [[container.requirements.general]].
563
 
564
  ``` cpp
565
  constexpr basic_string& operator=(const basic_string& str);
566
  ```
567
 
@@ -574,13 +575,12 @@ Otherwise, replaces the value of `*this` with a copy of `str`.
574
  constexpr basic_string& operator=(basic_string&& str)
575
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
576
  allocator_traits<Allocator>::is_always_equal::value);
577
  ```
578
 
579
- *Effects:* Move assigns as a sequence
580
- container [[container.requirements]], except that iterators, pointers
581
- and references may be invalidated.
582
 
583
  *Returns:* `*this`.
584
 
585
  ``` cpp
586
  template<class T>
@@ -746,14 +746,14 @@ constexpr size_type capacity() const noexcept;
746
  constexpr void reserve(size_type res_arg);
747
  ```
748
 
749
  *Effects:* A directive that informs a `basic_string` of a planned change
750
  in size, so that the storage allocation can be managed accordingly.
751
- After `reserve()`, `capacity()` is greater or equal to the argument of
752
- `reserve` if reallocation happens; and equal to the previous value of
753
- `capacity()` otherwise. Reallocation happens at this point if and only
754
- if the current capacity is less than the argument of `reserve()`.
755
 
756
  *Throws:* `length_error` if `res_arg > max_size()` or any exceptions
757
  thrown by `allocator_traits` `<Allocator>::allocate`.
758
 
759
  ``` cpp
@@ -784,11 +784,11 @@ constexpr void clear() noexcept;
784
  ```
785
 
786
  *Effects:* Equivalent to: `erase(begin(), end());`
787
 
788
  ``` cpp
789
- [[nodiscard]] constexpr bool empty() const noexcept;
790
  ```
791
 
792
  *Effects:* Equivalent to: `return size() == 0;`
793
 
794
  #### Element access <a id="string.access">[[string.access]]</a>
@@ -796,11 +796,11 @@ constexpr void clear() noexcept;
796
  ``` cpp
797
  constexpr const_reference operator[](size_type pos) const;
798
  constexpr reference operator[](size_type pos);
799
  ```
800
 
801
- *Preconditions:* `pos <= size()`.
802
 
803
  *Returns:* `*(begin() + pos)` if `pos < size()`. Otherwise, returns a
804
  reference to an object of type `charT` with value `charT()`, where
805
  modifying the object to any value other than `charT()` leads to
806
  undefined behavior.
@@ -821,20 +821,20 @@ constexpr reference at(size_type pos);
821
  ``` cpp
822
  constexpr const charT& front() const;
823
  constexpr charT& front();
824
  ```
825
 
826
- *Preconditions:* `!empty()`.
827
 
828
  *Effects:* Equivalent to: `return operator[](0);`
829
 
830
  ``` cpp
831
  constexpr const charT& back() const;
832
  constexpr charT& back();
833
  ```
834
 
835
- *Preconditions:* `!empty()`.
836
 
837
  *Effects:* Equivalent to: `return operator[](size() - 1);`
838
 
839
  #### Modifiers <a id="string.modifiers">[[string.modifiers]]</a>
840
 
@@ -964,11 +964,11 @@ constexpr basic_string& append(size_type n, charT c);
964
  template<class InputIterator>
965
  constexpr basic_string& append(InputIterator first, InputIterator last);
966
  ```
967
 
968
  *Constraints:* `InputIterator` is a type that qualifies as an input
969
- iterator [[container.requirements.general]].
970
 
971
  *Effects:* Equivalent to:
972
  `return append(basic_string(first, last, get_allocator()));`
973
 
974
  ``` cpp
@@ -1092,11 +1092,11 @@ return *this;
1092
  template<class InputIterator>
1093
  constexpr basic_string& assign(InputIterator first, InputIterator last);
1094
  ```
1095
 
1096
  *Constraints:* `InputIterator` is a type that qualifies as an input
1097
- iterator [[container.requirements.general]].
1098
 
1099
  *Effects:* Equivalent to:
1100
  `return assign(basic_string(first, last, get_allocator()));`
1101
 
1102
  ``` cpp
@@ -1192,11 +1192,11 @@ constexpr basic_string& insert(size_type pos, size_type n, charT c);
1192
  ```
1193
 
1194
  *Effects:* Inserts `n` copies of `c` before the character at position
1195
  `pos` if `pos < size()`, or otherwise at the end of the string.
1196
 
1197
- *Returns:* `*this`
1198
 
1199
  *Throws:*
1200
 
1201
  - `out_of_range` if `pos > size()`,
1202
  - `length_error` if `n > max_size() - size()`, or
@@ -1227,11 +1227,11 @@ constexpr iterator insert(const_iterator p, size_type n, charT c);
1227
  template<class InputIterator>
1228
  constexpr iterator insert(const_iterator p, InputIterator first, InputIterator last);
1229
  ```
1230
 
1231
  *Constraints:* `InputIterator` is a type that qualifies as an input
1232
- iterator [[container.requirements.general]].
1233
 
1234
  *Preconditions:* `p` is a valid iterator on `*this`.
1235
 
1236
  *Effects:* Equivalent to
1237
  `insert(p - begin(), basic_string(first, last, get_allocator()))`.
@@ -1291,11 +1291,11 @@ constexpr iterator erase(const_iterator first, const_iterator last);
1291
  ```
1292
 
1293
  *Preconditions:* `first` and `last` are valid iterators on `*this`.
1294
  \[`first`, `last`) is a valid range.
1295
 
1296
- *Effects:* Removes the characters in the range `[first, last)`.
1297
 
1298
  *Returns:* An iterator which points to the element pointed to by `last`
1299
  prior to the other elements being erased. If no such element exists,
1300
  `end()` is returned.
1301
 
@@ -1303,11 +1303,11 @@ prior to the other elements being erased. If no such element exists,
1303
 
1304
  ``` cpp
1305
  constexpr void pop_back();
1306
  ```
1307
 
1308
- *Preconditions:* `!empty()`.
1309
 
1310
  *Effects:* Equivalent to `erase(end() - 1)`.
1311
 
1312
  *Throws:* Nothing.
1313
 
@@ -1409,12 +1409,12 @@ the function replaces the characters in the range \[`begin() + pos1`,
1409
  *Returns:* `*this`.
1410
 
1411
  *Throws:*
1412
 
1413
  - `out_of_range` if `pos1 > size()`,
1414
- - `length_error` if the length of the resulting string would
1415
- exceed`max_size()`, or
1416
  - any exceptions thrown by `allocator_traits<Allocator>::allocate.`
1417
 
1418
  ``` cpp
1419
  constexpr basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
1420
  ```
@@ -1469,11 +1469,11 @@ template<class InputIterator>
1469
  constexpr basic_string& replace(const_iterator i1, const_iterator i2,
1470
  InputIterator j1, InputIterator j2);
1471
  ```
1472
 
1473
  *Constraints:* `InputIterator` is a type that qualifies as an input
1474
- iterator [[container.requirements.general]].
1475
 
1476
  *Effects:* Equivalent to:
1477
  `return replace(i1, i2, basic_string(j1, j2, get_allocator()));`
1478
 
1479
  ``` cpp
@@ -1649,10 +1649,17 @@ constexpr basic_string substr(size_type pos = 0, size_type n = npos) &&;
1649
  ```
1650
 
1651
  *Effects:* Equivalent to:
1652
  `return basic_string(std::move(*this), pos, n);`
1653
 
 
 
 
 
 
 
 
1654
  ##### `basic_string::compare` <a id="string.compare">[[string.compare]]</a>
1655
 
1656
  ``` cpp
1657
  template<class T>
1658
  constexpr int compare(const T& t) const noexcept(see below);
 
25
  public:
26
  // types
27
  using traits_type = traits;
28
  using value_type = charT;
29
  using allocator_type = Allocator;
30
+ using size_type = allocator_traits<Allocator>::size_type;
31
+ using difference_type = allocator_traits<Allocator>::difference_type;
32
+ using pointer = allocator_traits<Allocator>::pointer;
33
+ using const_pointer = allocator_traits<Allocator>::const_pointer;
34
  using reference = value_type&;
35
  using const_reference = const value_type&;
36
 
37
  using iterator = implementation-defined // type of basic_string::iterator; // see [container.requirements]
38
  using const_iterator = implementation-defined // type of basic_string::const_iterator; // see [container.requirements]
 
108
  template<class Operation> constexpr void resize_and_overwrite(size_type n, Operation op);
109
  constexpr size_type capacity() const noexcept;
110
  constexpr void reserve(size_type res_arg);
111
  constexpr void shrink_to_fit();
112
  constexpr void clear() noexcept;
113
+ constexpr bool empty() const noexcept;
114
 
115
  // [string.access], element access
116
  constexpr const_reference operator[](size_type pos) const;
117
  constexpr reference operator[](size_type pos);
118
  constexpr const_reference at(size_type n) const;
 
274
  constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
275
  constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
276
 
277
  constexpr basic_string substr(size_type pos = 0, size_type n = npos) const &;
278
  constexpr basic_string substr(size_type pos = 0, size_type n = npos) &&;
279
+ constexpr basic_string_view<charT, traits> subview(size_type pos = 0,
280
+ size_type n = npos) const;
281
 
282
  template<class T>
283
  constexpr int compare(const T& t) const noexcept(see below);
284
  template<class T>
285
  constexpr int compare(size_type pos1, size_type n1, const T& t) const;
 
349
 
350
  If any member function or operator of `basic_string` throws an
351
  exception, that function or operator has no other effect on the
352
  `basic_string` object.
353
 
354
+ Every object of type `basic_string<charT, traits, Allocator>` uses an
355
+ object of type `Allocator` to allocate and free storage for the
356
+ contained `charT` objects as needed. The `Allocator` object used is
357
+ obtained as described in [[container.reqmts]]. In every specialization
 
 
 
358
  `basic_string<charT, traits, Allocator>`, the type `traits` shall meet
359
  the character traits requirements [[char.traits]].
360
 
361
  [*Note 1*: Every specialization
362
+ `basic_string<charT, traits, Allocator>` is an allocator-aware container
363
+ [[container.alloc.reqmts]], but does not use the allocator’s `construct`
364
+ and `destroy` member functions [[container.requirements.pre]]. The
365
+ program is ill-formed if `Allocator::value_type` is not the same type as
366
+ `charT`. — *end note*]
367
 
368
  [*Note 2*: The program is ill-formed if `traits::char_type` is not the
369
  same type as `charT`. — *end note*]
370
 
371
  References, pointers, and iterators referring to the elements of a
 
471
  ``` cpp
472
  constexpr basic_string(const charT* s, const Allocator& a = Allocator());
473
  ```
474
 
475
  *Constraints:* `Allocator` is a type that qualifies as an
476
+ allocator [[container.reqmts]].
477
 
478
  [*Note 1*: This affects class template argument
479
  deduction. — *end note*]
480
 
481
  *Effects:* Equivalent to: `basic_string(s, traits::length(s), a)`.
 
483
  ``` cpp
484
  constexpr basic_string(size_type n, charT c, const Allocator& a = Allocator());
485
  ```
486
 
487
  *Constraints:* `Allocator` is a type that qualifies as an
488
+ allocator [[container.reqmts]].
489
 
490
  [*Note 2*: This affects class template argument
491
  deduction. — *end note*]
492
 
493
  *Effects:* Constructs an object whose value consists of `n` copies of
 
497
  template<class InputIterator>
498
  constexpr basic_string(InputIterator begin, InputIterator end, const Allocator& a = Allocator());
499
  ```
500
 
501
  *Constraints:* `InputIterator` is a type that qualifies as an input
502
+ iterator [[container.reqmts]].
503
 
504
  *Effects:* Constructs a string from the values in the range \[`begin`,
505
  `end`), as specified in [[sequence.reqmts]].
506
 
507
  ``` cpp
 
539
  Allocator>;
540
  ```
541
 
542
  *Constraints:* `InputIterator` is a type that qualifies as an input
543
  iterator, and `Allocator` is a type that qualifies as an
544
+ allocator [[container.reqmts]].
545
 
546
  ``` cpp
547
  template<class charT,
548
  class traits,
549
  class Allocator = allocator<charT>>
 
558
  const Allocator& = Allocator())
559
  -> basic_string<charT, traits, Allocator>;
560
  ```
561
 
562
  *Constraints:* `Allocator` is a type that qualifies as an
563
+ allocator [[container.reqmts]].
564
 
565
  ``` cpp
566
  constexpr basic_string& operator=(const basic_string& str);
567
  ```
568
 
 
575
  constexpr basic_string& operator=(basic_string&& str)
576
  noexcept(allocator_traits<Allocator>::propagate_on_container_move_assignment::value ||
577
  allocator_traits<Allocator>::is_always_equal::value);
578
  ```
579
 
580
+ *Effects:* Move assigns as a sequence container [[sequence.reqmts]],
581
+ except that iterators, pointers and references may be invalidated.
 
582
 
583
  *Returns:* `*this`.
584
 
585
  ``` cpp
586
  template<class T>
 
746
  constexpr void reserve(size_type res_arg);
747
  ```
748
 
749
  *Effects:* A directive that informs a `basic_string` of a planned change
750
  in size, so that the storage allocation can be managed accordingly.
751
+ Following a call to `reserve`, `capacity()` is greater or equal to the
752
+ argument of `reserve` if reallocation happens; and equal to the previous
753
+ value of `capacity()` otherwise. Reallocation happens at this point if
754
+ and only if the current capacity is less than the argument of `reserve`.
755
 
756
  *Throws:* `length_error` if `res_arg > max_size()` or any exceptions
757
  thrown by `allocator_traits` `<Allocator>::allocate`.
758
 
759
  ``` cpp
 
784
  ```
785
 
786
  *Effects:* Equivalent to: `erase(begin(), end());`
787
 
788
  ``` cpp
789
+ constexpr bool empty() const noexcept;
790
  ```
791
 
792
  *Effects:* Equivalent to: `return size() == 0;`
793
 
794
  #### Element access <a id="string.access">[[string.access]]</a>
 
796
  ``` cpp
797
  constexpr const_reference operator[](size_type pos) const;
798
  constexpr reference operator[](size_type pos);
799
  ```
800
 
801
+ `pos <= size()` is `true`.
802
 
803
  *Returns:* `*(begin() + pos)` if `pos < size()`. Otherwise, returns a
804
  reference to an object of type `charT` with value `charT()`, where
805
  modifying the object to any value other than `charT()` leads to
806
  undefined behavior.
 
821
  ``` cpp
822
  constexpr const charT& front() const;
823
  constexpr charT& front();
824
  ```
825
 
826
+ `empty()` is `false`.
827
 
828
  *Effects:* Equivalent to: `return operator[](0);`
829
 
830
  ``` cpp
831
  constexpr const charT& back() const;
832
  constexpr charT& back();
833
  ```
834
 
835
+ `empty()` is `false`.
836
 
837
  *Effects:* Equivalent to: `return operator[](size() - 1);`
838
 
839
  #### Modifiers <a id="string.modifiers">[[string.modifiers]]</a>
840
 
 
964
  template<class InputIterator>
965
  constexpr basic_string& append(InputIterator first, InputIterator last);
966
  ```
967
 
968
  *Constraints:* `InputIterator` is a type that qualifies as an input
969
+ iterator [[container.reqmts]].
970
 
971
  *Effects:* Equivalent to:
972
  `return append(basic_string(first, last, get_allocator()));`
973
 
974
  ``` cpp
 
1092
  template<class InputIterator>
1093
  constexpr basic_string& assign(InputIterator first, InputIterator last);
1094
  ```
1095
 
1096
  *Constraints:* `InputIterator` is a type that qualifies as an input
1097
+ iterator [[container.reqmts]].
1098
 
1099
  *Effects:* Equivalent to:
1100
  `return assign(basic_string(first, last, get_allocator()));`
1101
 
1102
  ``` cpp
 
1192
  ```
1193
 
1194
  *Effects:* Inserts `n` copies of `c` before the character at position
1195
  `pos` if `pos < size()`, or otherwise at the end of the string.
1196
 
1197
+ *Returns:* `*this`.
1198
 
1199
  *Throws:*
1200
 
1201
  - `out_of_range` if `pos > size()`,
1202
  - `length_error` if `n > max_size() - size()`, or
 
1227
  template<class InputIterator>
1228
  constexpr iterator insert(const_iterator p, InputIterator first, InputIterator last);
1229
  ```
1230
 
1231
  *Constraints:* `InputIterator` is a type that qualifies as an input
1232
+ iterator [[container.reqmts]].
1233
 
1234
  *Preconditions:* `p` is a valid iterator on `*this`.
1235
 
1236
  *Effects:* Equivalent to
1237
  `insert(p - begin(), basic_string(first, last, get_allocator()))`.
 
1291
  ```
1292
 
1293
  *Preconditions:* `first` and `last` are valid iterators on `*this`.
1294
  \[`first`, `last`) is a valid range.
1295
 
1296
+ *Effects:* Removes the characters in the range \[`first`, `last`).
1297
 
1298
  *Returns:* An iterator which points to the element pointed to by `last`
1299
  prior to the other elements being erased. If no such element exists,
1300
  `end()` is returned.
1301
 
 
1303
 
1304
  ``` cpp
1305
  constexpr void pop_back();
1306
  ```
1307
 
1308
+ `empty()` is `false`.
1309
 
1310
  *Effects:* Equivalent to `erase(end() - 1)`.
1311
 
1312
  *Throws:* Nothing.
1313
 
 
1409
  *Returns:* `*this`.
1410
 
1411
  *Throws:*
1412
 
1413
  - `out_of_range` if `pos1 > size()`,
1414
+ - `length_error` if the length of the resulting string would exceed
1415
+ `max_size()`, or
1416
  - any exceptions thrown by `allocator_traits<Allocator>::allocate.`
1417
 
1418
  ``` cpp
1419
  constexpr basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
1420
  ```
 
1469
  constexpr basic_string& replace(const_iterator i1, const_iterator i2,
1470
  InputIterator j1, InputIterator j2);
1471
  ```
1472
 
1473
  *Constraints:* `InputIterator` is a type that qualifies as an input
1474
+ iterator [[container.reqmts]].
1475
 
1476
  *Effects:* Equivalent to:
1477
  `return replace(i1, i2, basic_string(j1, j2, get_allocator()));`
1478
 
1479
  ``` cpp
 
1649
  ```
1650
 
1651
  *Effects:* Equivalent to:
1652
  `return basic_string(std::move(*this), pos, n);`
1653
 
1654
+ ``` cpp
1655
+ constexpr basic_string_view<charT, traits> subview(size_type pos = 0, size_type n = npos) const;
1656
+ ```
1657
+
1658
+ *Effects:* Equivalent to:
1659
+ `return basic_string_view<charT, traits>(*this).subview(pos, n);`
1660
+
1661
  ##### `basic_string::compare` <a id="string.compare">[[string.compare]]</a>
1662
 
1663
  ``` cpp
1664
  template<class T>
1665
  constexpr int compare(const T& t) const noexcept(see below);