33#ifndef _GLIBCXX_STRING_VIEW
34#define _GLIBCXX_STRING_VIEW 1
36#pragma GCC system_header
38#define __glibcxx_want_constexpr_char_traits
39#define __glibcxx_want_constexpr_string_view
40#define __glibcxx_want_freestanding_string_view
41#define __glibcxx_want_string_view
42#define __glibcxx_want_starts_ends_with
43#define __glibcxx_want_string_contains
46#if __cplusplus >= 201703L
55#if __cplusplus >= 202002L
64namespace std _GLIBCXX_VISIBILITY(default)
66_GLIBCXX_BEGIN_NAMESPACE_VERSION
70 __sv_check(
size_t __size,
size_t __pos,
const char* __s)
73 __throw_out_of_range_fmt(__N(
"%s: __pos (which is %zu) > __size "
74 "(which is %zu)"), __s, __pos, __size);
81 __sv_limit(
size_t __size,
size_t __pos,
size_t __off)
noexcept
83 const bool __testoff = __off < __size - __pos;
84 return __testoff ? __off : __size - __pos;
105 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>>
108 static_assert(!is_array_v<_CharT>);
109 static_assert(is_trivial_v<_CharT> && is_standard_layout_v<_CharT>);
110 static_assert(is_same_v<_CharT, typename _Traits::char_type>);
115 using traits_type = _Traits;
116 using value_type = _CharT;
117 using pointer = value_type*;
118 using const_pointer =
const value_type*;
119 using reference = value_type&;
120 using const_reference =
const value_type&;
121 using const_iterator =
const value_type*;
122 using iterator = const_iterator;
125 using size_type = size_t;
126 using difference_type = ptrdiff_t;
127 static constexpr size_type npos = size_type(-1);
133 : _M_len{0}, _M_str{
nullptr}
138 [[__gnu__::__nonnull__]]
141 : _M_len{traits_type::length(__str)},
147 : _M_len{__len}, _M_str{__str}
150#if __cplusplus >= 202002L && __cpp_lib_concepts
151 template<contiguous_iterator _It, sized_sentinel_for<_It> _End>
152 requires same_as<iter_value_t<_It>, _CharT>
153 && (!convertible_to<_End, size_type>)
156 noexcept(
noexcept(__last - __first))
160#if __cplusplus > 202002L
161 template<
typename _Range,
typename _DRange = remove_cvref_t<_Range>>
162 requires (!is_same_v<_DRange, basic_string_view>)
163 && ranges::contiguous_range<_Range>
164 && ranges::sized_range<_Range>
165 && is_same_v<ranges::range_value_t<_Range>, _CharT>
166 && (!is_convertible_v<_Range, const _CharT*>)
167 && (!
requires (_DRange& __d) {
168 __d.operator ::std::basic_string_view<_CharT, _Traits>();
186 constexpr const_iterator
187 begin()
const noexcept
188 {
return this->_M_str; }
191 constexpr const_iterator
193 {
return this->_M_str + this->_M_len; }
196 constexpr const_iterator
197 cbegin()
const noexcept
198 {
return this->_M_str; }
201 constexpr const_iterator
202 cend()
const noexcept
203 {
return this->_M_str + this->_M_len; }
207 rbegin()
const noexcept
212 rend()
const noexcept
217 crbegin()
const noexcept
222 crend()
const noexcept
229 size()
const noexcept
230 {
return this->_M_len; }
234 length()
const noexcept
239 max_size()
const noexcept
241 return (npos -
sizeof(size_type) -
sizeof(
void*))
242 /
sizeof(value_type) / 4;
247 empty()
const noexcept
248 {
return this->_M_len == 0; }
253 constexpr const_reference
254 operator[](size_type __pos)
const noexcept
256 __glibcxx_assert(__pos < this->_M_len);
257 return *(this->_M_str + __pos);
261 constexpr const_reference
262 at(size_type __pos)
const
265 __throw_out_of_range_fmt(__N(
"basic_string_view::at: __pos "
266 "(which is %zu) >= this->size() "
267 "(which is %zu)"), __pos, this->size());
268 return *(this->_M_str + __pos);
272 constexpr const_reference
273 front()
const noexcept
275 __glibcxx_assert(this->_M_len > 0);
276 return *this->_M_str;
280 constexpr const_reference
281 back()
const noexcept
283 __glibcxx_assert(this->_M_len > 0);
284 return *(this->_M_str + this->_M_len - 1);
288 constexpr const_pointer
289 data()
const noexcept
290 {
return this->_M_str; }
295 remove_prefix(size_type __n)
noexcept
297 __glibcxx_assert(this->_M_len >= __n);
303 remove_suffix(size_type __n)
noexcept
305 __glibcxx_assert(this->_M_len >= __n);
321 copy(_CharT* __str, size_type __n, size_type __pos = 0)
const
323 __glibcxx_requires_string_len(__str, __n);
324 __pos = std::__sv_check(size(), __pos,
"basic_string_view::copy");
325 const size_type __rlen = std::min<size_t>(__n, _M_len - __pos);
328 traits_type::copy(__str, data() + __pos, __rlen);
334 substr(size_type __pos = 0, size_type __n = npos)
const noexcept(
false)
336 __pos = std::__sv_check(size(), __pos,
"basic_string_view::substr");
337 const size_type __rlen = std::min<size_t>(__n, _M_len - __pos);
345 const size_type __rlen =
std::min(this->_M_len, __str._M_len);
346 int __ret = traits_type::compare(this->_M_str, __str._M_str, __rlen);
348 __ret = _S_compare(this->_M_len, __str._M_len);
355 {
return this->substr(__pos1, __n1).compare(__str); }
359 compare(size_type __pos1, size_type __n1,
362 return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2));
365 [[nodiscard, __gnu__::__nonnull__]]
367 compare(
const _CharT* __str)
const noexcept
370 [[nodiscard, __gnu__::__nonnull__]]
372 compare(size_type __pos1, size_type __n1,
const _CharT* __str)
const
377 compare(size_type __pos1, size_type __n1,
378 const _CharT* __str, size_type __n2)
const noexcept(
false)
380 return this->substr(__pos1, __n1)
384#ifdef __cpp_lib_starts_ends_with
388 {
return this->substr(0, __x.size()) == __x; }
392 starts_with(_CharT __x)
const noexcept
393 {
return !this->empty() && traits_type::eq(this->front(), __x); }
395 [[nodiscard, __gnu__::__nonnull__]]
397 starts_with(
const _CharT* __x)
const noexcept
404 const auto __len = this->size();
405 const auto __xlen = __x.size();
406 return __len >= __xlen
407 && traits_type::compare(end() - __xlen, __x.data(), __xlen) == 0;
412 ends_with(_CharT __x)
const noexcept
413 {
return !this->empty() && traits_type::eq(this->back(), __x); }
415 [[nodiscard, __gnu__::__nonnull__]]
417 ends_with(
const _CharT* __x)
const noexcept
421#if __cplusplus > 202002L
422#if _GLIBCXX_HOSTED && !defined(__cpp_lib_string_contains)
425# error "libstdc++ bug: string_contains not defined when it should be"
430 {
return this->find(__x) != npos; }
434 contains(_CharT __x)
const noexcept
435 {
return this->find(__x) != npos; }
437 [[nodiscard, __gnu__::__nonnull__]]
439 contains(
const _CharT* __x)
const noexcept
440 {
return this->find(__x) != npos; }
448 {
return this->find(__str._M_str, __pos, __str._M_len); }
452 find(_CharT __c, size_type __pos = 0)
const noexcept;
456 find(
const _CharT* __str, size_type __pos, size_type __n)
const noexcept;
458 [[nodiscard, __gnu__::__nonnull__]]
460 find(
const _CharT* __str, size_type __pos = 0)
const noexcept
461 {
return this->find(__str, __pos, traits_type::length(__str)); }
466 {
return this->rfind(__str._M_str, __pos, __str._M_len); }
470 rfind(_CharT __c, size_type __pos = npos)
const noexcept;
474 rfind(
const _CharT* __str, size_type __pos, size_type __n)
const noexcept;
476 [[nodiscard, __gnu__::__nonnull__]]
478 rfind(
const _CharT* __str, size_type __pos = npos)
const noexcept
479 {
return this->rfind(__str, __pos, traits_type::length(__str)); }
484 {
return this->find_first_of(__str._M_str, __pos, __str._M_len); }
488 find_first_of(_CharT __c, size_type __pos = 0)
const noexcept
489 {
return this->find(__c, __pos); }
493 find_first_of(
const _CharT* __str, size_type __pos,
494 size_type __n)
const noexcept;
496 [[nodiscard, __gnu__::__nonnull__]]
498 find_first_of(
const _CharT* __str, size_type __pos = 0)
const noexcept
499 {
return this->find_first_of(__str, __pos, traits_type::length(__str)); }
504 size_type __pos = npos)
const noexcept
505 {
return this->find_last_of(__str._M_str, __pos, __str._M_len); }
509 find_last_of(_CharT __c, size_type __pos=npos)
const noexcept
510 {
return this->rfind(__c, __pos); }
514 find_last_of(
const _CharT* __str, size_type __pos,
515 size_type __n)
const noexcept;
517 [[nodiscard, __gnu__::__nonnull__]]
519 find_last_of(
const _CharT* __str, size_type __pos = npos)
const noexcept
520 {
return this->find_last_of(__str, __pos, traits_type::length(__str)); }
525 size_type __pos = 0)
const noexcept
526 {
return this->find_first_not_of(__str._M_str, __pos, __str._M_len); }
530 find_first_not_of(_CharT __c, size_type __pos = 0)
const noexcept;
534 find_first_not_of(
const _CharT* __str,
535 size_type __pos, size_type __n)
const noexcept;
537 [[nodiscard, __gnu__::__nonnull__]]
539 find_first_not_of(
const _CharT* __str, size_type __pos = 0)
const noexcept
541 return this->find_first_not_of(__str, __pos,
542 traits_type::length(__str));
548 size_type __pos = npos)
const noexcept
549 {
return this->find_last_not_of(__str._M_str, __pos, __str._M_len); }
553 find_last_not_of(_CharT __c, size_type __pos = npos)
const noexcept;
557 find_last_not_of(
const _CharT* __str,
558 size_type __pos, size_type __n)
const noexcept;
560 [[nodiscard, __gnu__::__nonnull__]]
562 find_last_not_of(
const _CharT* __str,
563 size_type __pos = npos)
const noexcept
565 return this->find_last_not_of(__str, __pos,
566 traits_type::length(__str));
572 _S_compare(size_type __n1, size_type __n2)
noexcept
575 const difference_type __diff = __n1 - __n2;
576 if (__diff > __limits::__max)
577 return __limits::__max;
578 if (__diff < __limits::__min)
579 return __limits::__min;
580 return static_cast<int>(__diff);
584 const _CharT* _M_str;
587#if __cplusplus > 201703L && __cpp_lib_concepts && __cpp_deduction_guides
588 template<contiguous_iterator _It, sized_sentinel_for<_It> _End>
591#if __cplusplus > 202002L
592 template<ranges::contiguous_range _Range>
605#if __cpp_lib_three_way_comparison
606 template<
typename _CharT,
typename _Traits>
612 {
return __x.size() == __y.size() && __x.compare(__y) == 0; }
614 template<
typename _CharT,
typename _Traits>
617 operator<=>(basic_string_view<_CharT, _Traits> __x,
618 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
620 ->
decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
621 {
return __detail::__char_traits_cmp_cat<_Traits>(__x.compare(__y)); }
623 template<
typename _CharT,
typename _Traits>
626 operator==(basic_string_view<_CharT, _Traits> __x,
627 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
629 {
return __x.size() == __y.size() && __x.compare(__y) == 0; }
631 template<
typename _CharT,
typename _Traits>
634 operator==(basic_string_view<_CharT, _Traits> __x,
635 basic_string_view<_CharT, _Traits> __y)
noexcept
636 {
return __x.size() == __y.size() && __x.compare(__y) == 0; }
638 template<
typename _CharT,
typename _Traits>
641 operator==(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
642 basic_string_view<_CharT, _Traits> __y)
noexcept
643 {
return __x.size() == __y.size() && __x.compare(__y) == 0; }
645 template<
typename _CharT,
typename _Traits>
648 operator!=(basic_string_view<_CharT, _Traits> __x,
649 basic_string_view<_CharT, _Traits> __y)
noexcept
650 {
return !(__x == __y); }
652 template<
typename _CharT,
typename _Traits>
655 operator!=(basic_string_view<_CharT, _Traits> __x,
656 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
658 {
return !(__x == __y); }
660 template<
typename _CharT,
typename _Traits>
663 operator!=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
664 basic_string_view<_CharT, _Traits> __y)
noexcept
665 {
return !(__x == __y); }
667 template<
typename _CharT,
typename _Traits>
670 operator< (basic_string_view<_CharT, _Traits> __x,
671 basic_string_view<_CharT, _Traits> __y)
noexcept
672 {
return __x.compare(__y) < 0; }
674 template<
typename _CharT,
typename _Traits>
677 operator< (basic_string_view<_CharT, _Traits> __x,
678 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
680 {
return __x.compare(__y) < 0; }
682 template<
typename _CharT,
typename _Traits>
685 operator< (__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
686 basic_string_view<_CharT, _Traits> __y)
noexcept
687 {
return __x.compare(__y) < 0; }
689 template<
typename _CharT,
typename _Traits>
692 operator> (basic_string_view<_CharT, _Traits> __x,
693 basic_string_view<_CharT, _Traits> __y)
noexcept
694 {
return __x.compare(__y) > 0; }
696 template<
typename _CharT,
typename _Traits>
699 operator> (basic_string_view<_CharT, _Traits> __x,
700 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
702 {
return __x.compare(__y) > 0; }
704 template<
typename _CharT,
typename _Traits>
707 operator> (__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
708 basic_string_view<_CharT, _Traits> __y)
noexcept
709 {
return __x.compare(__y) > 0; }
711 template<
typename _CharT,
typename _Traits>
714 operator<=(basic_string_view<_CharT, _Traits> __x,
715 basic_string_view<_CharT, _Traits> __y)
noexcept
716 {
return __x.compare(__y) <= 0; }
718 template<
typename _CharT,
typename _Traits>
721 operator<=(basic_string_view<_CharT, _Traits> __x,
722 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
724 {
return __x.compare(__y) <= 0; }
726 template<
typename _CharT,
typename _Traits>
729 operator<=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
730 basic_string_view<_CharT, _Traits> __y)
noexcept
731 {
return __x.compare(__y) <= 0; }
733 template<
typename _CharT,
typename _Traits>
736 operator>=(basic_string_view<_CharT, _Traits> __x,
737 basic_string_view<_CharT, _Traits> __y)
noexcept
738 {
return __x.compare(__y) >= 0; }
740 template<
typename _CharT,
typename _Traits>
743 operator>=(basic_string_view<_CharT, _Traits> __x,
744 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
746 {
return __x.compare(__y) >= 0; }
748 template<
typename _CharT,
typename _Traits>
751 operator>=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
752 basic_string_view<_CharT, _Traits> __y)
noexcept
753 {
return __x.compare(__y) >= 0; }
758 template<
typename _CharT,
typename _Traits>
759 inline basic_ostream<_CharT, _Traits>&
760 operator<<(basic_ostream<_CharT, _Traits>& __os,
761 basic_string_view<_CharT,_Traits> __str)
762 {
return __ostream_insert(__os, __str.data(), __str.size()); }
767 using string_view = basic_string_view<char>;
768 using wstring_view = basic_string_view<wchar_t>;
769#ifdef _GLIBCXX_USE_CHAR8_T
770 using u8string_view = basic_string_view<char8_t>;
772 using u16string_view = basic_string_view<char16_t>;
773 using u32string_view = basic_string_view<char32_t>;
777 template<
typename _Tp>
781 struct hash<string_view>
782 :
public __hash_base<size_t, string_view>
786 operator()(
const string_view& __str)
const noexcept
787 {
return std::_Hash_impl::hash(__str.data(), __str.length()); }
795 struct hash<wstring_view>
796 :
public __hash_base<size_t, wstring_view>
800 operator()(
const wstring_view& __s)
const noexcept
801 {
return std::_Hash_impl::hash(__s.data(),
802 __s.length() *
sizeof(
wchar_t)); }
809#ifdef _GLIBCXX_USE_CHAR8_T
811 struct hash<u8string_view>
812 :
public __hash_base<size_t, u8string_view>
816 operator()(
const u8string_view& __str)
const noexcept
817 {
return std::_Hash_impl::hash(__str.data(), __str.length()); }
826 struct hash<u16string_view>
827 :
public __hash_base<size_t, u16string_view>
831 operator()(
const u16string_view& __s)
const noexcept
832 {
return std::_Hash_impl::hash(__s.data(),
833 __s.length() *
sizeof(
char16_t)); }
841 struct hash<u32string_view>
842 :
public __hash_base<size_t, u32string_view>
846 operator()(
const u32string_view& __s)
const noexcept
847 {
return std::_Hash_impl::hash(__s.data(),
848 __s.length() *
sizeof(
char32_t)); }
855 inline namespace literals
857 inline namespace string_view_literals
859#pragma GCC diagnostic push
860#pragma GCC diagnostic ignored "-Wliteral-suffix"
861 inline constexpr basic_string_view<char>
862 operator""sv(
const char* __str,
size_t __len)
noexcept
863 {
return basic_string_view<char>{__str, __len}; }
865 inline constexpr basic_string_view<wchar_t>
866 operator""sv(
const wchar_t* __str,
size_t __len)
noexcept
867 {
return basic_string_view<wchar_t>{__str, __len}; }
869#ifdef _GLIBCXX_USE_CHAR8_T
870 inline constexpr basic_string_view<char8_t>
871 operator""sv(
const char8_t* __str,
size_t __len)
noexcept
872 {
return basic_string_view<char8_t>{__str, __len}; }
875 inline constexpr basic_string_view<char16_t>
876 operator""sv(
const char16_t* __str,
size_t __len)
noexcept
877 {
return basic_string_view<char16_t>{__str, __len}; }
879 inline constexpr basic_string_view<char32_t>
880 operator""sv(
const char32_t* __str,
size_t __len)
noexcept
881 {
return basic_string_view<char32_t>{__str, __len}; }
883#pragma GCC diagnostic pop
887#if __cpp_lib_concepts
891 template<
typename _CharT,
typename _Traits>
892 inline constexpr bool
893 enable_borrowed_range<basic_string_view<_CharT, _Traits>> =
true;
896 template<
typename _CharT,
typename _Traits>
897 inline constexpr bool
898 enable_view<basic_string_view<_CharT, _Traits>> =
true;
901_GLIBCXX_END_NAMESPACE_VERSION
904#include <bits/string_view.tcc>
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr _Tp * to_address(_Tp *__ptr) noexcept
Obtain address referenced by a pointer to an object.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
ISO C++ entities toplevel namespace is std.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
constexpr auto data(_Container &__cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data())
Return the data pointer of a container.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.
A non-owning reference to a string.