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>();
170 && (!
requires {
typename _DRange::traits_type; }
171 || is_same_v<typename _DRange::traits_type, _Traits>)
188 constexpr const_iterator
189 begin()
const noexcept
190 {
return this->_M_str; }
193 constexpr const_iterator
195 {
return this->_M_str + this->_M_len; }
198 constexpr const_iterator
199 cbegin()
const noexcept
200 {
return this->_M_str; }
203 constexpr const_iterator
204 cend()
const noexcept
205 {
return this->_M_str + this->_M_len; }
209 rbegin()
const noexcept
214 rend()
const noexcept
219 crbegin()
const noexcept
224 crend()
const noexcept
231 size()
const noexcept
232 {
return this->_M_len; }
236 length()
const noexcept
241 max_size()
const noexcept
243 return (npos -
sizeof(size_type) -
sizeof(
void*))
244 /
sizeof(value_type) / 4;
249 empty()
const noexcept
250 {
return this->_M_len == 0; }
255 constexpr const_reference
256 operator[](size_type __pos)
const noexcept
258 __glibcxx_assert(__pos < this->_M_len);
259 return *(this->_M_str + __pos);
263 constexpr const_reference
264 at(size_type __pos)
const
267 __throw_out_of_range_fmt(__N(
"basic_string_view::at: __pos "
268 "(which is %zu) >= this->size() "
269 "(which is %zu)"), __pos, this->size());
270 return *(this->_M_str + __pos);
274 constexpr const_reference
275 front()
const noexcept
277 __glibcxx_assert(this->_M_len > 0);
278 return *this->_M_str;
282 constexpr const_reference
283 back()
const noexcept
285 __glibcxx_assert(this->_M_len > 0);
286 return *(this->_M_str + this->_M_len - 1);
290 constexpr const_pointer
291 data()
const noexcept
292 {
return this->_M_str; }
297 remove_prefix(size_type __n)
noexcept
299 __glibcxx_assert(this->_M_len >= __n);
305 remove_suffix(size_type __n)
noexcept
307 __glibcxx_assert(this->_M_len >= __n);
323 copy(_CharT* __str, size_type __n, size_type __pos = 0)
const
325 __glibcxx_requires_string_len(__str, __n);
326 __pos = std::__sv_check(size(), __pos,
"basic_string_view::copy");
327 const size_type __rlen = std::min<size_t>(__n, _M_len - __pos);
330 traits_type::copy(__str, data() + __pos, __rlen);
336 substr(size_type __pos = 0, size_type __n = npos)
const noexcept(
false)
338 __pos = std::__sv_check(size(), __pos,
"basic_string_view::substr");
339 const size_type __rlen = std::min<size_t>(__n, _M_len - __pos);
347 const size_type __rlen =
std::min(this->_M_len, __str._M_len);
348 int __ret = traits_type::compare(this->_M_str, __str._M_str, __rlen);
350 __ret = _S_compare(this->_M_len, __str._M_len);
357 {
return this->substr(__pos1, __n1).compare(__str); }
361 compare(size_type __pos1, size_type __n1,
364 return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2));
367 [[nodiscard, __gnu__::__nonnull__]]
369 compare(
const _CharT* __str)
const noexcept
372 [[nodiscard, __gnu__::__nonnull__]]
374 compare(size_type __pos1, size_type __n1,
const _CharT* __str)
const
379 compare(size_type __pos1, size_type __n1,
380 const _CharT* __str, size_type __n2)
const noexcept(
false)
382 return this->substr(__pos1, __n1)
386#ifdef __cpp_lib_starts_ends_with
390 {
return this->substr(0, __x.size()) == __x; }
394 starts_with(_CharT __x)
const noexcept
395 {
return !this->empty() && traits_type::eq(this->front(), __x); }
397 [[nodiscard, __gnu__::__nonnull__]]
399 starts_with(
const _CharT* __x)
const noexcept
406 const auto __len = this->size();
407 const auto __xlen = __x.size();
408 return __len >= __xlen
409 && traits_type::compare(end() - __xlen, __x.data(), __xlen) == 0;
414 ends_with(_CharT __x)
const noexcept
415 {
return !this->empty() && traits_type::eq(this->back(), __x); }
417 [[nodiscard, __gnu__::__nonnull__]]
419 ends_with(
const _CharT* __x)
const noexcept
423#if __cplusplus > 202002L
424#if _GLIBCXX_HOSTED && !defined(__cpp_lib_string_contains)
427# error "libstdc++ bug: string_contains not defined when it should be"
432 {
return this->find(__x) != npos; }
436 contains(_CharT __x)
const noexcept
437 {
return this->find(__x) != npos; }
439 [[nodiscard, __gnu__::__nonnull__]]
441 contains(
const _CharT* __x)
const noexcept
442 {
return this->find(__x) != npos; }
450 {
return this->find(__str._M_str, __pos, __str._M_len); }
454 find(_CharT __c, size_type __pos = 0)
const noexcept;
458 find(
const _CharT* __str, size_type __pos, size_type __n)
const noexcept;
460 [[nodiscard, __gnu__::__nonnull__]]
462 find(
const _CharT* __str, size_type __pos = 0)
const noexcept
463 {
return this->find(__str, __pos, traits_type::length(__str)); }
468 {
return this->rfind(__str._M_str, __pos, __str._M_len); }
472 rfind(_CharT __c, size_type __pos = npos)
const noexcept;
476 rfind(
const _CharT* __str, size_type __pos, size_type __n)
const noexcept;
478 [[nodiscard, __gnu__::__nonnull__]]
480 rfind(
const _CharT* __str, size_type __pos = npos)
const noexcept
481 {
return this->rfind(__str, __pos, traits_type::length(__str)); }
486 {
return this->find_first_of(__str._M_str, __pos, __str._M_len); }
490 find_first_of(_CharT __c, size_type __pos = 0)
const noexcept
491 {
return this->find(__c, __pos); }
495 find_first_of(
const _CharT* __str, size_type __pos,
496 size_type __n)
const noexcept;
498 [[nodiscard, __gnu__::__nonnull__]]
500 find_first_of(
const _CharT* __str, size_type __pos = 0)
const noexcept
501 {
return this->find_first_of(__str, __pos, traits_type::length(__str)); }
506 size_type __pos = npos)
const noexcept
507 {
return this->find_last_of(__str._M_str, __pos, __str._M_len); }
511 find_last_of(_CharT __c, size_type __pos=npos)
const noexcept
512 {
return this->rfind(__c, __pos); }
516 find_last_of(
const _CharT* __str, size_type __pos,
517 size_type __n)
const noexcept;
519 [[nodiscard, __gnu__::__nonnull__]]
521 find_last_of(
const _CharT* __str, size_type __pos = npos)
const noexcept
522 {
return this->find_last_of(__str, __pos, traits_type::length(__str)); }
527 size_type __pos = 0)
const noexcept
528 {
return this->find_first_not_of(__str._M_str, __pos, __str._M_len); }
532 find_first_not_of(_CharT __c, size_type __pos = 0)
const noexcept;
536 find_first_not_of(
const _CharT* __str,
537 size_type __pos, size_type __n)
const noexcept;
539 [[nodiscard, __gnu__::__nonnull__]]
541 find_first_not_of(
const _CharT* __str, size_type __pos = 0)
const noexcept
543 return this->find_first_not_of(__str, __pos,
544 traits_type::length(__str));
550 size_type __pos = npos)
const noexcept
551 {
return this->find_last_not_of(__str._M_str, __pos, __str._M_len); }
555 find_last_not_of(_CharT __c, size_type __pos = npos)
const noexcept;
559 find_last_not_of(
const _CharT* __str,
560 size_type __pos, size_type __n)
const noexcept;
562 [[nodiscard, __gnu__::__nonnull__]]
564 find_last_not_of(
const _CharT* __str,
565 size_type __pos = npos)
const noexcept
567 return this->find_last_not_of(__str, __pos,
568 traits_type::length(__str));
574 _S_compare(size_type __n1, size_type __n2)
noexcept
577 const difference_type __diff = __n1 - __n2;
578 if (__diff > __limits::__max)
579 return __limits::__max;
580 if (__diff < __limits::__min)
581 return __limits::__min;
582 return static_cast<int>(__diff);
586 const _CharT* _M_str;
589#if __cplusplus > 201703L && __cpp_lib_concepts && __cpp_deduction_guides
590 template<contiguous_iterator _It, sized_sentinel_for<_It> _End>
593#if __cplusplus > 202002L
594 template<ranges::contiguous_range _Range>
607 template<
typename _CharT,
typename _Traits>
613 {
return __x.size() == __y.size() && __x.compare(__y) == 0; }
615#if __cpp_lib_three_way_comparison
616 template<
typename _CharT,
typename _Traits>
619 operator<=>(basic_string_view<_CharT, _Traits> __x,
620 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
622 ->
decltype(__detail::__char_traits_cmp_cat<_Traits>(0))
623 {
return __detail::__char_traits_cmp_cat<_Traits>(__x.compare(__y)); }
625 template<
typename _CharT,
typename _Traits>
628 operator==(basic_string_view<_CharT, _Traits> __x,
629 basic_string_view<_CharT, _Traits> __y)
noexcept
630 {
return __x.size() == __y.size() && __x.compare(__y) == 0; }
632 template<
typename _CharT,
typename _Traits>
635 operator==(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
636 basic_string_view<_CharT, _Traits> __y)
noexcept
637 {
return __x.size() == __y.size() && __x.compare(__y) == 0; }
639 template<
typename _CharT,
typename _Traits>
642 operator!=(basic_string_view<_CharT, _Traits> __x,
643 basic_string_view<_CharT, _Traits> __y)
noexcept
644 {
return !(__x == __y); }
646 template<
typename _CharT,
typename _Traits>
649 operator!=(basic_string_view<_CharT, _Traits> __x,
650 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
652 {
return !(__x == __y); }
654 template<
typename _CharT,
typename _Traits>
657 operator!=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
658 basic_string_view<_CharT, _Traits> __y)
noexcept
659 {
return !(__x == __y); }
661 template<
typename _CharT,
typename _Traits>
664 operator< (basic_string_view<_CharT, _Traits> __x,
665 basic_string_view<_CharT, _Traits> __y)
noexcept
666 {
return __x.compare(__y) < 0; }
668 template<
typename _CharT,
typename _Traits>
671 operator< (basic_string_view<_CharT, _Traits> __x,
672 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
674 {
return __x.compare(__y) < 0; }
676 template<
typename _CharT,
typename _Traits>
679 operator< (__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
680 basic_string_view<_CharT, _Traits> __y)
noexcept
681 {
return __x.compare(__y) < 0; }
683 template<
typename _CharT,
typename _Traits>
686 operator> (basic_string_view<_CharT, _Traits> __x,
687 basic_string_view<_CharT, _Traits> __y)
noexcept
688 {
return __x.compare(__y) > 0; }
690 template<
typename _CharT,
typename _Traits>
693 operator> (basic_string_view<_CharT, _Traits> __x,
694 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
696 {
return __x.compare(__y) > 0; }
698 template<
typename _CharT,
typename _Traits>
701 operator> (__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
702 basic_string_view<_CharT, _Traits> __y)
noexcept
703 {
return __x.compare(__y) > 0; }
705 template<
typename _CharT,
typename _Traits>
708 operator<=(basic_string_view<_CharT, _Traits> __x,
709 basic_string_view<_CharT, _Traits> __y)
noexcept
710 {
return __x.compare(__y) <= 0; }
712 template<
typename _CharT,
typename _Traits>
715 operator<=(basic_string_view<_CharT, _Traits> __x,
716 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
718 {
return __x.compare(__y) <= 0; }
720 template<
typename _CharT,
typename _Traits>
723 operator<=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
724 basic_string_view<_CharT, _Traits> __y)
noexcept
725 {
return __x.compare(__y) <= 0; }
727 template<
typename _CharT,
typename _Traits>
730 operator>=(basic_string_view<_CharT, _Traits> __x,
731 basic_string_view<_CharT, _Traits> __y)
noexcept
732 {
return __x.compare(__y) >= 0; }
734 template<
typename _CharT,
typename _Traits>
737 operator>=(basic_string_view<_CharT, _Traits> __x,
738 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
740 {
return __x.compare(__y) >= 0; }
742 template<
typename _CharT,
typename _Traits>
745 operator>=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
746 basic_string_view<_CharT, _Traits> __y)
noexcept
747 {
return __x.compare(__y) >= 0; }
752 template<
typename _CharT,
typename _Traits>
753 inline basic_ostream<_CharT, _Traits>&
754 operator<<(basic_ostream<_CharT, _Traits>& __os,
755 basic_string_view<_CharT,_Traits> __str)
756 {
return __ostream_insert(__os, __str.data(), __str.size()); }
761 using string_view = basic_string_view<char>;
762 using wstring_view = basic_string_view<wchar_t>;
763#ifdef _GLIBCXX_USE_CHAR8_T
764 using u8string_view = basic_string_view<char8_t>;
766 using u16string_view = basic_string_view<char16_t>;
767 using u32string_view = basic_string_view<char32_t>;
771 template<
typename _Tp>
775 struct hash<string_view>
776 :
public __hash_base<size_t, string_view>
780 operator()(
const string_view& __str)
const noexcept
781 {
return std::_Hash_impl::hash(__str.data(), __str.length()); }
789 struct hash<wstring_view>
790 :
public __hash_base<size_t, wstring_view>
794 operator()(
const wstring_view& __s)
const noexcept
795 {
return std::_Hash_impl::hash(__s.data(),
796 __s.length() *
sizeof(
wchar_t)); }
803#ifdef _GLIBCXX_USE_CHAR8_T
805 struct hash<u8string_view>
806 :
public __hash_base<size_t, u8string_view>
810 operator()(
const u8string_view& __str)
const noexcept
811 {
return std::_Hash_impl::hash(__str.data(), __str.length()); }
820 struct hash<u16string_view>
821 :
public __hash_base<size_t, u16string_view>
825 operator()(
const u16string_view& __s)
const noexcept
826 {
return std::_Hash_impl::hash(__s.data(),
827 __s.length() *
sizeof(
char16_t)); }
835 struct hash<u32string_view>
836 :
public __hash_base<size_t, u32string_view>
840 operator()(
const u32string_view& __s)
const noexcept
841 {
return std::_Hash_impl::hash(__s.data(),
842 __s.length() *
sizeof(
char32_t)); }
849 inline namespace literals
851 inline namespace string_view_literals
853#pragma GCC diagnostic push
854#pragma GCC diagnostic ignored "-Wliteral-suffix"
855 inline constexpr basic_string_view<char>
856 operator""sv(
const char* __str,
size_t __len)
noexcept
857 {
return basic_string_view<char>{__str, __len}; }
859 inline constexpr basic_string_view<wchar_t>
860 operator""sv(
const wchar_t* __str,
size_t __len)
noexcept
861 {
return basic_string_view<wchar_t>{__str, __len}; }
863#ifdef _GLIBCXX_USE_CHAR8_T
864 inline constexpr basic_string_view<char8_t>
865 operator""sv(
const char8_t* __str,
size_t __len)
noexcept
866 {
return basic_string_view<char8_t>{__str, __len}; }
869 inline constexpr basic_string_view<char16_t>
870 operator""sv(
const char16_t* __str,
size_t __len)
noexcept
871 {
return basic_string_view<char16_t>{__str, __len}; }
873 inline constexpr basic_string_view<char32_t>
874 operator""sv(
const char32_t* __str,
size_t __len)
noexcept
875 {
return basic_string_view<char32_t>{__str, __len}; }
877#pragma GCC diagnostic pop
881#if __cpp_lib_concepts
885 template<
typename _CharT,
typename _Traits>
886 inline constexpr bool
887 enable_borrowed_range<basic_string_view<_CharT, _Traits>> =
true;
890 template<
typename _CharT,
typename _Traits>
891 inline constexpr bool
892 enable_view<basic_string_view<_CharT, _Traits>> =
true;
895_GLIBCXX_END_NAMESPACE_VERSION
898#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.