From Jason Turner

[string.replace]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpqwc1vwlv/{from.md → to.md} +86 -93
tmp/tmpqwc1vwlv/{from.md → to.md} RENAMED
@@ -1,179 +1,172 @@
1
  ##### `basic_string::replace` <a id="string.replace">[[string.replace]]</a>
2
 
3
  ``` cpp
4
- basic_string&
5
- replace(size_type pos1, size_type n1,
6
- const basic_string& str);
7
  ```
8
 
9
  *Effects:* Equivalent to:
10
  `return replace(pos1, n1, str.data(), str.size());`
11
 
12
  ``` cpp
13
- basic_string&
14
- replace(size_type pos1, size_type n1,
15
- const basic_string& str,
16
  size_type pos2, size_type n2 = npos);
17
  ```
18
 
19
- *Throws:* `out_of_range` if `pos1 > size()` or `pos2 > str.size()`.
20
-
21
- *Effects:* Determines the effective length `rlen` of the string to be
22
- inserted as the smaller of `n2` and `str.size() - pos2` and calls
23
- `replace(pos1, n1, str.data() + pos2, rlen)`.
24
 
25
- *Returns:* `*this`.
 
 
26
 
27
  ``` cpp
28
- basic_string& replace(size_type pos1, size_type n1,
29
- basic_string_view<charT, traits> sv);
30
  ```
31
 
 
 
 
 
 
 
32
  *Effects:* Equivalent to:
33
- `return replace(pos1, n1, sv.data(), sv.size());`
 
 
 
 
34
 
35
  ``` cpp
36
  template<class T>
37
- basic_string& replace(size_type pos1, size_type n1, const T& t,
38
  size_type pos2, size_type n2 = npos);
39
  ```
40
 
41
- *Throws:* `out_of_range` if `pos1 > size()` or `pos2 > sv.size()`.
42
 
43
- *Effects:* Creates a variable, `sv`, as if by
44
- `basic_string_view<charT, traits> sv = t`. Determines the effective
45
- length `rlen` of the string to be inserted as the smaller of `n2` and
46
- `sv.size() - pos2` and calls
47
- `replace(pos1, n1, sv.data() + pos2, rlen)`.
48
 
49
- *Remarks:* This function shall not participate in overload resolution
50
- unless `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
51
- `true` and `is_convertible_v<const T&, const charT*>` is `false`.
52
 
53
- *Returns:* `*this`.
 
 
 
54
 
55
  ``` cpp
56
- basic_string&
57
- replace(size_type pos1, size_type n1, const charT* s, size_type n2);
58
  ```
59
 
60
- *Requires:* `s` points to an array of at least `n2` elements of `charT`.
 
 
61
 
62
- *Throws:* `out_of_range` if `pos1 > size()` or `length_error` if the
63
- length of the resulting string would exceed `max_size()` (see below).
 
 
64
 
65
  *Effects:* Determines the effective length `xlen` of the string to be
66
  removed as the smaller of `n1` and `size() - pos1`. If
67
  `size() - xlen >= max_size() - n2` throws `length_error`. Otherwise, the
68
- function replaces the string controlled by \*`this` with a string of
69
- length `size() - xlen + n2` whose first `pos1` elements are a copy of
70
- the initial elements of the original string controlled by `*this`, whose
71
- next `n2` elements are a copy of the initial `n2` elements of `s`, and
72
- whose remaining elements are a copy of the elements of the original
73
- string controlled by `*this` beginning at position `pos + xlen`.
74
 
75
  *Returns:* `*this`.
76
 
77
  ``` cpp
78
- basic_string&
79
- replace(size_type pos, size_type n, const charT* s);
80
  ```
81
 
82
- *Requires:* `s` points to an array of at least `traits::length(s) + 1`
83
- elements of `charT`.
84
-
85
  *Effects:* Equivalent to:
86
  `return replace(pos, n, s, traits::length(s));`
87
 
88
  ``` cpp
89
- basic_string&
90
- replace(size_type pos1, size_type n1,
91
- size_type n2, charT c);
92
  ```
93
 
94
- *Effects:* Equivalent to `replace(pos1, n1, basic_string(n2, c))`.
 
 
 
 
 
 
 
 
 
 
 
95
 
96
  *Returns:* `*this`.
97
 
98
  ``` cpp
99
- basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
100
  ```
101
 
102
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
103
-
104
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, str)`.
105
-
106
- *Returns:* `*this`.
107
 
108
  ``` cpp
109
- basic_string& replace(const_iterator i1, const_iterator i2,
110
- basic_string_view<charT, traits> sv);
111
  ```
112
 
113
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
114
 
115
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, sv)`.
 
 
116
 
117
- *Returns:* `*this`.
 
 
118
 
119
  ``` cpp
120
- basic_string&
121
- replace(const_iterator i1, const_iterator i2, const charT* s, size_type n);
122
  ```
123
 
124
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges and
125
- `s` points to an array of at least `n` elements of `charT`.
126
-
127
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, s, n)`.
128
-
129
- *Returns:* `*this`.
130
-
131
  ``` cpp
132
- basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
133
  ```
134
 
135
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges and
136
- `s` points to an array of at least `traits::length(s) + 1` elements of
137
- `charT`.
138
 
139
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, s, traits::length(s))`.
 
 
140
 
141
- *Returns:* `*this`.
 
142
 
143
  ``` cpp
144
- basic_string& replace(const_iterator i1, const_iterator i2, size_type n,
145
- charT c);
146
  ```
147
 
148
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
149
 
150
- *Effects:* Calls `replace(i1 - begin(), i2 - i1, basic_string(n, c))`.
151
-
152
- *Returns:* `*this`.
153
 
154
  ``` cpp
155
  template<class InputIterator>
156
- basic_string& replace(const_iterator i1, const_iterator i2,
157
  InputIterator j1, InputIterator j2);
158
  ```
159
 
160
- *Requires:* \[`begin()`, `i1`), \[`i1`, `i2`) and \[`j1`, `j2`) are
161
- valid ranges.
162
 
163
- *Effects:* Calls
164
- `replace(i1 - begin(), i2 - i1, basic_string(j1, j2, get_allocator()))`.
165
-
166
- *Returns:* `*this`.
167
 
168
  ``` cpp
169
- basic_string& replace(const_iterator i1, const_iterator i2,
170
- initializer_list<charT> il);
171
  ```
172
 
173
- *Requires:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
174
-
175
- *Effects:* Calls
176
- `replace(i1 - begin(), i2 - i1, il.begin(), il.size())`.
177
-
178
- *Returns:* `*this`.
179
 
 
1
  ##### `basic_string::replace` <a id="string.replace">[[string.replace]]</a>
2
 
3
  ``` cpp
4
+ constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
 
 
5
  ```
6
 
7
  *Effects:* Equivalent to:
8
  `return replace(pos1, n1, str.data(), str.size());`
9
 
10
  ``` cpp
11
+ constexpr basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
 
 
12
  size_type pos2, size_type n2 = npos);
13
  ```
14
 
15
+ *Effects:* Equivalent to:
 
 
 
 
16
 
17
+ ``` cpp
18
+ return replace(pos1, n1, basic_string_view<charT, traits>(str).substr(pos2, n2));
19
+ ```
20
 
21
  ``` cpp
22
+ template<class T>
23
+ constexpr basic_string& replace(size_type pos1, size_type n1, const T& t);
24
  ```
25
 
26
+ *Constraints:*
27
+
28
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
29
+ `true` and
30
+ - `is_convertible_v<const T&, const charT*>` is `false`.
31
+
32
  *Effects:* Equivalent to:
33
+
34
+ ``` cpp
35
+ basic_string_view<charT, traits> sv = t;
36
+ return replace(pos1, n1, sv.data(), sv.size());
37
+ ```
38
 
39
  ``` cpp
40
  template<class T>
41
+ constexpr basic_string& replace(size_type pos1, size_type n1, const T& t,
42
  size_type pos2, size_type n2 = npos);
43
  ```
44
 
45
+ *Constraints:*
46
 
47
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
48
+ `true` and
49
+ - `is_convertible_v<const T&, const charT*>` is `false`.
 
 
50
 
51
+ *Effects:* Equivalent to:
 
 
52
 
53
+ ``` cpp
54
+ basic_string_view<charT, traits> sv = t;
55
+ return replace(pos1, n1, sv.substr(pos2, n2));
56
+ ```
57
 
58
  ``` cpp
59
+ constexpr basic_string& replace(size_type pos1, size_type n1, const charT* s, size_type n2);
 
60
  ```
61
 
62
+ *Preconditions:* \[`s`, `s + n2`) is a valid range.
63
+
64
+ *Throws:*
65
 
66
+ - `out_of_range` if `pos1 > size()`,
67
+ - `length_error` if the length of the resulting string would exceed
68
+ `max_size()` (see below), or
69
+ - any exceptions thrown by `allocator_traits<Allocator>::allocate`.
70
 
71
  *Effects:* Determines the effective length `xlen` of the string to be
72
  removed as the smaller of `n1` and `size() - pos1`. If
73
  `size() - xlen >= max_size() - n2` throws `length_error`. Otherwise, the
74
+ function replaces the characters in the range \[`begin() + pos1`,
75
+ `begin() + pos1 + xlen`) with a copy of the range \[`s`, `s + n2`).
 
 
 
 
76
 
77
  *Returns:* `*this`.
78
 
79
  ``` cpp
80
+ constexpr basic_string& replace(size_type pos, size_type n, const charT* s);
 
81
  ```
82
 
 
 
 
83
  *Effects:* Equivalent to:
84
  `return replace(pos, n, s, traits::length(s));`
85
 
86
  ``` cpp
87
+ constexpr basic_string& replace(size_type pos1, size_type n1, size_type n2, charT c);
 
 
88
  ```
89
 
90
+ *Throws:*
91
+
92
+ - `out_of_range` if `pos1 > size()`,
93
+ - `length_error` if the length of the resulting string would exceed
94
+ `max_size()` (see below), or
95
+ - any exceptions thrown by `allocator_traits<Allocator>::allocate.`
96
+
97
+ *Effects:* Determines the effective length `xlen` of the string to be
98
+ removed as the smaller of `n1` and `size() - pos1`. If
99
+ `size() - xlen >=` `max_size() - n2` throws `length_error`. Otherwise,
100
+ the function replaces the characters in the range \[`begin() + pos1`,
101
+ `begin() + pos1 + xlen`) with `n2` copies of `c`.
102
 
103
  *Returns:* `*this`.
104
 
105
  ``` cpp
106
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
107
  ```
108
 
109
+ *Effects:* Equivalent to:
110
+ `return replace(i1, i2, basic_string_view<charT, traits>(str));`
 
 
 
111
 
112
  ``` cpp
113
+ template<class T>
114
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const T& t);
115
  ```
116
 
117
+ *Constraints:*
118
 
119
+ - `is_convertible_v<const T&, basic_string_view<charT, traits>>` is
120
+ `true` and
121
+ - `is_convertible_v<const T&, const charT*>` is `false`.
122
 
123
+ *Preconditions:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
124
+
125
+ *Effects:* Equivalent to:
126
 
127
  ``` cpp
128
+ basic_string_view<charT, traits> sv = t;
129
+ return replace(i1 - begin(), i2 - i1, sv.data(), sv.size());
130
  ```
131
 
 
 
 
 
 
 
 
132
  ``` cpp
133
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s, size_type n);
134
  ```
135
 
136
+ *Effects:* Equivalent to:
137
+ `return replace(i1, i2, basic_string_view<charT, traits>(s, n));`
 
138
 
139
+ ``` cpp
140
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, const charT* s);
141
+ ```
142
 
143
+ *Effects:* Equivalent to:
144
+ `return replace(i1, i2, basic_string_view<charT, traits>(s));`
145
 
146
  ``` cpp
147
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, size_type n, charT c);
 
148
  ```
149
 
150
+ *Preconditions:* \[`begin()`, `i1`) and \[`i1`, `i2`) are valid ranges.
151
 
152
+ *Effects:* Equivalent to: `return replace(i1 - begin(), i2 - i1, n, c);`
 
 
153
 
154
  ``` cpp
155
  template<class InputIterator>
156
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2,
157
  InputIterator j1, InputIterator j2);
158
  ```
159
 
160
+ *Constraints:* `InputIterator` is a type that qualifies as an input
161
+ iterator [[container.requirements.general]].
162
 
163
+ *Effects:* Equivalent to:
164
+ `return replace(i1, i2, basic_string(j1, j2, get_allocator()));`
 
 
165
 
166
  ``` cpp
167
+ constexpr basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<charT> il);
 
168
  ```
169
 
170
+ *Effects:* Equivalent to:
171
+ `return replace(i1, i2, il.begin(), il.size());`
 
 
 
 
172