forked from cplusplus/fundamentals-ts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string.view.html
696 lines (578 loc) · 35 KB
/
string.view.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
<cxx-clause id="string.view">
<h1><code>string_view</code></h1>
<p>
The class template <code>basic_string_view</code> describes an object that can refer to a constant contiguous sequence of char-like (<cxx-ref in="cxx" to="strings.general"></cxx-ref>) objects with the first element of the sequence at position zero.
In the rest of this section, the type of the char-like objects held in a <code>basic_string_view</code> object is designated by <code>charT</code>.
</p>
<p>
<cxx-note>The library provides implicit conversions from <code>const charT*</code> and <code>std::basic_string<charT, ...></code> to <code>std::basic_string_view<charT, ...></code> so that user code can accept just <code>std::basic_string_view<charT></code> as a non-templated parameter wherever a sequence of characters is expected.
User-defined types should define their own implicit conversions to <code>std::basic_string_view</code> in order to interoperate with these functions.</cxx-note>
</p>
<p>
The complexity of <code>basic_string_view</code> member functions is O(1) unless otherwise specified.
</p>
<cxx-section id="string.view.synop">
<h1>Header <code><experimental/string_view></code> synopsis</h1>
<pre><code>namespace std {
namespace experimental {
inline namespace fundamentals_v2 {
<cxx-ref insynopsis="" to="string.view.template"></cxx-ref>
template<class charT, class traits = char_traits<charT>>
class basic_string_view;
<cxx-ref insynopsis="" to="string.view.comparison"></cxx-ref>
template<class charT, class traits>
constexpr bool operator==(basic_string_view<charT, traits> x,
basic_string_view<charT, traits> y) noexcept;
template<class charT, class traits>
constexpr bool operator!=(basic_string_view<charT, traits> x,
basic_string_view<charT, traits> y) noexcept;
template<class charT, class traits>
constexpr bool operator< (basic_string_view<charT, traits> x,
basic_string_view<charT, traits> y) noexcept;
template<class charT, class traits>
constexpr bool operator> (basic_string_view<charT, traits> x,
basic_string_view<charT, traits> y) noexcept;
template<class charT, class traits>
constexpr bool operator<=(basic_string_view<charT, traits> x,
basic_string_view<charT, traits> y) noexcept;
template<class charT, class traits>
constexpr bool operator>=(basic_string_view<charT, traits> x,
basic_string_view<charT, traits> y) noexcept;
// <i>see below</i>, sufficient additional overloads of comparison functions
<cxx-ref insynopsis="" to="string.view.io"></cxx-ref>
template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
basic_string_view<charT, traits> str);
// basic_string_view typedef names
typedef basic_string_view<char> string_view;
typedef basic_string_view<char16_t> u16string_view;
typedef basic_string_view<char32_t> u32string_view;
typedef basic_string_view<wchar_t> wstring_view;
} // namespace fundamentals_v2
} // namespace experimental
<cxx-ref insynopsis="" to="string.view.hash"></cxx-ref>
template <class T> struct hash;
template <> struct hash<experimental::string_view>;
template <> struct hash<experimental::u16string_view>;
template <> struct hash<experimental::u32string_view>;
template <> struct hash<experimental::wstring_view>;
} // namespace std</code></pre>
<p>
The function templates defined in <cxx-ref in="cxx" to="utility.swap"></cxx-ref> and <cxx-ref in="cxx" to="iterator.range"></cxx-ref> are available when <code><experimental/string_view></code> is included.
</p>
</cxx-section>
<cxx-section id="string.view.template">
<h1>Class template <code>basic_string_view</code></h1>
<pre><code>template<class charT, class traits = char_traits<charT>>
class basic_string_view {
public:
// types
typedef traits traits_type;
typedef charT value_type;
typedef charT* pointer;
typedef const charT* const_pointer;
typedef charT& reference;
typedef const charT& const_reference;
typedef <var>implementation-defined</var> const_iterator; // See <cxx-ref to="string.view.iterators"></cxx-ref>
typedef const_iterator iterator;<cxx-footnote>Because <code>basic_string_view</code> refers to a constant sequence, <code>iterator</code> and <code>const_iterator</code> are the same type.</cxx-footnote>
typedef reverse_iterator<const_iterator> const_reverse_iterator;
typedef const_reverse_iterator reverse_iterator;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
static constexpr size_type npos = size_type(-1);
<cxx-ref insynopsis="" to="string.view.cons"></cxx-ref>
constexpr basic_string_view() noexcept;
constexpr basic_string_view(const basic_string_view&) noexcept = default;
basic_string_view& operator=(const basic_string_view&) noexcept = default;
template<class Allocator>
basic_string_view(const basic_string<charT, traits, Allocator>& str) noexcept;
constexpr basic_string_view(const charT* str);
constexpr basic_string_view(const charT* str, size_type len);
<cxx-ref insynopsis="" to="string.view.iterators"></cxx-ref>
constexpr const_iterator begin() const noexcept;
constexpr const_iterator end() const noexcept;
constexpr const_iterator cbegin() const noexcept;
constexpr const_iterator cend() const noexcept;
const_reverse_iterator rbegin() const noexcept;
const_reverse_iterator rend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
<cxx-ref insynopsis="" to="string.view.capacity"></cxx-ref>
constexpr size_type size() const noexcept;
constexpr size_type length() const noexcept;
constexpr size_type max_size() const noexcept;
constexpr bool empty() const noexcept;
<cxx-ref insynopsis="" to="string.view.access"></cxx-ref>
constexpr const_reference operator[](size_type pos) const;
constexpr const_reference at(size_type pos) const;
constexpr const_reference front() const;
constexpr const_reference back() const;
constexpr const_pointer data() const noexcept;
<cxx-ref insynopsis="" to="string.view.modifiers"></cxx-ref>
constexpr void remove_prefix(size_type n);
constexpr void remove_suffix(size_type n);
constexpr void swap(basic_string_view& s) noexcept;
<cxx-ref insynopsis="" to="string.view.ops"></cxx-ref>
template<class Allocator>
explicit operator basic_string<charT, traits, Allocator>() const;
template<class Allocator = allocator<charT> >
basic_string<charT, traits, Allocator> to_string(
const Allocator& a = Allocator()) const;
size_type copy(charT* s, size_type n, size_type pos = 0) const;
constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
constexpr int compare(basic_string_view s) const noexcept;
constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
constexpr int compare(size_type pos1, size_type n1,
basic_string_view s, size_type pos2, size_type n2) const;
constexpr int compare(const charT* s) const;
constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
constexpr int compare(size_type pos1, size_type n1,
const charT* s, size_type n2) const;
constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
constexpr size_type find(charT c, size_type pos = 0) const noexcept;
constexpr size_type find(const charT* s, size_type pos, size_type n) const;
constexpr size_type find(const charT* s, size_type pos = 0) const;
constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
constexpr size_type rfind(const charT* s, size_type pos = npos) const;
constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const;
constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;
constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const;
constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
private:
const_pointer data_; // <em>exposition only</em>
size_type size_; // <em>exposition only</em>
};</code></pre>
<p>
In every specialization <code>basic_string_view<charT, traits></code>, the type <code>traits</code> shall satisfy the character traits requirements (<cxx-ref in="cxx" to="char.traits"></cxx-ref>),
and the type <code>traits::char_type</code> shall name the same type as <code>charT</code>.
</p>
</cxx-section>
<cxx-section id="string.view.cons">
<h1><code>basic_string_view</code> constructors and assignment operators</h1>
<cxx-function>
<cxx-signature>constexpr basic_string_view() noexcept;</cxx-signature>
<cxx-effects>Constructs an empty <code>basic_string_view</code>.</cxx-effects>
<cxx-postconditions><code>size_ == 0</code> and <code>data_ == nullptr</code>.</cxx-postconditions>
</cxx-function>
<cxx-function>
<cxx-signature>template<class Allocator>
basic_string_view(const basic_string<charT, traits, Allocator>& str) noexcept;</cxx-signature>
<cxx-effects>Constructs a <code>basic_string_view</code>, with the postconditions in <cxx-ref to="tab:string.view.ctr.1"></cxx-ref>.</cxx-effects>
<table is="cxx-table" id="tab:string.view.ctr.1">
<caption><code>basic_string_view(const basic_string&)</code> effects</caption>
<tr><th>Element</th><th>Value</th></tr>
<tr><td><code>data_</code></td><td><code>str.data()</code></td></tr>
<tr><td><code>size_</code></td><td><code>str.size()</code></td></tr>
</table>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr basic_string_view(const charT* str);</cxx-signature>
<cxx-requires><cxx-range begin="str" end="str + traits::length(str)"></cxx-range> is a valid range.</cxx-requires>
<cxx-effects>Constructs a <code>basic_string_view</code>, with the postconditions
in <cxx-ref to="tab:string.view.ctr.2"></cxx-ref>.</cxx-effects>
<table is="cxx-table" id="tab:string.view.ctr.2"><caption><code>basic_string_view(const charT*)</code> effects</caption>
<tr><th>Element</th><th>Value</th></tr>
<tr><td><code>data_</code></td><td><code>str</code></td></tr>
<tr><td><code>size_</code></td><td><code>traits::length(str)</code></td></tr>
</table>
<cxx-complexity>O(<code>traits::length(str)</code>)</cxx-complexity>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr basic_string_view(const charT* str, size_type len);</cxx-signature>
<cxx-requires><cxx-range begin="str" end="str + len"></cxx-range> is a valid range.</cxx-requires>
<cxx-effects>Constructs a <code>basic_string_view</code>, with the postconditions in <cxx-ref to="tab:string.view.ctr.3"></cxx-ref>.</cxx-effects>
<table is="cxx-table" id="tab:string.view.ctr.3"><caption><code>basic_string_view(const charT*, size_type)</code> effects</caption>
<tr><th>Element</th><th>Value</th></tr>
<tr><td><code>data_</code></td><td><code>str</code></td></tr>
<tr><td><code>size_</code></td><td><code>len</code></td></tr>
</table>
</cxx-function>
</cxx-section>
<cxx-section id="string.view.iterators">
<h1><code>basic_string_view</code> iterator support</h1>
<cxx-function>
<cxx-signature>typedef <var>implementation-defined</var> const_iterator;</cxx-signature>
<p>
A constant random-access iterator type such that, for a <code>const_iterator it</code>, if <code>&*(it+N)</code> is valid, then it is equal to <code>(&*it)+N</code>.
</p>
<p>
For a <code>basic_string_view str</code>, any operation that invalidates a pointer in the range <cxx-range begin="str.data()" end="str.data()+str.size()"></cxx-range> invalidates pointers, iterators, and references returned from <code>str</code>'s methods.
</p>
<p>
All requirements on container iterators (<cxx-ref in="cxx" to="container.requirements"></cxx-ref>) apply to <code>basic_string_view::const_iterator</code> as well.
</p>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr const_iterator begin() const noexcept;</cxx-signature>
<cxx-signature>constexpr const_iterator cbegin() const noexcept;</cxx-signature>
<cxx-returns>An iterator such that <code>&*begin() == data_</code> if <code>!empty()</code>,
or else an unspecified value such that <cxx-range begin="begin()" end="end()"></cxx-range> is a valid range.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr const_iterator end() const noexcept;</cxx-signature>
<cxx-signature>constexpr const_iterator cend() const noexcept;</cxx-signature>
<cxx-returns> <code>begin() + size()</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>const_reverse_iterator rbegin() const noexcept;</cxx-signature>
<cxx-signature>const_reverse_iterator crbegin() const noexcept;</cxx-signature>
<cxx-returns> <code>const_reverse_iterator(end())</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>const_reverse_iterator rend() const noexcept;</cxx-signature>
<cxx-signature>const_reverse_iterator crend() const noexcept;</cxx-signature>
<cxx-returns><code>const_reverse_iterator(begin())</code>.</cxx-returns>
</cxx-function>
</cxx-section>
<cxx-section id="string.view.capacity">
<h1><code>basic_string_view</code> capacity</h1>
<cxx-function>
<cxx-signature>constexpr size_type size() const noexcept;</cxx-signature>
<cxx-returns><code>size_</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr size_type length() const noexcept;</cxx-signature>
<cxx-returns><code>size_</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr size_type max_size() const noexcept;</cxx-signature>
<cxx-returns>The largest possible number of char-like objects that can be referred to by a <code>basic_string_view</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr bool empty() const noexcept;</cxx-signature>
<cxx-returns><code>size_ == 0</code>.</cxx-returns>
</cxx-function>
</cxx-section>
<cxx-section id="string.view.access">
<h1><code>basic_string_view</code> element access</h1>
<cxx-function>
<cxx-signature>constexpr const_reference operator[](size_type pos) const;</cxx-signature>
<cxx-requires><code>pos < size()</code>.</cxx-requires>
<cxx-returns><code>data_[pos]</code>.</cxx-returns>
<cxx-throws>Nothing.</cxx-throws>
<p><cxx-note>Unlike <code>basic_string::operator[]</code>,
<code>basic_string_view::operator[](size())</code> has undefined behavior instead of returning <code>charT()</code>.</cxx-note></p>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr const_reference at(size_type pos) const;</cxx-signature>
<cxx-throws><code>out_of_range</code> if <code>pos >= size()</code>.</cxx-throws>
<cxx-returns><code>data_[pos]</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr const_reference front() const;</cxx-signature>
<cxx-requires><code>!empty()</code></cxx-requires>
<cxx-returns><code>data_[0]</code>.</cxx-returns>
<cxx-throws>Nothing.</cxx-throws>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr const_reference back() const;</cxx-signature>
<cxx-requires><code>!empty()</code></cxx-requires>
<cxx-returns><code>data_[size() - 1]</code>.</cxx-returns>
<cxx-throws>Nothing.</cxx-throws>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr const_pointer data() const noexcept;</cxx-signature>
<cxx-returns><code>data_</code>.</cxx-returns>
<p><cxx-note>Unlike <code>basic_string::data()</code> and string literals,
<code>data()</code> may return a pointer to a buffer that is not null-terminated.
Therefore it is typically a mistake to pass <code>data()</code> to a routine that takes just a <code>const charT*</code> and expects a null-terminated string.</cxx-note></p>
</cxx-function>
</cxx-section>
<cxx-section id="string.view.modifiers">
<h1><code>basic_string_view</code> modifiers</h1>
<cxx-function>
<cxx-signature>constexpr void remove_prefix(size_type n);</cxx-signature>
<cxx-requires><code>n <= size()</code>.</cxx-requires>
<cxx-effects>Equivalent to <code>data_ += n; size_ -= n;</code></cxx-effects>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr void remove_suffix(size_type n);</cxx-signature>
<cxx-requires><code>n <= size()</code>.</cxx-requires>
<cxx-effects>Equivalent to <code>size_ -= n;</code></cxx-effects>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr void swap(basic_string_view& s) noexcept;</cxx-signature>
<cxx-effects>Exchanges the values of <code>*this</code> and <code>s</code>.</cxx-effects>
</cxx-function>
</cxx-section>
<cxx-section id="string.view.ops">
<h1><code>basic_string_view</code> string operations</h1>
<cxx-function>
<cxx-signature>template<class Allocator>
explicit<cxx-footnote>This conversion is explicit to avoid accidental O(N) operations on type mismatches.</cxx-footnote> operator basic_string<
charT, traits, Allocator>() const;</cxx-signature>
<cxx-effects>Equivalent to <code>return basic_string<charT, traits, Allocator>(begin(), end());</code></cxx-effects>
<cxx-complexity>O(<code>size()</code>)</cxx-complexity>
<p><cxx-note>Users who want to control the allocator instance should call <code>to_string(allocator)</code>.</cxx-note></p>
</cxx-function>
<cxx-function>
<cxx-signature>template<class Allocator = allocator<charT>>
basic_string<charT, traits, Allocator> to_string(
const Allocator& a = Allocator()) const;</cxx-signature>
<cxx-returns><code>basic_string<charT, traits, Allocator>(begin(), end(), a)</code>.</cxx-returns>
<cxx-complexity>O(<code>size()</code>)</cxx-complexity>
</cxx-function>
<cxx-function>
<cxx-signature>size_type copy(charT* s, size_type n, size_type pos = 0) const;</cxx-signature>
<p>Let <code>rlen</code> be the smaller of <code>n</code> and <code>size() - pos</code>.</p>
<cxx-throws><code>out_of_range</code> if <code>pos > size()</code>.</cxx-throws>
<cxx-requires><cxx-range begin="s" end="s + rlen"></cxx-range> is a valid range.</cxx-requires>
<cxx-effects>Equivalent to <code>std::copy_n(begin() + pos, rlen, s).</code></cxx-effects>
<cxx-returns><code>rlen</code>.</cxx-returns>
<cxx-complexity>O(<code>rlen</code>)</cxx-complexity>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;</cxx-signature>
<cxx-throws><code>out_of_range</code> if <code>pos > size()</code>.</cxx-throws>
<cxx-effects>Determines the effective length <code><var>rlen</var></code> of the string to reference as the smaller of <code>n</code> and <code>size() - pos</code>.</cxx-effects>
<cxx-returns><code>basic_string_view(data()+pos, <var>rlen</var>)</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr int compare(basic_string_view str) const noexcept;</cxx-signature>
<cxx-effects>Determines the effective length <code><var>rlen</var></code> of the strings to compare as the smaller of <code>size()</code> and <code>str.size()</code>.
The function then compares the two strings by calling <code>traits::compare(data(), str.data(), <var>rlen</var>)</code>.</cxx-effects>
<cxx-complexity>O(<code><var>rlen</var></code>)</cxx-complexity>
<cxx-returns>The nonzero result if the result of the comparison is nonzero.
Otherwise, returns a value as indicated in <cxx-ref to="tab:string.view.compare"></cxx-ref>.</cxx-returns>
<table is="cxx-table" id="tab:string.view.compare" class="center">
<caption><code>compare()</code> results</caption>
<tr><th>Condition</th><th>Return Value</th></tr>
<tr><td><code>size() < str.size()</code></td><td><code>< 0</code></td></tr>
<tr><td><code>size() == str.size()</code></td><td><code>  0</code></td></tr>
<tr><td><code>size() > str.size()</code></td><td><code>> 0</code></td></tr>
</table>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr int compare(size_type pos1, size_type n1, basic_string_view str) const;</cxx-signature>
<cxx-effects>Equivalent to <code>return substr(pos1, n1).compare(str);</code></cxx-effects>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr int compare(size_type pos1, size_type n1, basic_string_view str,
size_type pos2, size_type n2) const;</cxx-signature>
<cxx-effects>Equivalent to <code>return substr(pos1, n1).compare(str.substr(pos2, n2));</code></cxx-effects>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr int compare(const charT* s) const;</cxx-signature>
<cxx-effects>Equivalent to <code>return compare(basic_string_view(s));</code></cxx-effects>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr int compare(size_type pos1, size_type n1, const charT* s) const;</cxx-signature>
<cxx-effects>Equivalent to <code>return substr(pos1, n1).compare(basic_string_view(s));</code></cxx-effects>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr int compare(size_type pos1, size_type n1,
const charT* s, size_type n2) const;</cxx-signature>
<cxx-effects>Equivalent to <code>return substr(pos1, n1).compare(basic_string_view(s, n2));</code></cxx-effects>
</cxx-function>
<cxx-section id="string.view.find">
<h1>Searching <code>basic_string_view</code></h1>
<p>This section specifies the <code>basic_string_view</code> member functions named
<code>find</code>, <code>rfind</code>, <code>find_first_of</code>, <code>find_last_of</code>, <code>find_first_not_of</code>, and <code>find_last_not_of</code>.</p>
<p>Member functions in this section have complexity O(<code>size() * str.size()</code>) at worst,
although implementations are encouraged to do better.</p>
<p>Each member function of the form</p>
<pre><code>constexpr <var>return-type fx1</var>(const charT* s, size_type pos);</code></pre>
<p class="cont">is equivalent to <code>return <var>fx1</var>(basic_string_view(s), pos);</code></p>
<p>Each member function of the form</p>
<pre><code>constexpr <var>return-type fx1</var>(const charT* s, size_type pos, size_type n);</code></pre>
<p class="cont">is equivalent to <code>return <var>fx1</var>(basic_string_view(s, n), pos);</code></p>
<p>Each member function of the form</p>
<pre><code>constexpr <var>return-type fx2</var>(charT c, size_type pos);</code></pre>
<p class="cont">is equivalent to <code>return <var>fx2</var>(basic_string_view(&c, 1), pos);</code></p>
<cxx-function>
<cxx-signature>constexpr size_type find(basic_string_view str, size_type pos = 0) const noexcept;</cxx-signature>
<cxx-effects>
Determines the lowest position <code>xpos</code>, if possible, such that the following conditions obtain:
<ul>
<li><code>pos <= xpos</code></li>
<li><code>xpos + str.size() <= size()</code></li>
<li><code>traits::eq(at(xpos+I), str.at(I))</code> for all elements <code>I</code> of the string referenced by <code>str</code>.</li>
</ul>
</cxx-effects>
<cxx-returns><code>xpos</code> if the function can determine such a value for <code>xpos</code>.
Otherwise, returns <code>npos</code>.</cxx-returns>
<cxx-remarks>Uses <code>traits::eq()</code>.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr size_type rfind(basic_string_view str, size_type pos = npos) const noexcept;</cxx-signature>
<cxx-effects>
Determines the highest position <code>xpos</code>, if possible, such that the following conditions obtain:
<ul>
<li><code>xpos <= pos</code></li>
<li><code>xpos + str.size() <= size()</code></li>
<li><code>traits::eq(at(xpos+I), str.at(I))</code> for all elements <code>I</code> of the string referenced by <code>str</code>.</li>
</ul>
</cxx-effects>
<cxx-returns><code>xpos</code> if the function can determine such a value for <code>xpos</code>.
Otherwise, returns <code>npos</code>.</cxx-returns>
<cxx-remarks>Uses <code>traits::eq()</code>.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr size_type find_first_of(basic_string_view str, size_type pos = 0) const noexcept;</cxx-signature>
<cxx-effects>Determines the lowest position <code>xpos</code>, if possible, such that the following conditions obtain:
<ul>
<li><code>pos <= xpos</code></li>
<li><code>xpos < size()</code></li>
<li><code>traits::eq(at(xpos), str.at(I))</code> for some element <code>I</code> of the string referenced by <code>str</code>.</li>
</ul>
</cxx-effects>
<cxx-returns><code>xpos</code> if the function can determine such a value for <code>xpos</code>.
Otherwise, returns <code>npos</code>.</cxx-returns>
<cxx-remarks>Uses <code>traits::eq()</code>.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr size_type find_last_of(basic_string_view str, size_type pos = npos) const noexcept;</cxx-signature>
<cxx-effects>Determines the highest position <code>xpos</code>, if possible, such that the following conditions obtain:
<ul>
<li><code>xpos <= pos</code></li>
<li><code>xpos < size()</code></li>
<li><code>traits::eq(at(xpos), str.at(I))</code> for some element <code>I</code> of the string referenced by <code>str</code>.</li>
</ul>
</cxx-effects>
<cxx-returns><code>xpos</code> if the function can determine such a value for <code>xpos</code>.
Otherwise, returns <code>npos</code>.</cxx-returns>
<cxx-remarks>Uses <code>traits::eq()</code>.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr size_type find_first_not_of(basic_string_view str, size_type pos = 0) const noexcept;</cxx-signature>
<cxx-effects>Determines the lowest position <code>xpos</code>, if possible, such that the following conditions obtain:
<ul>
<li><code>pos <= xpos</code></li>
<li><code>xpos < size()</code></li>
<li><code>traits::eq(at(xpos), str.at(I))</code> for no element <code>I</code> of the string referenced by <code>str</code>.</li>
</ul>
</cxx-effects>
<cxx-returns><code>xpos</code> if the function can determine such a value for <code>xpos</code>. Otherwise, returns <code>npos</code>.</cxx-returns>
<cxx-remarks>Uses <code>traits::eq()</code>.</cxx-remarks>
</cxx-function>
<cxx-function>
<cxx-signature>constexpr size_type find_last_not_of(basic_string_view str, size_type pos = npos) const noexcept;</cxx-signature>
<cxx-effects>Determines the highest position <code>xpos</code>, if possible, such that the following conditions obtain:
<ul>
<li><code>xpos <= pos</code></li>
<li><code>xpos < size()</code></li>
<li><code>traits::eq(at(xpos), str.at(I))</code> for no element <code>I</code> of the string referenced by <code>str</code>.</li>
</ul>
</cxx-effects>
<cxx-returns><code>xpos</code> if the function can determine such a value for <code>xpos</code>.
Otherwise, returns <code>npos</code>.</cxx-returns>
<cxx-remarks>Uses <code>traits::eq()</code>.</cxx-remarks>
</cxx-function>
</cxx-section>
</cxx-section>
<cxx-section id="string.view.comparison">
<h1><code>basic_string_view</code> non-member comparison functions</h1>
<p>
Let <code>S</code> be <code>basic_string_view<charT, traits></code>, and <code>sv</code> be an instance of <code>S</code>.
Implementations shall provide sufficient additional overloads marked <code>constexpr</code> and <code>noexcept</code>
so that an object <code><var>t</var></code> with an implicit conversion to <code>S</code> can be compared according to <cxx-ref to="tab:string.view.comparison.overloads"></cxx-ref>.
</p>
<table is="cxx-table" id="tab:string.view.comparison.overloads" class="center"><caption>Additional <code>basic_string_view</code> comparison overloads</caption>
<tr><th>Expression</th><th>Equivalent to</th></tr>
<tr><td><code>t == sv</code></td><td><code>S(t) == sv</code></td></tr>
<tr><td><code>sv == t</code></td><td><code>sv == S(t)</code></td></tr>
<tr><td><code>t != sv</code></td><td><code>S(t) != sv</code></td></tr>
<tr><td><code>sv != t</code></td><td><code>sv != S(t)</code></td></tr>
<tr><td><code>t < sv</code></td><td><code>S(t) < sv</code></td></tr>
<tr><td><code>sv < t</code></td><td><code>sv < S(t)</code></td></tr>
<tr><td><code>t > sv</code></td><td><code>S(t) > sv</code></td></tr>
<tr><td><code>sv > t</code></td><td><code>sv > S(t)</code></td></tr>
<tr><td><code>t <= sv</code></td><td><code>S(t) <= sv</code></td></tr>
<tr><td><code>sv <= t</code></td><td><code>sv <= S(t)</code></td></tr>
<tr><td><code>t >= sv</code></td><td><code>S(t) >= sv</code></td></tr>
<tr><td><code>sv >= t</code></td><td><code>sv >= S(t)</code></td></tr>
</table>
<cxx-example>A sample conforming implementation for operator== would be:
<pre><code>template<class T> using __identity = decay_t<T>;
template<class charT, class traits>
constexpr bool operator==(
basic_string_view<charT, traits> lhs,
basic_string_view<charT, traits> rhs) noexcept {
return lhs.compare(rhs) == 0;
}
template<class charT, class traits>
constexpr bool operator==(
basic_string_view<charT, traits> lhs,
__identity<basic_string_view<charT, traits>> rhs) noexcept {
return lhs.compare(rhs) == 0;
}
template<class charT, class traits>
constexpr bool operator==(
__identity<basic_string_view<charT, traits>> lhs,
basic_string_view<charT, traits> rhs) noexcept {
return lhs.compare(rhs) == 0;
}</code></pre>
</cxx-example>
<cxx-function>
<cxx-signature>template<class charT, class traits>
constexpr bool operator==(basic_string_view<charT, traits> lhs,
basic_string_view<charT, traits> rhs) noexcept;</cxx-signature>
<cxx-returns> <code>lhs.compare(rhs) == 0</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template<class charT, class traits>
constexpr bool operator!=(basic_string_view<charT, traits> lhs,
basic_string_view<charT, traits> rhs) noexcept;</cxx-signature>
<cxx-returns> <code>lhs.compare(rhs) != 0</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template<class charT, class traits>
constexpr bool operator< (basic_string_view<charT, traits> lhs,
basic_string_view<charT, traits> rhs) noexcept;</cxx-signature>
<cxx-returns> <code>lhs.compare(rhs) < 0</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template<class charT, class traits>
constexpr bool operator> (basic_string_view<charT, traits> lhs,
basic_string_view<charT, traits> rhs) noexcept;</cxx-signature>
<cxx-returns> <code>lhs.compare(rhs) > 0</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template<class charT, class traits>
constexpr bool operator<=(basic_string_view<charT, traits> lhs,
basic_string_view<charT, traits> rhs) noexcept;</cxx-signature>
<cxx-returns> <code>lhs.compare(rhs) <= 0</code>.</cxx-returns>
</cxx-function>
<cxx-function>
<cxx-signature>template<class charT, class traits>
constexpr bool operator>=(basic_string_view<charT, traits> lhs,
basic_string_view<charT, traits> rhs) noexcept;</cxx-signature>
<cxx-returns> <code>lhs.compare(rhs) >= 0</code>.</cxx-returns>
</cxx-function>
</cxx-section>
<cxx-section id="string.view.io">
<h1>Inserters and extractors</h1>
<cxx-function>
<cxx-signature>template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
basic_string_view<charT, traits> str);</cxx-signature>
<cxx-effects>Equivalent to <code>return os << str.to_string();</code></cxx-effects>
</cxx-function>
</cxx-section>
<cxx-section id="string.view.hash">
<h1>Hash support</h1>
<cxx-function>
<cxx-signature>template <> struct hash<experimental::string_view>;</cxx-signature>
<cxx-signature>template <> struct hash<experimental::u16string_view>;</cxx-signature>
<cxx-signature>template <> struct hash<experimental::u32string_view>;</cxx-signature>
<cxx-signature>template <> struct hash<experimental::wstring_view>;</cxx-signature>
<p>The template specializations shall meet the requirements of class template hash (<cxx-ref in="cxx" to="unord.hash"></cxx-ref>).</p>
</cxx-function>
</cxx-section>
</cxx-clause>