Skip to content

Commit 12fdd84

Browse files
committed
[libc++][string_view] Applied [[nodiscard]]
`[[nodiscard]]` should be applied to functions where discarding the return value is most likely a correctness issue. - https://libcxx.llvm.org/CodingGuidelines.html#apply-nodiscard-where-relevant
1 parent 13ed14f commit 12fdd84

File tree

3 files changed

+172
-61
lines changed

3 files changed

+172
-61
lines changed

libcxx/include/string_view

Lines changed: 67 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -362,71 +362,74 @@ public:
362362
# endif
363363

364364
// [string.view.iterators], iterators
365-
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return cbegin(); }
365+
[[__nodiscard__]] _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return cbegin(); }
366366

367-
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return cend(); }
367+
[[__nodiscard__]] _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return cend(); }
368368

369-
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT {
369+
[[__nodiscard__]] _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT {
370370
# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
371371
return std::__make_bounded_iter(data(), data(), data() + size());
372372
# else
373373
return const_iterator(__data_);
374374
# endif
375375
}
376376

377-
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT {
377+
[[__nodiscard__]] _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT {
378378
# ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
379379
return std::__make_bounded_iter(data() + size(), data(), data() + size());
380380
# else
381381
return const_iterator(__data_ + __size_);
382382
# endif
383383
}
384384

385-
_LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT {
385+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator
386+
rbegin() const _NOEXCEPT {
386387
return const_reverse_iterator(cend());
387388
}
388389

389-
_LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT {
390+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT {
390391
return const_reverse_iterator(cbegin());
391392
}
392393

393-
_LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT {
394+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator
395+
crbegin() const _NOEXCEPT {
394396
return const_reverse_iterator(cend());
395397
}
396398

397-
_LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT {
399+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT {
398400
return const_reverse_iterator(cbegin());
399401
}
400402

401403
// [string.view.capacity], capacity
402-
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; }
404+
[[__nodiscard__]] _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; }
403405

404-
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI size_type length() const _NOEXCEPT { return __size_; }
406+
[[__nodiscard__]] _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI size_type length() const _NOEXCEPT { return __size_; }
405407

406-
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
408+
[[__nodiscard__]] _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
407409
return numeric_limits<size_type>::max() / sizeof(value_type);
408410
}
409411

410412
[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return __size_ == 0; }
411413

412414
// [string.view.access], element access
413-
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __pos) const _NOEXCEPT {
415+
[[__nodiscard__]] _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference
416+
operator[](size_type __pos) const _NOEXCEPT {
414417
return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__pos < size(), "string_view[] index out of bounds"), __data_[__pos];
415418
}
416419

417-
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __pos) const {
420+
[[__nodiscard__]] _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __pos) const {
418421
return __pos >= size() ? (__throw_out_of_range("string_view::at"), __data_[0]) : __data_[__pos];
419422
}
420423

421-
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT {
424+
[[__nodiscard__]] _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT {
422425
return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::front(): string is empty"), __data_[0];
423426
}
424427

425-
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT {
428+
[[__nodiscard__]] _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT {
426429
return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::back(): string is empty"), __data_[__size_ - 1];
427430
}
428431

429-
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_pointer data() const _NOEXCEPT { return __data_; }
432+
[[__nodiscard__]] _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_pointer data() const _NOEXCEPT { return __data_; }
430433

431434
// [string.view.modifiers], modifiers:
432435
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI void remove_prefix(size_type __n) _NOEXCEPT {
@@ -459,7 +462,8 @@ public:
459462
return __rlen;
460463
}
461464

462-
_LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view substr(size_type __pos = 0, size_type __n = npos) const {
465+
[[__nodiscard__]] _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view
466+
substr(size_type __pos = 0, size_type __n = npos) const {
463467
// Use the `__assume_valid` form of the constructor to avoid an unnecessary check. Any substring of a view is a
464468
// valid view. In particular, `size()` is known to be smaller than `numeric_limits<difference_type>::max()`, so the
465469
// new size is also smaller. See also https://llvm.org/PR91634.
@@ -474,225 +478,232 @@ public:
474478
}
475479
# endif
476480

477-
_LIBCPP_CONSTEXPR_SINCE_CXX14 int compare(basic_string_view __sv) const _NOEXCEPT {
481+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 int compare(basic_string_view __sv) const _NOEXCEPT {
478482
size_type __rlen = std::min(size(), __sv.size());
479483
int __retval = _Traits::compare(data(), __sv.data(), __rlen);
480484
if (__retval == 0) // first __rlen chars matched
481485
__retval = size() == __sv.size() ? 0 : (size() < __sv.size() ? -1 : 1);
482486
return __retval;
483487
}
484488

485-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
489+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
486490
compare(size_type __pos1, size_type __n1, basic_string_view __sv) const {
487491
return substr(__pos1, __n1).compare(__sv);
488492
}
489493

490-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
494+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
491495
compare(size_type __pos1, size_type __n1, basic_string_view __sv, size_type __pos2, size_type __n2) const {
492496
return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
493497
}
494498

495-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
499+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
496500
compare(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s) const _NOEXCEPT {
497501
return compare(basic_string_view(__s));
498502
}
499503

500-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
504+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
501505
compare(size_type __pos1, size_type __n1, const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s) const {
502506
return substr(__pos1, __n1).compare(basic_string_view(__s));
503507
}
504508

505-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
509+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
506510
compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
507511
_LIBCPP_DIAGNOSE_NULLPTR_IF(__n2 != 0 && __s == nullptr, " if n2 is not zero") {
508512
return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
509513
}
510514

511515
// find
512-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
516+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
513517
find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
514518
return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __s.data(), __pos, __s.size());
515519
}
516520

517-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT {
521+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
522+
find(_CharT __c, size_type __pos = 0) const _NOEXCEPT {
518523
return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
519524
}
520525

521-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
526+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
522527
find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
523528
_LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr, " if n is not zero") {
524529
_LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
525530
return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
526531
}
527532

528-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
533+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
529534
find(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __pos = 0) const _NOEXCEPT {
530535
_LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find(): received nullptr");
531536
return std::__str_find<value_type, size_type, traits_type, npos>(
532537
data(), size(), __s, __pos, traits_type::length(__s));
533538
}
534539

535540
// rfind
536-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
541+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
537542
rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
538543
return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __s.data(), __pos, __s.size());
539544
}
540545

541-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
546+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
542547
rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT {
543548
return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
544549
}
545550

546-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
551+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
547552
rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
548553
_LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr, " if n is not zero") {
549554
_LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
550555
return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
551556
}
552557

553-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
558+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
554559
rfind(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __pos = npos) const _NOEXCEPT {
555560
_LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::rfind(): received nullptr");
556561
return std::__str_rfind<value_type, size_type, traits_type, npos>(
557562
data(), size(), __s, __pos, traits_type::length(__s));
558563
}
559564

560565
// find_first_of
561-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
566+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
562567
find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
563568
return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
564569
data(), size(), __s.data(), __pos, __s.size());
565570
}
566571

567-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
572+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
568573
find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT {
569574
return find(__c, __pos);
570575
}
571576

572-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
577+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
573578
find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
574579
_LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr, " if n is not zero") {
575580
_LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
576581
return std::__str_find_first_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
577582
}
578583

579-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
584+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
580585
find_first_of(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __pos = 0) const _NOEXCEPT {
581586
_LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_of(): received nullptr");
582587
return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
583588
data(), size(), __s, __pos, traits_type::length(__s));
584589
}
585590

586591
// find_last_of
587-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
592+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
588593
find_last_of(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
589594
return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
590595
data(), size(), __s.data(), __pos, __s.size());
591596
}
592597

593-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
598+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
594599
find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT {
595600
return rfind(__c, __pos);
596601
}
597602

598-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
603+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
599604
find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
600605
_LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr, " if n is not zero") {
601606
_LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
602607
return std::__str_find_last_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
603608
}
604609

605-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
610+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
606611
find_last_of(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __pos = npos) const _NOEXCEPT {
607612
_LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_of(): received nullptr");
608613
return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
609614
data(), size(), __s, __pos, traits_type::length(__s));
610615
}
611616

612617
// find_first_not_of
613-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
618+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
614619
find_first_not_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
615620
return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
616621
data(), size(), __s.data(), __pos, __s.size());
617622
}
618623

619-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
624+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
620625
find_first_not_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT {
621626
return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
622627
}
623628

624-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
629+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
625630
find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
626631
_LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr, " if n is not zero") {
627632
_LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
628633
return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
629634
}
630635

631-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
636+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
632637
find_first_not_of(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __pos = 0) const _NOEXCEPT {
633638
_LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
634639
return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
635640
data(), size(), __s, __pos, traits_type::length(__s));
636641
}
637642

638643
// find_last_not_of
639-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
644+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
640645
find_last_not_of(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
641646
return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
642647
data(), size(), __s.data(), __pos, __s.size());
643648
}
644649

645-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
650+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
646651
find_last_not_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT {
647652
return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
648653
}
649654

650-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
655+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
651656
find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
652657
_LIBCPP_DIAGNOSE_NULLPTR_IF(__n != 0 && __s == nullptr, " if n is not zero") {
653658
_LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
654659
return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
655660
}
656661

657-
_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
662+
[[__nodiscard__]] _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
658663
find_last_not_of(const _CharT* _LIBCPP_DIAGNOSE_NULLPTR __s, size_type __pos = npos) const _NOEXCEPT {
659664
_LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
660665
return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
661666
data(), size(), __s, __pos, traits_type::length(__s));
662667
}
663668

664669
# if _LIBCPP_STD_VER >= 20
665-
constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(basic_string_view __s) const noexcept {
670+
[[nodiscard]] constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(basic_string_view __s) const noexcept {
666671
return size() >= __s.size() && compare(0, __s.size(), __s) == 0;
667672
}
668673

669-
constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(value_type __c) const noexcept {
674+
[[nodiscard]] constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(value_type __c) const noexcept {
670675
return !empty() && _Traits::eq(front(), __c);
671676
}
672677

673-
constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const noexcept {
678+
[[nodiscard]] constexpr _LIBCPP_HIDE_FROM_ABI bool
679+
starts_with(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const noexcept {
674680
return starts_with(basic_string_view(__s));
675681
}
676682

677-
constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(basic_string_view __s) const noexcept {
683+
[[nodiscard]] constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(basic_string_view __s) const noexcept {
678684
return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0;
679685
}
680686

681-
constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(value_type __c) const noexcept {
687+
[[nodiscard]] constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(value_type __c) const noexcept {
682688
return !empty() && _Traits::eq(back(), __c);
683689
}
684690

685-
constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const noexcept {
691+
[[nodiscard]] constexpr _LIBCPP_HIDE_FROM_ABI bool
692+
ends_with(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const noexcept {
686693
return ends_with(basic_string_view(__s));
687694
}
688695
# endif
689696

690697
# if _LIBCPP_STD_VER >= 23
691-
constexpr _LIBCPP_HIDE_FROM_ABI bool contains(basic_string_view __sv) const noexcept { return find(__sv) != npos; }
698+
[[nodiscard]] constexpr _LIBCPP_HIDE_FROM_ABI bool contains(basic_string_view __sv) const noexcept {
699+
return find(__sv) != npos;
700+
}
692701

693-
constexpr _LIBCPP_HIDE_FROM_ABI bool contains(value_type __c) const noexcept { return find(__c) != npos; }
702+
[[nodiscard]] constexpr _LIBCPP_HIDE_FROM_ABI bool contains(value_type __c) const noexcept {
703+
return find(__c) != npos;
704+
}
694705

695-
constexpr _LIBCPP_HIDE_FROM_ABI bool contains(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const {
706+
[[nodiscard]] constexpr _LIBCPP_HIDE_FROM_ABI bool contains(const value_type* _LIBCPP_DIAGNOSE_NULLPTR __s) const {
696707
return find(__s) != npos;
697708
}
698709
# endif

0 commit comments

Comments
 (0)