Warning, /include/c++/v1/__cxx03/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___CXX03_STRING_VIEW
0011 #define _LIBCPP___CXX03_STRING_VIEW
0012
0013 // clang-format off
0014
0015 /*
0016
0017 string_view synopsis
0018
0019 #include <__cxx03/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 #include <__cxx03/__algorithm/min.h>
0209 #include <__cxx03/__assert>
0210 #include <__cxx03/__config>
0211 #include <__cxx03/__functional/hash.h>
0212 #include <__cxx03/__functional/unary_function.h>
0213 #include <__cxx03/__fwd/ostream.h>
0214 #include <__cxx03/__fwd/string_view.h>
0215 #include <__cxx03/__iterator/bounded_iter.h>
0216 #include <__cxx03/__iterator/concepts.h>
0217 #include <__cxx03/__iterator/iterator_traits.h>
0218 #include <__cxx03/__iterator/reverse_iterator.h>
0219 #include <__cxx03/__iterator/wrap_iter.h>
0220 #include <__cxx03/__memory/pointer_traits.h>
0221 #include <__cxx03/__ranges/concepts.h>
0222 #include <__cxx03/__ranges/data.h>
0223 #include <__cxx03/__ranges/enable_borrowed_range.h>
0224 #include <__cxx03/__ranges/enable_view.h>
0225 #include <__cxx03/__ranges/size.h>
0226 #include <__cxx03/__string/char_traits.h>
0227 #include <__cxx03/__type_traits/is_array.h>
0228 #include <__cxx03/__type_traits/is_convertible.h>
0229 #include <__cxx03/__type_traits/is_same.h>
0230 #include <__cxx03/__type_traits/is_standard_layout.h>
0231 #include <__cxx03/__type_traits/is_trivial.h>
0232 #include <__cxx03/__type_traits/remove_cvref.h>
0233 #include <__cxx03/__type_traits/remove_reference.h>
0234 #include <__cxx03/__type_traits/type_identity.h>
0235 #include <__cxx03/cstddef>
0236 #include <__cxx03/iosfwd>
0237 #include <__cxx03/limits>
0238 #include <__cxx03/stdexcept>
0239 #include <__cxx03/version>
0240
0241 // standard-mandated includes
0242
0243 // [iterator.range]
0244 #include <__cxx03/__iterator/access.h>
0245 #include <__cxx03/__iterator/data.h>
0246 #include <__cxx03/__iterator/empty.h>
0247 #include <__cxx03/__iterator/reverse_access.h>
0248 #include <__cxx03/__iterator/size.h>
0249
0250 // [string.view.synop]
0251 #include <__cxx03/compare>
0252
0253 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0254 # pragma GCC system_header
0255 #endif
0256
0257 _LIBCPP_PUSH_MACROS
0258 #include <__cxx03/__undef_macros>
0259
0260 _LIBCPP_BEGIN_NAMESPACE_STD
0261
0262 // TODO: This is a workaround for some vendors to carry a downstream diff to accept `nullptr` in
0263 // string_view constructors. This can be refactored when this exact form isn't needed anymore.
0264 template <class _Traits>
0265 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR inline size_t
0266 __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
0267 // This needs to be a single statement for C++11 constexpr
0268 return _LIBCPP_ASSERT_NON_NULL(
0269 __s != nullptr, "null pointer passed to non-null argument of char_traits<...>::length"),
0270 _Traits::length(__s);
0271 }
0272
0273 template <class _CharT, class _Traits>
0274 class basic_string_view {
0275 public:
0276 // types
0277 using traits_type = _Traits;
0278 using value_type = _CharT;
0279 using pointer = _CharT*;
0280 using const_pointer = const _CharT*;
0281 using reference = _CharT&;
0282 using const_reference = const _CharT&;
0283 #if defined(_LIBCPP_ABI_BOUNDED_ITERATORS)
0284 using const_iterator = __bounded_iter<const_pointer>;
0285 #elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW)
0286 using const_iterator = __wrap_iter<const_pointer>;
0287 #else
0288 using const_iterator = const_pointer;
0289 #endif
0290 using iterator = const_iterator;
0291 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
0292 using reverse_iterator = const_reverse_iterator;
0293 using size_type = size_t;
0294 using difference_type = ptrdiff_t;
0295 static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
0296
0297 static_assert(!is_array<value_type>::value, "Character type of basic_string_view must not be an array");
0298 static_assert(is_standard_layout<value_type>::value, "Character type of basic_string_view must be standard-layout");
0299 static_assert(is_trivial<value_type>::value, "Character type of basic_string_view must be trivial");
0300 static_assert(is_same<_CharT, typename traits_type::char_type>::value,
0301 "traits_type::char_type must be the same type as CharT");
0302
0303 // [string.view.cons], construct/copy
0304 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view() _NOEXCEPT : __data_(nullptr), __size_(0) {}
0305
0306 _LIBCPP_HIDE_FROM_ABI basic_string_view(const basic_string_view&) _NOEXCEPT = default;
0307
0308 _LIBCPP_HIDE_FROM_ABI basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
0309
0310 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
0311 : __data_(__s),
0312 __size_(__len) {
0313 #if _LIBCPP_STD_VER >= 14
0314 // Allocations must fit in `ptrdiff_t` for pointer arithmetic to work. If `__len` exceeds it, the input
0315 // range could not have been valid. Most likely the caller underflowed some arithmetic and inadvertently
0316 // passed in a negative length.
0317 _LIBCPP_ASSERT_VALID_INPUT_RANGE(
0318 __len <= static_cast<size_type>(numeric_limits<difference_type>::max()),
0319 "string_view::string_view(_CharT *, size_t): length does not fit in difference_type");
0320 _LIBCPP_ASSERT_NON_NULL(
0321 __len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
0322 #endif
0323 }
0324
0325 #if _LIBCPP_STD_VER >= 20
0326 template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
0327 requires(is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>)
0328 constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end)
0329 : __data_(std::to_address(__begin)), __size_(__end - __begin) {
0330 _LIBCPP_ASSERT_VALID_INPUT_RANGE(
0331 (__end - __begin) >= 0, "std::string_view::string_view(iterator, sentinel) received invalid range");
0332 }
0333 #endif // _LIBCPP_STD_VER >= 20
0334
0335 #if _LIBCPP_STD_VER >= 23
0336 template <class _Range>
0337 requires(!is_same_v<remove_cvref_t<_Range>, basic_string_view> && ranges::contiguous_range<_Range> &&
0338 ranges::sized_range<_Range> && is_same_v<ranges::range_value_t<_Range>, _CharT> &&
0339 !is_convertible_v<_Range, const _CharT*> &&
0340 (!requires(remove_cvref_t<_Range>& __d) { __d.operator std::basic_string_view<_CharT, _Traits>(); }))
0341 constexpr explicit _LIBCPP_HIDE_FROM_ABI basic_string_view(_Range&& __r)
0342 : __data_(ranges::data(__r)), __size_(ranges::size(__r)) {}
0343 #endif // _LIBCPP_STD_VER >= 23
0344
0345 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view(const _CharT* __s)
0346 : __data_(__s), __size_(std::__char_traits_length_checked<_Traits>(__s)) {}
0347
0348 #if _LIBCPP_STD_VER >= 23
0349 basic_string_view(nullptr_t) = delete;
0350 #endif
0351
0352 // [string.view.iterators], iterators
0353 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return cbegin(); }
0354
0355 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return cend(); }
0356
0357 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT {
0358 #ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
0359 return std::__make_bounded_iter(data(), data(), data() + size());
0360 #else
0361 return const_iterator(__data_);
0362 #endif
0363 }
0364
0365 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT {
0366 #ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
0367 return std::__make_bounded_iter(data() + size(), data(), data() + size());
0368 #else
0369 return const_iterator(__data_ + __size_);
0370 #endif
0371 }
0372
0373 _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT {
0374 return const_reverse_iterator(cend());
0375 }
0376
0377 _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT {
0378 return const_reverse_iterator(cbegin());
0379 }
0380
0381 _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT {
0382 return const_reverse_iterator(cend());
0383 }
0384
0385 _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT {
0386 return const_reverse_iterator(cbegin());
0387 }
0388
0389 // [string.view.capacity], capacity
0390 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; }
0391
0392 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI size_type length() const _NOEXCEPT { return __size_; }
0393
0394 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
0395 return numeric_limits<size_type>::max() / sizeof(value_type);
0396 }
0397
0398 _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT { return __size_ == 0; }
0399
0400 // [string.view.access], element access
0401 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __pos) const _NOEXCEPT {
0402 return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__pos < size(), "string_view[] index out of bounds"), __data_[__pos];
0403 }
0404
0405 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __pos) const {
0406 return __pos >= size() ? (__throw_out_of_range("string_view::at"), __data_[0]) : __data_[__pos];
0407 }
0408
0409 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT {
0410 return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::front(): string is empty"), __data_[0];
0411 }
0412
0413 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT {
0414 return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::back(): string is empty"), __data_[__size_ - 1];
0415 }
0416
0417 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI const_pointer data() const _NOEXCEPT { return __data_; }
0418
0419 // [string.view.modifiers], modifiers:
0420 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI void remove_prefix(size_type __n) _NOEXCEPT {
0421 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n <= size(), "remove_prefix() can't remove more than size()");
0422 __data_ += __n;
0423 __size_ -= __n;
0424 }
0425
0426 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI void remove_suffix(size_type __n) _NOEXCEPT {
0427 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n <= size(), "remove_suffix() can't remove more than size()");
0428 __size_ -= __n;
0429 }
0430
0431 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI void swap(basic_string_view& __other) _NOEXCEPT {
0432 const value_type* __p = __data_;
0433 __data_ = __other.__data_;
0434 __other.__data_ = __p;
0435
0436 size_type __sz = __size_;
0437 __size_ = __other.__size_;
0438 __other.__size_ = __sz;
0439 }
0440
0441 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 size_type
0442 copy(_CharT* __s, size_type __n, size_type __pos = 0) const {
0443 if (__pos > size())
0444 __throw_out_of_range("string_view::copy");
0445 size_type __rlen = std::min(__n, size() - __pos);
0446 _Traits::copy(__s, data() + __pos, __rlen);
0447 return __rlen;
0448 }
0449
0450 _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI basic_string_view substr(size_type __pos = 0, size_type __n = npos) const {
0451 return __pos > size() ? (__throw_out_of_range("string_view::substr"), basic_string_view())
0452 : basic_string_view(data() + __pos, std::min(__n, size() - __pos));
0453 }
0454
0455 _LIBCPP_CONSTEXPR_SINCE_CXX14 int compare(basic_string_view __sv) const _NOEXCEPT {
0456 size_type __rlen = std::min(size(), __sv.size());
0457 int __retval = _Traits::compare(data(), __sv.data(), __rlen);
0458 if (__retval == 0) // first __rlen chars matched
0459 __retval = size() == __sv.size() ? 0 : (size() < __sv.size() ? -1 : 1);
0460 return __retval;
0461 }
0462
0463 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
0464 compare(size_type __pos1, size_type __n1, basic_string_view __sv) const {
0465 return substr(__pos1, __n1).compare(__sv);
0466 }
0467
0468 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
0469 compare(size_type __pos1, size_type __n1, basic_string_view __sv, size_type __pos2, size_type __n2) const {
0470 return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
0471 }
0472
0473 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int compare(const _CharT* __s) const _NOEXCEPT {
0474 return compare(basic_string_view(__s));
0475 }
0476
0477 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
0478 compare(size_type __pos1, size_type __n1, const _CharT* __s) const {
0479 return substr(__pos1, __n1).compare(basic_string_view(__s));
0480 }
0481
0482 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI int
0483 compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const {
0484 return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
0485 }
0486
0487 // find
0488 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0489 find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
0490 _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
0491 return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __s.data(), __pos, __s.size());
0492 }
0493
0494 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT {
0495 return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
0496 }
0497
0498 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0499 find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
0500 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
0501 return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
0502 }
0503
0504 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0505 find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT {
0506 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find(): received nullptr");
0507 return std::__str_find<value_type, size_type, traits_type, npos>(
0508 data(), size(), __s, __pos, traits_type::length(__s));
0509 }
0510
0511 // rfind
0512 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0513 rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
0514 _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
0515 return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __s.data(), __pos, __s.size());
0516 }
0517
0518 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0519 rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT {
0520 return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
0521 }
0522
0523 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0524 rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
0525 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
0526 return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
0527 }
0528
0529 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0530 rfind(const _CharT* __s, size_type __pos = npos) const _NOEXCEPT {
0531 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::rfind(): received nullptr");
0532 return std::__str_rfind<value_type, size_type, traits_type, npos>(
0533 data(), size(), __s, __pos, traits_type::length(__s));
0534 }
0535
0536 // find_first_of
0537 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0538 find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
0539 _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
0540 return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
0541 data(), size(), __s.data(), __pos, __s.size());
0542 }
0543
0544 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0545 find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT {
0546 return find(__c, __pos);
0547 }
0548
0549 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0550 find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
0551 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
0552 return std::__str_find_first_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
0553 }
0554
0555 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0556 find_first_of(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT {
0557 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_of(): received nullptr");
0558 return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
0559 data(), size(), __s, __pos, traits_type::length(__s));
0560 }
0561
0562 // find_last_of
0563 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0564 find_last_of(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
0565 _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
0566 return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
0567 data(), size(), __s.data(), __pos, __s.size());
0568 }
0569
0570 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0571 find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT {
0572 return rfind(__c, __pos);
0573 }
0574
0575 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0576 find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
0577 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
0578 return std::__str_find_last_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
0579 }
0580
0581 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0582 find_last_of(const _CharT* __s, size_type __pos = npos) const _NOEXCEPT {
0583 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_of(): received nullptr");
0584 return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
0585 data(), size(), __s, __pos, traits_type::length(__s));
0586 }
0587
0588 // find_first_not_of
0589 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0590 find_first_not_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
0591 _LIBCPP_ASSERT_NON_NULL(
0592 __s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
0593 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
0594 data(), size(), __s.data(), __pos, __s.size());
0595 }
0596
0597 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0598 find_first_not_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT {
0599 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
0600 }
0601
0602 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0603 find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
0604 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
0605 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
0606 }
0607
0608 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0609 find_first_not_of(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT {
0610 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
0611 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
0612 data(), size(), __s, __pos, traits_type::length(__s));
0613 }
0614
0615 // find_last_not_of
0616 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0617 find_last_not_of(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
0618 _LIBCPP_ASSERT_NON_NULL(
0619 __s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
0620 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
0621 data(), size(), __s.data(), __pos, __s.size());
0622 }
0623
0624 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0625 find_last_not_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT {
0626 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
0627 }
0628
0629 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0630 find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
0631 _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
0632 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
0633 }
0634
0635 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI size_type
0636 find_last_not_of(const _CharT* __s, size_type __pos = npos) const _NOEXCEPT {
0637 _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
0638 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
0639 data(), size(), __s, __pos, traits_type::length(__s));
0640 }
0641
0642 #if _LIBCPP_STD_VER >= 20
0643 constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(basic_string_view __s) const noexcept {
0644 return size() >= __s.size() && compare(0, __s.size(), __s) == 0;
0645 }
0646
0647 constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(value_type __c) const noexcept {
0648 return !empty() && _Traits::eq(front(), __c);
0649 }
0650
0651 constexpr _LIBCPP_HIDE_FROM_ABI bool starts_with(const value_type* __s) const noexcept {
0652 return starts_with(basic_string_view(__s));
0653 }
0654
0655 constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(basic_string_view __s) const noexcept {
0656 return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0;
0657 }
0658
0659 constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(value_type __c) const noexcept {
0660 return !empty() && _Traits::eq(back(), __c);
0661 }
0662
0663 constexpr _LIBCPP_HIDE_FROM_ABI bool ends_with(const value_type* __s) const noexcept {
0664 return ends_with(basic_string_view(__s));
0665 }
0666 #endif
0667
0668 #if _LIBCPP_STD_VER >= 23
0669 constexpr _LIBCPP_HIDE_FROM_ABI bool contains(basic_string_view __sv) const noexcept { return find(__sv) != npos; }
0670
0671 constexpr _LIBCPP_HIDE_FROM_ABI bool contains(value_type __c) const noexcept { return find(__c) != npos; }
0672
0673 constexpr _LIBCPP_HIDE_FROM_ABI bool contains(const value_type* __s) const { return find(__s) != npos; }
0674 #endif
0675
0676 private:
0677 const value_type* __data_;
0678 size_type __size_;
0679 };
0680 _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_string_view);
0681
0682 #if _LIBCPP_STD_VER >= 20
0683 template <class _CharT, class _Traits>
0684 inline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true;
0685
0686 template <class _CharT, class _Traits>
0687 inline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true;
0688 #endif // _LIBCPP_STD_VER >= 20
0689
0690 // [string.view.deduct]
0691
0692 #if _LIBCPP_STD_VER >= 20
0693 template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
0694 basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
0695 #endif // _LIBCPP_STD_VER >= 20
0696
0697 #if _LIBCPP_STD_VER >= 23
0698 template <ranges::contiguous_range _Range>
0699 basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>;
0700 #endif
0701
0702 // [string.view.comparison]
0703
0704 #if _LIBCPP_STD_VER >= 20
0705
0706 template <class _CharT, class _Traits>
0707 _LIBCPP_HIDE_FROM_ABI constexpr bool operator==(basic_string_view<_CharT, _Traits> __lhs,
0708 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) noexcept {
0709 if (__lhs.size() != __rhs.size())
0710 return false;
0711 return __lhs.compare(__rhs) == 0;
0712 }
0713
0714 template <class _CharT, class _Traits>
0715 _LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(basic_string_view<_CharT, _Traits> __lhs,
0716 type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) noexcept {
0717 if constexpr (requires { typename _Traits::comparison_category; }) {
0718 // [string.view]/4
0719 static_assert(
0720 __comparison_category<typename _Traits::comparison_category>, "return type is not a comparison category type");
0721 return static_cast<typename _Traits::comparison_category>(__lhs.compare(__rhs) <=> 0);
0722 } else {
0723 return static_cast<weak_ordering>(__lhs.compare(__rhs) <=> 0);
0724 }
0725 }
0726
0727 #else
0728
0729 // operator ==
0730
0731 template <class _CharT, class _Traits>
0732 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0733 operator==(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0734 if (__lhs.size() != __rhs.size())
0735 return false;
0736 return __lhs.compare(__rhs) == 0;
0737 }
0738
0739 // The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details.
0740 // This applies to the other sufficient overloads below for the other comparison operators.
0741 template <class _CharT, class _Traits, int = 1>
0742 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0743 operator==(basic_string_view<_CharT, _Traits> __lhs,
0744 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
0745 if (__lhs.size() != __rhs.size())
0746 return false;
0747 return __lhs.compare(__rhs) == 0;
0748 }
0749
0750 template <class _CharT, class _Traits, int = 2>
0751 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0752 operator==(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
0753 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0754 if (__lhs.size() != __rhs.size())
0755 return false;
0756 return __lhs.compare(__rhs) == 0;
0757 }
0758
0759 // operator !=
0760 template <class _CharT, class _Traits>
0761 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0762 operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0763 if (__lhs.size() != __rhs.size())
0764 return true;
0765 return __lhs.compare(__rhs) != 0;
0766 }
0767
0768 template <class _CharT, class _Traits, int = 1>
0769 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0770 operator!=(basic_string_view<_CharT, _Traits> __lhs,
0771 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
0772 if (__lhs.size() != __rhs.size())
0773 return true;
0774 return __lhs.compare(__rhs) != 0;
0775 }
0776
0777 template <class _CharT, class _Traits, int = 2>
0778 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0779 operator!=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
0780 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0781 if (__lhs.size() != __rhs.size())
0782 return true;
0783 return __lhs.compare(__rhs) != 0;
0784 }
0785
0786 // operator <
0787 template <class _CharT, class _Traits>
0788 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0789 operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0790 return __lhs.compare(__rhs) < 0;
0791 }
0792
0793 template <class _CharT, class _Traits, int = 1>
0794 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0795 operator<(basic_string_view<_CharT, _Traits> __lhs,
0796 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
0797 return __lhs.compare(__rhs) < 0;
0798 }
0799
0800 template <class _CharT, class _Traits, int = 2>
0801 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0802 operator<(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
0803 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0804 return __lhs.compare(__rhs) < 0;
0805 }
0806
0807 // operator >
0808 template <class _CharT, class _Traits>
0809 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0810 operator>(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0811 return __lhs.compare(__rhs) > 0;
0812 }
0813
0814 template <class _CharT, class _Traits, int = 1>
0815 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0816 operator>(basic_string_view<_CharT, _Traits> __lhs,
0817 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
0818 return __lhs.compare(__rhs) > 0;
0819 }
0820
0821 template <class _CharT, class _Traits, int = 2>
0822 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0823 operator>(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
0824 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0825 return __lhs.compare(__rhs) > 0;
0826 }
0827
0828 // operator <=
0829 template <class _CharT, class _Traits>
0830 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0831 operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0832 return __lhs.compare(__rhs) <= 0;
0833 }
0834
0835 template <class _CharT, class _Traits, int = 1>
0836 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0837 operator<=(basic_string_view<_CharT, _Traits> __lhs,
0838 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
0839 return __lhs.compare(__rhs) <= 0;
0840 }
0841
0842 template <class _CharT, class _Traits, int = 2>
0843 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0844 operator<=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
0845 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0846 return __lhs.compare(__rhs) <= 0;
0847 }
0848
0849 // operator >=
0850 template <class _CharT, class _Traits>
0851 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0852 operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0853 return __lhs.compare(__rhs) >= 0;
0854 }
0855
0856 template <class _CharT, class _Traits, int = 1>
0857 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0858 operator>=(basic_string_view<_CharT, _Traits> __lhs,
0859 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
0860 return __lhs.compare(__rhs) >= 0;
0861 }
0862
0863 template <class _CharT, class _Traits, int = 2>
0864 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
0865 operator>=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
0866 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
0867 return __lhs.compare(__rhs) >= 0;
0868 }
0869
0870 #endif // _LIBCPP_STD_VER >= 20
0871
0872 template <class _CharT, class _Traits>
0873 _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
0874 operator<<(basic_ostream<_CharT, _Traits>& __os, basic_string_view<_CharT, _Traits> __str);
0875
0876 // [string.view.hash]
0877 template <class _CharT>
0878 struct __string_view_hash : public __unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t> {
0879 _LIBCPP_HIDE_FROM_ABI size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT {
0880 return std::__do_string_hash(__val.data(), __val.data() + __val.size());
0881 }
0882 };
0883
0884 template <>
0885 struct hash<basic_string_view<char, char_traits<char> > > : __string_view_hash<char> {};
0886
0887 #ifndef _LIBCPP_HAS_NO_CHAR8_T
0888 template <>
0889 struct hash<basic_string_view<char8_t, char_traits<char8_t> > > : __string_view_hash<char8_t> {};
0890 #endif
0891
0892 template <>
0893 struct hash<basic_string_view<char16_t, char_traits<char16_t> > > : __string_view_hash<char16_t> {};
0894
0895 template <>
0896 struct hash<basic_string_view<char32_t, char_traits<char32_t> > > : __string_view_hash<char32_t> {};
0897
0898 #ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
0899 template <>
0900 struct hash<basic_string_view<wchar_t, char_traits<wchar_t> > > : __string_view_hash<wchar_t> {};
0901 #endif
0902
0903 #if _LIBCPP_STD_VER >= 14
0904 inline namespace literals {
0905 inline namespace string_view_literals {
0906 inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<char> operator""sv(const char* __str, size_t __len) noexcept {
0907 return basic_string_view<char>(__str, __len);
0908 }
0909
0910 # ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
0911 inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<wchar_t>
0912 operator""sv(const wchar_t* __str, size_t __len) noexcept {
0913 return basic_string_view<wchar_t>(__str, __len);
0914 }
0915 # endif
0916
0917 # ifndef _LIBCPP_HAS_NO_CHAR8_T
0918 inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<char8_t>
0919 operator""sv(const char8_t* __str, size_t __len) noexcept {
0920 return basic_string_view<char8_t>(__str, __len);
0921 }
0922 # endif
0923
0924 inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<char16_t>
0925 operator""sv(const char16_t* __str, size_t __len) noexcept {
0926 return basic_string_view<char16_t>(__str, __len);
0927 }
0928
0929 inline _LIBCPP_HIDE_FROM_ABI constexpr basic_string_view<char32_t>
0930 operator""sv(const char32_t* __str, size_t __len) noexcept {
0931 return basic_string_view<char32_t>(__str, __len);
0932 }
0933 } // namespace string_view_literals
0934 } // namespace literals
0935 #endif
0936 _LIBCPP_END_NAMESPACE_STD
0937
0938 _LIBCPP_POP_MACROS
0939
0940 #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
0941 # include <__cxx03/algorithm>
0942 # include <__cxx03/concepts>
0943 # include <__cxx03/cstdlib>
0944 # include <__cxx03/iterator>
0945 # include <__cxx03/type_traits>
0946 #endif
0947
0948 #endif // _LIBCPP___CXX03_STRING_VIEW