Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/c++/v1/string_view is written in an unsupported language. File is not indexed.

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP_STRING_VIEW
0011 #define _LIBCPP_STRING_VIEW
0012 
0013 // clang-format off
0014 
0015 /*
0016 
0017     string_view synopsis
0018 
0019 #include <compare>
0020 
0021 namespace std {
0022 
0023     // 7.2, Class template basic_string_view
0024     template<class charT, class traits = char_traits<charT>>
0025         class basic_string_view;
0026 
0027     template<class charT, class traits>
0028     inline constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true;
0029 
0030     template<class charT, class traits>
0031     inline constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true;  // C++20
0032 
0033     // 7.9, basic_string_view non-member comparison functions
0034     template<class charT, class traits>
0035     constexpr bool operator==(basic_string_view<charT, traits> x,
0036                               basic_string_view<charT, traits> y) noexcept;
0037     template<class charT, class traits>                                                            // Removed in C++20
0038     constexpr bool operator!=(basic_string_view<charT, traits> x,
0039                               basic_string_view<charT, traits> y) noexcept;
0040     template<class charT, class traits>                                                            // Removed in C++20
0041     constexpr bool operator< (basic_string_view<charT, traits> x,
0042                                  basic_string_view<charT, traits> y) noexcept;
0043     template<class charT, class traits>                                                            // Removed in C++20
0044     constexpr bool operator> (basic_string_view<charT, traits> x,
0045                               basic_string_view<charT, traits> y) noexcept;
0046     template<class charT, class traits>                                                            // Removed in C++20
0047     constexpr bool operator<=(basic_string_view<charT, traits> x,
0048                                  basic_string_view<charT, traits> y) noexcept;
0049     template<class charT, class traits>                                                            // Removed in C++20
0050     constexpr bool operator>=(basic_string_view<charT, traits> x,
0051                               basic_string_view<charT, traits> y) noexcept;
0052     template<class charT, class traits>                                                            // Since C++20
0053     constexpr see below operator<=>(basic_string_view<charT, traits> x,
0054                                     basic_string_view<charT, traits> y) noexcept;
0055 
0056     // see below, sufficient additional overloads of comparison functions
0057 
0058     // 7.10, Inserters and extractors
0059     template<class charT, class traits>
0060       basic_ostream<charT, traits>&
0061         operator<<(basic_ostream<charT, traits>& os,
0062                    basic_string_view<charT, traits> str);
0063 
0064     // basic_string_view typedef names
0065     typedef basic_string_view<char> string_view;
0066     typedef basic_string_view<char8_t> u8string_view; // C++20
0067     typedef basic_string_view<char16_t> u16string_view;
0068     typedef basic_string_view<char32_t> u32string_view;
0069     typedef basic_string_view<wchar_t> wstring_view;
0070 
0071     template<class charT, class traits = char_traits<charT>>
0072     class basic_string_view {
0073       public:
0074       // types
0075       typedef traits traits_type;
0076       typedef charT value_type;
0077       typedef charT* pointer;
0078       typedef const charT* const_pointer;
0079       typedef charT& reference;
0080       typedef const charT& const_reference;
0081       typedef implementation-defined const_iterator;
0082       typedef const_iterator iterator;
0083       typedef reverse_iterator<const_iterator> const_reverse_iterator;
0084       typedef const_reverse_iterator reverse_iterator;
0085       typedef size_t size_type;
0086       typedef ptrdiff_t difference_type;
0087       static constexpr size_type npos = size_type(-1);
0088 
0089       // 7.3, basic_string_view constructors and assignment operators
0090       constexpr basic_string_view() noexcept;
0091       constexpr basic_string_view(const basic_string_view&) noexcept = default;
0092       basic_string_view& operator=(const basic_string_view&) noexcept = default;
0093       template<class Allocator>
0094       constexpr basic_string_view(const charT* str);
0095       basic_string_view(nullptr_t) = delete; // C++23
0096       constexpr basic_string_view(const charT* str, size_type len);
0097       template <class It, class End>
0098       constexpr basic_string_view(It begin, End end); // C++20
0099       template <class Range>
0100       constexpr basic_string_view(Range&& r); // C++23
0101 
0102       // 7.4, basic_string_view iterator support
0103       constexpr const_iterator begin() const noexcept;
0104       constexpr const_iterator end() const noexcept;
0105       constexpr const_iterator cbegin() const noexcept;
0106       constexpr const_iterator cend() const noexcept;
0107       const_reverse_iterator rbegin() const noexcept;
0108       const_reverse_iterator rend() const noexcept;
0109       const_reverse_iterator crbegin() const noexcept;
0110       const_reverse_iterator crend() const noexcept;
0111 
0112       // 7.5, basic_string_view capacity
0113       constexpr size_type size() const noexcept;
0114       constexpr size_type length() const noexcept;
0115       constexpr size_type max_size() const noexcept;
0116       constexpr bool empty() const noexcept;
0117 
0118       // 7.6, basic_string_view element access
0119       constexpr const_reference operator[](size_type pos) const;
0120       constexpr const_reference at(size_type pos) const;
0121       constexpr const_reference front() const;
0122       constexpr const_reference back() const;
0123       constexpr const_pointer data() const noexcept;
0124 
0125       // 7.7, basic_string_view modifiers
0126       constexpr void remove_prefix(size_type n);
0127       constexpr void remove_suffix(size_type n);
0128       constexpr void swap(basic_string_view& s) noexcept;
0129 
0130       size_type copy(charT* s, size_type n, size_type pos = 0) const;  // constexpr in C++20
0131 
0132       constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
0133       constexpr int compare(basic_string_view s) const noexcept;
0134       constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
0135       constexpr int compare(size_type pos1, size_type n1,
0136                             basic_string_view s, size_type pos2, size_type n2) const;
0137       constexpr int compare(const charT* s) const;
0138       constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
0139       constexpr int compare(size_type pos1, size_type n1,
0140                             const charT* s, size_type n2) const;
0141       constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
0142       constexpr size_type find(charT c, size_type pos = 0) const noexcept;
0143       constexpr size_type find(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
0144       constexpr size_type find(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
0145       constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
0146       constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
0147       constexpr size_type rfind(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
0148       constexpr size_type rfind(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
0149       constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
0150       constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
0151       constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
0152       constexpr size_type find_first_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
0153       constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
0154       constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
0155       constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
0156       constexpr size_type find_last_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
0157       constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
0158       constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
0159       constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
0160       constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
0161       constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
0162       constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
0163       constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
0164       constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
0165 
0166       constexpr bool starts_with(basic_string_view s) const noexcept; // C++20
0167       constexpr bool starts_with(charT c) const noexcept;             // C++20
0168       constexpr bool starts_with(const charT* s) const;               // C++20
0169       constexpr bool ends_with(basic_string_view s) const noexcept;   // C++20
0170       constexpr bool ends_with(charT c) const noexcept;               // C++20
0171       constexpr bool ends_with(const charT* s) const;                 // C++20
0172 
0173       constexpr bool contains(basic_string_view s) const noexcept; // C++23
0174       constexpr bool contains(charT c) const noexcept;             // C++23
0175       constexpr bool contains(const charT* s) const;               // C++23
0176 
0177      private:
0178       const_pointer data_;  // exposition only
0179       size_type     size_;  // exposition only
0180     };
0181 
0182   // basic_string_view deduction guides
0183   template<class It, class End>
0184     basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>; // C++20
0185   template<class Range>
0186     basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23
0187 
0188   // 7.11, Hash support
0189   template <class T> struct hash;
0190   template <> struct hash<string_view>;
0191   template <> struct hash<u8string_view>; // C++20
0192   template <> struct hash<u16string_view>;
0193   template <> struct hash<u32string_view>;
0194   template <> struct hash<wstring_view>;
0195 
0196   constexpr basic_string_view<char>     operator""sv(const char *str,     size_t len) noexcept;
0197   constexpr basic_string_view<wchar_t>  operator""sv(const wchar_t *str,  size_t len) noexcept;
0198   constexpr basic_string_view<char8_t>  operator""sv(const char8_t *str,  size_t len) noexcept; // C++20
0199   constexpr basic_string_view<char16_t> operator""sv(const char16_t *str, size_t len) noexcept;
0200   constexpr basic_string_view<char32_t> operator""sv(const char32_t *str, size_t len) noexcept;
0201 
0202 }  // namespace std
0203 
0204 */
0205 
0206 // clang-format on
0207 
0208 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0209 #  include <__cxx03/string_view>
0210 #else
0211 #  include <__algorithm/min.h>
0212 #  include <__assert>
0213 #  include <__config>
0214 #  include <__cstddef/nullptr_t.h>
0215 #  include <__cstddef/ptrdiff_t.h>
0216 #  include <__cstddef/size_t.h>
0217 #  include <__functional/hash.h>
0218 #  include <__functional/unary_function.h>
0219 #  include <__fwd/ostream.h>
0220 #  include <__fwd/string.h>
0221 #  include <__fwd/string_view.h>
0222 #  include <__iterator/bounded_iter.h>
0223 #  include <__iterator/concepts.h>
0224 #  include <__iterator/iterator_traits.h>
0225 #  include <__iterator/reverse_iterator.h>
0226 #  include <__iterator/wrap_iter.h>
0227 #  include <__memory/pointer_traits.h>
0228 #  include <__ranges/concepts.h>
0229 #  include <__ranges/data.h>
0230 #  include <__ranges/enable_borrowed_range.h>
0231 #  include <__ranges/enable_view.h>
0232 #  include <__ranges/size.h>
0233 #  include <__string/char_traits.h>
0234 #  include <__type_traits/is_array.h>
0235 #  include <__type_traits/is_convertible.h>
0236 #  include <__type_traits/is_same.h>
0237 #  include <__type_traits/is_standard_layout.h>
0238 #  include <__type_traits/is_trivial.h>
0239 #  include <__type_traits/remove_cvref.h>
0240 #  include <__type_traits/remove_reference.h>
0241 #  include <__type_traits/type_identity.h>
0242 #  include <iosfwd>
0243 #  include <limits>
0244 #  include <stdexcept>
0245 #  include <version>
0246 
0247 // standard-mandated includes
0248 
0249 // [iterator.range]
0250 #  include <__iterator/access.h>
0251 #  include <__iterator/data.h>
0252 #  include <__iterator/empty.h>
0253 #  include <__iterator/reverse_access.h>
0254 #  include <__iterator/size.h>
0255 
0256 // [string.view.synop]
0257 #  include <compare>
0258 
0259 #  if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0260 #    pragma GCC system_header
0261 #  endif
0262 
0263 _LIBCPP_PUSH_MACROS
0264 #  include <__undef_macros>
0265 
0266 _LIBCPP_BEGIN_NAMESPACE_STD
0267 
0268 // TODO: This is a workaround for some vendors to carry a downstream diff to accept `nullptr` in
0269 //       string_view constructors. This can be refactored when this exact form isn't needed anymore.
0270 template <class _Traits>
0271 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR inline size_t
0272 __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
0273   // This needs to be a single statement for C++11 constexpr
0274   return _LIBCPP_ASSERT_NON_NULL(
0275              __s != nullptr, "null pointer passed to non-null argument of char_traits<...>::length"),
0276          _Traits::length(__s);
0277 }
0278 
0279 template <class _CharT, class _Traits>
0280 class basic_string_view {
0281 public:
0282   // types
0283   using traits_type     = _Traits;
0284   using value_type      = _CharT;
0285   using pointer         = _CharT*;
0286   using const_pointer   = const _CharT*;
0287   using reference       = _CharT&;
0288   using const_reference = const _CharT&;
0289 #  if defined(_LIBCPP_ABI_BOUNDED_ITERATORS)
0290   using const_iterator = __bounded_iter<const_pointer>;
0291 #  elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW)
0292   using const_iterator = __wrap_iter<const_pointer>;
0293 #  else
0294   using const_iterator = const_pointer;
0295 #  endif
0296   using iterator                                = const_iterator;
0297   using const_reverse_iterator                  = std::reverse_iterator<const_iterator>;
0298   using reverse_iterator                        = const_reverse_iterator;
0299   using size_type                               = size_t;
0300   using difference_type                         = ptrdiff_t;
0301   static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
0302 
0303   static_assert(!is_array<value_type>::value, "Character type of basic_string_view must not be an array");
0304   static_assert(is_standard_layout<value_type>::value, "Character type of basic_string_view must be standard-layout");
0305   static_assert(is_trivial<value_type>::value, "Character type of basic_string_view must be trivial");
0306   static_assert(is_same<_CharT, typename traits_type::char_type>::value,
0307                 "traits_type::char_type must be the same type as CharT");
0308 
0309   // [string.view.cons], construct/copy
0310   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view() _NOEXCEPT : __data_(nullptr), __size_(0) {}
0311 
0312   _LIBCPP_HIDE_FROM_ABI basic_string_view(const basic_string_view&) _NOEXCEPT = default;
0313 
0314   _LIBCPP_HIDE_FROM_ABI basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
0315 
0316   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
0317       : __data_(__s),
0318         __size_(__len) {
0319 #  if _LIBCPP_STD_VER >= 14
0320     // Allocations must fit in `ptrdiff_t` for pointer arithmetic to work. If `__len` exceeds it, the input
0321     // range could not have been valid. Most likely the caller underflowed some arithmetic and inadvertently
0322     // passed in a negative length.
0323     _LIBCPP_ASSERT_VALID_INPUT_RANGE(
0324         __len <= static_cast<size_type>(numeric_limits<difference_type>::max()),
0325         "string_view::string_view(_CharT *, size_t): length does not fit in difference_type");
0326     _LIBCPP_ASSERT_NON_NULL(
0327         __len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
0328 #  endif
0329   }
0330 
0331 #  if _LIBCPP_STD_VER >= 20
0332   template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
0333     requires(is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>)
0334   constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end)
0335       : __data_(std::to_address(__begin)), __size_(__end - __begin) {
0336     _LIBCPP_ASSERT_VALID_INPUT_RANGE(
0337         (__end - __begin) >= 0, "std::string_view::string_view(iterator, sentinel) received invalid range");
0338   }
0339 #  endif // _LIBCPP_STD_VER >= 20
0340 
0341 #  if _LIBCPP_STD_VER >= 23
0342   template <class _Range>
0343     requires(!is_same_v<remove_cvref_t<_Range>, basic_string_view> && ranges::contiguous_range<_Range> &&
0344              ranges::sized_range<_Range> && is_same_v<ranges::range_value_t<_Range>, _CharT> &&
0345              !is_convertible_v<_Range, const _CharT*> &&
0346              (!requires(remove_cvref_t<_Range>& __d) { __d.operator std::basic_string_view<_CharT, _Traits>(); }))
0347   constexpr explicit _LIBCPP_HIDE_FROM_ABI basic_string_view(_Range&& __r)
0348       : __data_(ranges::data(__r)), __size_(ranges::size(__r)) {}
0349 #  endif // _LIBCPP_STD_VER >= 23
0350 
0351   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view(const _CharT* __s)
0352       : __data_(__s), __size_(std::__char_traits_length_checked<_Traits>(__s)) {}
0353 
0354 #  if _LIBCPP_STD_VER >= 23
0355   basic_string_view(nullptr_t) = delete;
0356 #  endif
0357 
0358   // [string.view.iterators], iterators
0359   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return cbegin(); }
0360 
0361   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return cend(); }
0362 
0363   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT {
0364 #  ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
0365     return std::__make_bounded_iter(data(), data(), data() + size());
0366 #  else
0367     return const_iterator(__data_);
0368 #  endif
0369   }
0370 
0371   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT {
0372 #  ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
0373     return std::__make_bounded_iter(data() + size(), data(), data() + size());
0374 #  else
0375     return const_iterator(__data_ + __size_);
0376 #  endif
0377   }
0378 
0379   _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT {
0380     return const_reverse_iterator(cend());
0381   }
0382 
0383   _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT {
0384     return const_reverse_iterator(cbegin());
0385   }
0386 
0387   _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT {
0388     return const_reverse_iterator(cend());
0389   }
0390 
0391   _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT {
0392     return const_reverse_iterator(cbegin());
0393   }
0394 
0395   // [string.view.capacity], capacity
0396   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; }
0397 
0398   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI size_type length() const _NOEXCEPT { return __size_; }
0399 
0400   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
0401     return numeric_limits<size_type>::max() / sizeof(value_type);
0402   }
0403 
0404   [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return __size_ == 0; }
0405 
0406   // [string.view.access], element access
0407   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __pos) const _NOEXCEPT {
0408     return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__pos < size(), "string_view[] index out of bounds"), __data_[__pos];
0409   }
0410 
0411   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __pos) const {
0412     return __pos >= size() ? (__throw_out_of_range("string_view::at"), __data_[0]) : __data_[__pos];
0413   }
0414 
0415   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT {
0416     return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::front(): string is empty"), __data_[0];
0417   }
0418 
0419   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT {
0420     return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::back(): string is empty"), __data_[__size_ - 1];
0421   }
0422 
0423   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_pointer data() const _NOEXCEPT { return __data_; }
0424 
0425   // [string.view.modifiers], modifiers:
0426   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI void remove_prefix(size_type __n) _NOEXCEPT {
0427     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n <= size(), "remove_prefix() can't remove more than size()");
0428     __data_ += __n;
0429     __size_ -= __n;
0430   }
0431 
0432   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI void remove_suffix(size_type __n) _NOEXCEPT {
0433     _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n <= size(), "remove_suffix() can't remove more than size()");
0434     __size_ -= __n;
0435   }
0436 
0437   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI void swap(basic_string_view& __other) _NOEXCEPT {
0438     const value_type* __p = __data_;
0439     __data_               = __other.__data_;
0440     __other.__data_       = __p;
0441 
0442     size_type __sz  = __size_;
0443     __size_         = __other.__size_;
0444     __other.__size_ = __sz;
0445   }
0446 
0447   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
0448   copy(_CharT* __s, size_type __n, size_type __pos = 0) const {
0449     if (__pos > size())
0450       __throw_out_of_range("string_view::copy");
0451     size_type __rlen = std::min(__n, size() - __pos);
0452     _Traits::copy(__s, data() + __pos, __rlen);
0453     return __rlen;
0454   }
0455 
0456   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view substr(size_type __pos = 0, size_type __n = npos) const {
0457     // Use the `__assume_valid` form of the constructor to avoid an unnecessary check. Any substring of a view is a
0458     // valid view. In particular, `size()` is known to be smaller than `numeric_limits<difference_type>::max()`, so the
0459     // new size is also smaller. See also https://github.com/llvm/llvm-project/issues/91634.
0460     return __pos > size() ? (__throw_out_of_range("string_view::substr"), basic_string_view())
0461                           : basic_string_view(__assume_valid(), data() + __pos, std::min(__n, size() - __pos));
0462   }
0463 
0464   _LIBCPP_CONSTEXPR_SINCE_CXX14 int compare(basic_string_view __sv) const _NOEXCEPT {
0465     size_type __rlen = std::min(size(), __sv.size());
0466     int __retval     = _Traits::compare(data(), __sv.data(), __rlen);
0467     if (__retval == 0) // first __rlen chars matched
0468       __retval = size() == __sv.size() ? 0 : (size() < __sv.size() ? -1 : 1);
0469     return __retval;
0470   }
0471 
0472   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
0473   compare(size_type __pos1, size_type __n1, basic_string_view __sv) const {
0474     return substr(__pos1, __n1).compare(__sv);
0475   }
0476 
0477   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
0478   compare(size_type __pos1, size_type __n1, basic_string_view __sv, size_type __pos2, size_type __n2) const {
0479     return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
0480   }
0481 
0482   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int compare(const _CharT* __s) const _NOEXCEPT {
0483     return compare(basic_string_view(__s));
0484   }
0485 
0486   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
0487   compare(size_type __pos1, size_type __n1, const _CharT* __s) const {
0488     return substr(__pos1, __n1).compare(basic_string_view(__s));
0489   }
0490 
0491   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
0492   compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const {
0493     return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
0494   }
0495 
0496   // find
0497   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0498   find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
0499     _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
0500     return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __s.data(), __pos, __s.size());
0501   }
0502 
0503   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT {
0504     return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
0505   }
0506 
0507   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0508   find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
0509     _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
0510     return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
0511   }
0512 
0513   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0514   find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT {
0515     _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find(): received nullptr");
0516     return std::__str_find<value_type, size_type, traits_type, npos>(
0517         data(), size(), __s, __pos, traits_type::length(__s));
0518   }
0519 
0520   // rfind
0521   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0522   rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
0523     _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
0524     return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __s.data(), __pos, __s.size());
0525   }
0526 
0527   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0528   rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT {
0529     return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
0530   }
0531 
0532   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0533   rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
0534     _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
0535     return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
0536   }
0537 
0538   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0539   rfind(const _CharT* __s, size_type __pos = npos) const _NOEXCEPT {
0540     _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::rfind(): received nullptr");
0541     return std::__str_rfind<value_type, size_type, traits_type, npos>(
0542         data(), size(), __s, __pos, traits_type::length(__s));
0543   }
0544 
0545   // find_first_of
0546   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0547   find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
0548     _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
0549     return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
0550         data(), size(), __s.data(), __pos, __s.size());
0551   }
0552 
0553   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0554   find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT {
0555     return find(__c, __pos);
0556   }
0557 
0558   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0559   find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
0560     _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
0561     return std::__str_find_first_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
0562   }
0563 
0564   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0565   find_first_of(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT {
0566     _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_of(): received nullptr");
0567     return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
0568         data(), size(), __s, __pos, traits_type::length(__s));
0569   }
0570 
0571   // find_last_of
0572   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0573   find_last_of(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
0574     _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
0575     return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
0576         data(), size(), __s.data(), __pos, __s.size());
0577   }
0578 
0579   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0580   find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT {
0581     return rfind(__c, __pos);
0582   }
0583 
0584   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0585   find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
0586     _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
0587     return std::__str_find_last_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
0588   }
0589 
0590   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0591   find_last_of(const _CharT* __s, size_type __pos = npos) const _NOEXCEPT {
0592     _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_of(): received nullptr");
0593     return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
0594         data(), size(), __s, __pos, traits_type::length(__s));
0595   }
0596 
0597   // find_first_not_of
0598   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0599   find_first_not_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
0600     _LIBCPP_ASSERT_NON_NULL(
0601         __s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
0602     return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
0603         data(), size(), __s.data(), __pos, __s.size());
0604   }
0605 
0606   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0607   find_first_not_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT {
0608     return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
0609   }
0610 
0611   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0612   find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
0613     _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
0614     return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
0615   }
0616 
0617   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0618   find_first_not_of(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT {
0619     _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
0620     return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
0621         data(), size(), __s, __pos, traits_type::length(__s));
0622   }
0623 
0624   // find_last_not_of
0625   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0626   find_last_not_of(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
0627     _LIBCPP_ASSERT_NON_NULL(
0628         __s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
0629     return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
0630         data(), size(), __s.data(), __pos, __s.size());
0631   }
0632 
0633   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0634   find_last_not_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT {
0635     return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
0636   }
0637 
0638   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0639   find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
0640     _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
0641     return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
0642   }
0643 
0644   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0645   find_last_not_of(const _CharT* __s, size_type __pos = npos) const _NOEXCEPT {
0646     _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
0647     return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
0648         data(), size(), __s, __pos, traits_type::length(__s));
0649   }
0650 
0651 #  if _LIBCPP_STD_VER >= 20
0652   constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(basic_string_view __s) const noexcept {
0653     return size() >= __s.size() && compare(0, __s.size(), __s) == 0;
0654   }
0655 
0656   constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(value_type __c) const noexcept {
0657     return !empty() && _Traits::eq(front(), __c);
0658   }
0659 
0660   constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(const value_type* __s) const noexcept {
0661     return starts_with(basic_string_view(__s));
0662   }
0663 
0664   constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(basic_string_view __s) const noexcept {
0665     return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0;
0666   }
0667 
0668   constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(value_type __c) const noexcept {
0669     return !empty() && _Traits::eq(back(), __c);
0670   }
0671 
0672   constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(const value_type* __s) const noexcept {
0673     return ends_with(basic_string_view(__s));
0674   }
0675 #  endif
0676 
0677 #  if _LIBCPP_STD_VER >= 23
0678   constexpr _LIBCPP_HIDE_FROM_ABI bool contains(basic_string_view __sv) const noexcept { return find(__sv) != npos; }
0679 
0680   constexpr _LIBCPP_HIDE_FROM_ABI bool contains(value_type __c) const noexcept { return find(__c) != npos; }
0681 
0682   constexpr _LIBCPP_HIDE_FROM_ABI bool contains(const value_type* __s) const { return find(__s) != npos; }
0683 #  endif
0684 
0685 private:
0686   struct __assume_valid {};
0687 
0688   // This is the same as the pointer and length constructor, but without the additional hardening checks. It is intended
0689   // for use within the class, when the class invariants already guarantee the resulting object is valid. The compiler
0690   // usually cannot eliminate the redundant checks because it does not know class invariants.
0691   _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
0692   basic_string_view(__assume_valid, const _CharT* __s, size_type __len) _NOEXCEPT
0693       : __data_(__s),
0694         __size_(__len) {}
0695 
0696   const value_type* __data_;
0697   size_type __size_;
0698 
0699   template <class, class, class>
0700   friend class basic_string;
0701 };
0702 _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_string_view);
0703 
0704 #  if _LIBCPP_STD_VER >= 20
0705 template <class _CharT, class _Traits>
0706 inline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true;
0707 
0708 template <class _CharT, class _Traits>
0709 inline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true;
0710 #  endif // _LIBCPP_STD_VER >= 20
0711 
0712 // [string.view.deduct]
0713 
0714 #  if _LIBCPP_STD_VER >= 20
0715 template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
0716 basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
0717 #  endif // _LIBCPP_STD_VER >= 20
0718 
0719 #  if _LIBCPP_STD_VER >= 23
0720 template <ranges::contiguous_range _Range>
0721 basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>;
0722 #  endif
0723 
0724 // [string.view.comparison]
0725 
0726 // The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details.
0727 // This applies to the other sufficient overloads below for the other comparison operators.
0728 template <class _CharT, class _Traits, int = 1>
0729 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0730 operator==(basic_string_view<_CharT, _Traits> __lhs,
0731            __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
0732   if (__lhs.size() != __rhs.size())
0733     return false;
0734   return __lhs.compare(__rhs) == 0;
0735 }
0736 
0737 #  if _LIBCPP_STD_VER >= 20
0738 
0739 template <class _CharT, class _Traits>
0740 _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(basic_string_view<_CharT, _Traits> __lhs,
0741                                                  type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) noexcept {
0742   if constexpr (requires { typename _Traits::comparison_category; }) {
0743     // [string.view]/4
0744     static_assert(
0745         __comparison_category<typename _Traits::comparison_category>, "return type is not a comparison category type");
0746     return static_cast<typename _Traits::comparison_category>(__lhs.compare(__rhs) <=> 0);
0747   } else {
0748     return static_cast<weak_ordering>(__lhs.compare(__rhs) <=> 0);
0749   }
0750 }
0751 
0752 #  else
0753 
0754 // operator ==
0755 
0756 template <class _CharT, class _Traits>
0757 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0758 operator==(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0759   if (__lhs.size() != __rhs.size())
0760     return false;
0761   return __lhs.compare(__rhs) == 0;
0762 }
0763 
0764 template <class _CharT, class _Traits, int = 2>
0765 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0766 operator==(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
0767            basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0768   return __lhs == __rhs;
0769 }
0770 
0771 // operator !=
0772 template <class _CharT, class _Traits>
0773 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0774 operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0775   return !(__lhs == __rhs);
0776 }
0777 
0778 template <class _CharT, class _Traits, int = 1>
0779 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0780 operator!=(basic_string_view<_CharT, _Traits> __lhs,
0781            __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
0782   return !(__lhs == __rhs);
0783 }
0784 
0785 template <class _CharT, class _Traits, int = 2>
0786 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0787 operator!=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
0788            basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0789   return !(__lhs == __rhs);
0790 }
0791 
0792 // operator <
0793 template <class _CharT, class _Traits>
0794 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0795 operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0796   return __lhs.compare(__rhs) < 0;
0797 }
0798 
0799 template <class _CharT, class _Traits, int = 1>
0800 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0801 operator<(basic_string_view<_CharT, _Traits> __lhs,
0802           __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
0803   return __lhs.compare(__rhs) < 0;
0804 }
0805 
0806 template <class _CharT, class _Traits, int = 2>
0807 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0808 operator<(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
0809           basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0810   return __lhs.compare(__rhs) < 0;
0811 }
0812 
0813 // operator >
0814 template <class _CharT, class _Traits>
0815 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0816 operator>(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0817   return __lhs.compare(__rhs) > 0;
0818 }
0819 
0820 template <class _CharT, class _Traits, int = 1>
0821 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0822 operator>(basic_string_view<_CharT, _Traits> __lhs,
0823           __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
0824   return __lhs.compare(__rhs) > 0;
0825 }
0826 
0827 template <class _CharT, class _Traits, int = 2>
0828 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0829 operator>(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
0830           basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0831   return __lhs.compare(__rhs) > 0;
0832 }
0833 
0834 // operator <=
0835 template <class _CharT, class _Traits>
0836 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0837 operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0838   return __lhs.compare(__rhs) <= 0;
0839 }
0840 
0841 template <class _CharT, class _Traits, int = 1>
0842 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0843 operator<=(basic_string_view<_CharT, _Traits> __lhs,
0844            __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
0845   return __lhs.compare(__rhs) <= 0;
0846 }
0847 
0848 template <class _CharT, class _Traits, int = 2>
0849 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0850 operator<=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
0851            basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0852   return __lhs.compare(__rhs) <= 0;
0853 }
0854 
0855 // operator >=
0856 template <class _CharT, class _Traits>
0857 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0858 operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0859   return __lhs.compare(__rhs) >= 0;
0860 }
0861 
0862 template <class _CharT, class _Traits, int = 1>
0863 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0864 operator>=(basic_string_view<_CharT, _Traits> __lhs,
0865            __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
0866   return __lhs.compare(__rhs) >= 0;
0867 }
0868 
0869 template <class _CharT, class _Traits, int = 2>
0870 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0871 operator>=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
0872            basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0873   return __lhs.compare(__rhs) >= 0;
0874 }
0875 
0876 #  endif //  _LIBCPP_STD_VER >= 20
0877 
0878 template <class _CharT, class _Traits>
0879 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0880 operator<<(basic_ostream<_CharT, _Traits>& __os, basic_string_view<_CharT, _Traits> __str);
0881 
0882 // [string.view.hash]
0883 template <class _CharT>
0884 struct __string_view_hash : public __unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t> {
0885   _LIBCPP_HIDE_FROM_ABI size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT {
0886     return std::__do_string_hash(__val.data(), __val.data() + __val.size());
0887   }
0888 };
0889 
0890 template <>
0891 struct hash<basic_string_view<char, char_traits<char> > > : __string_view_hash<char> {};
0892 
0893 #  if _LIBCPP_HAS_CHAR8_T
0894 template <>
0895 struct hash<basic_string_view<char8_t, char_traits<char8_t> > > : __string_view_hash<char8_t> {};
0896 #  endif
0897 
0898 template <>
0899 struct hash<basic_string_view<char16_t, char_traits<char16_t> > > : __string_view_hash<char16_t> {};
0900 
0901 template <>
0902 struct hash<basic_string_view<char32_t, char_traits<char32_t> > > : __string_view_hash<char32_t> {};
0903 
0904 #  if _LIBCPP_HAS_WIDE_CHARACTERS
0905 template <>
0906 struct hash<basic_string_view<wchar_t, char_traits<wchar_t> > > : __string_view_hash<wchar_t> {};
0907 #  endif
0908 
0909 #  if _LIBCPP_STD_VER >= 14
0910 inline namespace literals {
0911 inline namespace string_view_literals {
0912 inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<char> operator""sv(const char* __str, size_t __len) noexcept {
0913   return basic_string_view<char>(__str, __len);
0914 }
0915 
0916 #    if _LIBCPP_HAS_WIDE_CHARACTERS
0917 inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<wchar_t>
0918 operator""sv(const wchar_t* __str, size_t __len) noexcept {
0919   return basic_string_view<wchar_t>(__str, __len);
0920 }
0921 #    endif
0922 
0923 #    if _LIBCPP_HAS_CHAR8_T
0924 inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<char8_t>
0925 operator""sv(const char8_t* __str, size_t __len) noexcept {
0926   return basic_string_view<char8_t>(__str, __len);
0927 }
0928 #    endif
0929 
0930 inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<char16_t>
0931 operator""sv(const char16_t* __str, size_t __len) noexcept {
0932   return basic_string_view<char16_t>(__str, __len);
0933 }
0934 
0935 inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<char32_t>
0936 operator""sv(const char32_t* __str, size_t __len) noexcept {
0937   return basic_string_view<char32_t>(__str, __len);
0938 }
0939 } // namespace string_view_literals
0940 } // namespace literals
0941 #  endif
0942 _LIBCPP_END_NAMESPACE_STD
0943 
0944 _LIBCPP_POP_MACROS
0945 
0946 #  if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
0947 #    include <algorithm>
0948 #    include <concepts>
0949 #    include <cstdlib>
0950 #    include <iterator>
0951 #    include <type_traits>
0952 #  endif
0953 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0954 
0955 #endif // _LIBCPP_STRING_VIEW