1// -*- C++ -*- 2//===----------------------------------------------------------------------===// 3// 4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5// See https://llvm.org/LICENSE.txt for license information. 6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef _LIBCPP_STRING_VIEW 11#define _LIBCPP_STRING_VIEW 12 13/* 14 15 string_view synopsis 16 17#include <compare> 18 19namespace std { 20 21 // 7.2, Class template basic_string_view 22 template<class charT, class traits = char_traits<charT>> 23 class basic_string_view; 24 25 template<class charT, class traits> 26 inline constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true; 27 28 template<class charT, class traits> 29 inline constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true; // C++20 30 31 // 7.9, basic_string_view non-member comparison functions 32 template<class charT, class traits> 33 constexpr bool operator==(basic_string_view<charT, traits> x, 34 basic_string_view<charT, traits> y) noexcept; 35 template<class charT, class traits> // Removed in C++20 36 constexpr bool operator!=(basic_string_view<charT, traits> x, 37 basic_string_view<charT, traits> y) noexcept; 38 template<class charT, class traits> // Removed in C++20 39 constexpr bool operator< (basic_string_view<charT, traits> x, 40 basic_string_view<charT, traits> y) noexcept; 41 template<class charT, class traits> // Removed in C++20 42 constexpr bool operator> (basic_string_view<charT, traits> x, 43 basic_string_view<charT, traits> y) noexcept; 44 template<class charT, class traits> // Removed in C++20 45 constexpr bool operator<=(basic_string_view<charT, traits> x, 46 basic_string_view<charT, traits> y) noexcept; 47 template<class charT, class traits> // Removed in C++20 48 constexpr bool operator>=(basic_string_view<charT, traits> x, 49 basic_string_view<charT, traits> y) noexcept; 50 template<class charT, class traits> // Since C++20 51 constexpr see below operator<=>(basic_string_view<charT, traits> x, 52 basic_string_view<charT, traits> y) noexcept; 53 54 // see below, sufficient additional overloads of comparison functions 55 56 // 7.10, Inserters and extractors 57 template<class charT, class traits> 58 basic_ostream<charT, traits>& 59 operator<<(basic_ostream<charT, traits>& os, 60 basic_string_view<charT, traits> str); 61 62 // basic_string_view typedef names 63 typedef basic_string_view<char> string_view; 64 typedef basic_string_view<char8_t> u8string_view; // C++20 65 typedef basic_string_view<char16_t> u16string_view; 66 typedef basic_string_view<char32_t> u32string_view; 67 typedef basic_string_view<wchar_t> wstring_view; 68 69 template<class charT, class traits = char_traits<charT>> 70 class basic_string_view { 71 public: 72 // types 73 typedef traits traits_type; 74 typedef charT value_type; 75 typedef charT* pointer; 76 typedef const charT* const_pointer; 77 typedef charT& reference; 78 typedef const charT& const_reference; 79 typedef implementation-defined const_iterator; 80 typedef const_iterator iterator; 81 typedef reverse_iterator<const_iterator> const_reverse_iterator; 82 typedef const_reverse_iterator reverse_iterator; 83 typedef size_t size_type; 84 typedef ptrdiff_t difference_type; 85 static constexpr size_type npos = size_type(-1); 86 87 // 7.3, basic_string_view constructors and assignment operators 88 constexpr basic_string_view() noexcept; 89 constexpr basic_string_view(const basic_string_view&) noexcept = default; 90 basic_string_view& operator=(const basic_string_view&) noexcept = default; 91 template<class Allocator> 92 constexpr basic_string_view(const charT* str); 93 basic_string_view(nullptr_t) = delete; // C++2b 94 constexpr basic_string_view(const charT* str, size_type len); 95 template <class It, class End> 96 constexpr basic_string_view(It begin, End end); // C++20 97 template <class Range> 98 constexpr basic_string_view(Range&& r); // C++23 99 100 // 7.4, basic_string_view iterator support 101 constexpr const_iterator begin() const noexcept; 102 constexpr const_iterator end() const noexcept; 103 constexpr const_iterator cbegin() const noexcept; 104 constexpr const_iterator cend() const noexcept; 105 const_reverse_iterator rbegin() const noexcept; 106 const_reverse_iterator rend() const noexcept; 107 const_reverse_iterator crbegin() const noexcept; 108 const_reverse_iterator crend() const noexcept; 109 110 // 7.5, basic_string_view capacity 111 constexpr size_type size() const noexcept; 112 constexpr size_type length() const noexcept; 113 constexpr size_type max_size() const noexcept; 114 constexpr bool empty() const noexcept; 115 116 // 7.6, basic_string_view element access 117 constexpr const_reference operator[](size_type pos) const; 118 constexpr const_reference at(size_type pos) const; 119 constexpr const_reference front() const; 120 constexpr const_reference back() const; 121 constexpr const_pointer data() const noexcept; 122 123 // 7.7, basic_string_view modifiers 124 constexpr void remove_prefix(size_type n); 125 constexpr void remove_suffix(size_type n); 126 constexpr void swap(basic_string_view& s) noexcept; 127 128 size_type copy(charT* s, size_type n, size_type pos = 0) const; // constexpr in C++20 129 130 constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const; 131 constexpr int compare(basic_string_view s) const noexcept; 132 constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const; 133 constexpr int compare(size_type pos1, size_type n1, 134 basic_string_view s, size_type pos2, size_type n2) const; 135 constexpr int compare(const charT* s) const; 136 constexpr int compare(size_type pos1, size_type n1, const charT* s) const; 137 constexpr int compare(size_type pos1, size_type n1, 138 const charT* s, size_type n2) const; 139 constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept; 140 constexpr size_type find(charT c, size_type pos = 0) const noexcept; 141 constexpr size_type find(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 142 constexpr size_type find(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension 143 constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept; 144 constexpr size_type rfind(charT c, size_type pos = npos) const noexcept; 145 constexpr size_type rfind(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 146 constexpr size_type rfind(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension 147 constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept; 148 constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept; 149 constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 150 constexpr size_type find_first_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension 151 constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept; 152 constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept; 153 constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 154 constexpr size_type find_last_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension 155 constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept; 156 constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept; 157 constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 158 constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension 159 constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept; 160 constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept; 161 constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 162 constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension 163 164 constexpr bool starts_with(basic_string_view s) const noexcept; // C++20 165 constexpr bool starts_with(charT c) const noexcept; // C++20 166 constexpr bool starts_with(const charT* s) const; // C++20 167 constexpr bool ends_with(basic_string_view s) const noexcept; // C++20 168 constexpr bool ends_with(charT c) const noexcept; // C++20 169 constexpr bool ends_with(const charT* s) const; // C++20 170 171 constexpr bool contains(basic_string_view s) const noexcept; // C++2b 172 constexpr bool contains(charT c) const noexcept; // C++2b 173 constexpr bool contains(const charT* s) const; // C++2b 174 175 private: 176 const_pointer data_; // exposition only 177 size_type size_; // exposition only 178 }; 179 180 // basic_string_view deduction guides 181 template<class It, class End> 182 basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>; // C++20 183 template<class Range> 184 basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23 185 186 // 7.11, Hash support 187 template <class T> struct hash; 188 template <> struct hash<string_view>; 189 template <> struct hash<u8string_view>; // C++20 190 template <> struct hash<u16string_view>; 191 template <> struct hash<u32string_view>; 192 template <> struct hash<wstring_view>; 193 194 constexpr basic_string_view<char> operator "" sv(const char *str, size_t len) noexcept; 195 constexpr basic_string_view<wchar_t> operator "" sv(const wchar_t *str, size_t len) noexcept; 196 constexpr basic_string_view<char8_t> operator "" sv(const char8_t *str, size_t len) noexcept; // C++20 197 constexpr basic_string_view<char16_t> operator "" sv(const char16_t *str, size_t len) noexcept; 198 constexpr basic_string_view<char32_t> operator "" sv(const char32_t *str, size_t len) noexcept; 199 200} // namespace std 201 202 203*/ 204 205#include <__algorithm/min.h> 206#include <__assert> // all public C++ headers provide the assertion handler 207#include <__config> 208#include <__functional/hash.h> 209#include <__functional/unary_function.h> 210#include <__fwd/string_view.h> 211#include <__iterator/bounded_iter.h> 212#include <__iterator/concepts.h> 213#include <__iterator/readable_traits.h> 214#include <__iterator/reverse_iterator.h> 215#include <__memory/pointer_traits.h> 216#include <__ranges/concepts.h> 217#include <__ranges/data.h> 218#include <__ranges/enable_borrowed_range.h> 219#include <__ranges/enable_view.h> 220#include <__ranges/size.h> 221#include <__string/char_traits.h> 222#include <__type_traits/is_array.h> 223#include <__type_traits/is_convertible.h> 224#include <__type_traits/is_same.h> 225#include <__type_traits/is_standard_layout.h> 226#include <__type_traits/is_trivial.h> 227#include <__type_traits/remove_cvref.h> 228#include <__type_traits/remove_reference.h> 229#include <__type_traits/type_identity.h> 230#include <iosfwd> 231#include <limits> 232#include <stdexcept> 233#include <version> 234 235// standard-mandated includes 236 237// [iterator.range] 238#include <__iterator/access.h> 239#include <__iterator/data.h> 240#include <__iterator/empty.h> 241#include <__iterator/reverse_access.h> 242#include <__iterator/size.h> 243 244// [string.view.synop] 245#include <compare> 246 247#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 248# pragma GCC system_header 249#endif 250 251_LIBCPP_PUSH_MACROS 252#include <__undef_macros> 253 254 255_LIBCPP_BEGIN_NAMESPACE_STD 256 257// TODO: This is a workaround for some vendors to carry a downstream diff to accept `nullptr` in 258// string_view constructors. This can be refactored when this exact form isn't needed anymore. 259template <class _Traits> 260_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR 261inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT { 262 // This needs to be a single statement for C++11 constexpr 263 return _LIBCPP_ASSERT(__s != nullptr, "null pointer passed to non-null argument of char_traits<...>::length"), _Traits::length(__s); 264} 265 266template<class _CharT, class _Traits> 267class basic_string_view { 268public: 269 // types 270 using traits_type = _Traits; 271 using value_type = _CharT; 272 using pointer = _CharT*; 273 using const_pointer = const _CharT*; 274 using reference = _CharT&; 275 using const_reference = const _CharT&; 276#ifdef _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING 277 using const_iterator = __bounded_iter<const_pointer>; 278#else 279 using const_iterator = const_pointer; // See [string.view.iterators] 280#endif 281 using iterator = const_iterator; 282 using const_reverse_iterator = _VSTD::reverse_iterator<const_iterator>; 283 using reverse_iterator = const_reverse_iterator; 284 using size_type = size_t; 285 using difference_type = ptrdiff_t; 286 static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1); 287 288 static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array"); 289 static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout"); 290 static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial"); 291 static_assert((is_same<_CharT, typename traits_type::char_type>::value), 292 "traits_type::char_type must be the same type as CharT"); 293 294 // [string.view.cons], construct/copy 295 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 296 basic_string_view() _NOEXCEPT : __data_(nullptr), __size_(0) {} 297 298 _LIBCPP_INLINE_VISIBILITY 299 basic_string_view(const basic_string_view&) _NOEXCEPT = default; 300 301 _LIBCPP_INLINE_VISIBILITY 302 basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default; 303 304 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 305 basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT 306 : __data_(__s), __size_(__len) 307 { 308#if _LIBCPP_STD_VER >= 14 309 _LIBCPP_ASSERT(__len <= static_cast<size_type>(numeric_limits<difference_type>::max()), "string_view::string_view(_CharT *, size_t): length does not fit in difference_type"); 310 _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr"); 311#endif 312 } 313 314#if _LIBCPP_STD_VER >= 20 315 template <contiguous_iterator _It, sized_sentinel_for<_It> _End> 316 requires (is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>) 317 constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end) 318 : __data_(_VSTD::to_address(__begin)), __size_(__end - __begin) 319 { 320 _LIBCPP_ASSERT((__end - __begin) >= 0, "std::string_view::string_view(iterator, sentinel) received invalid range"); 321 } 322#endif // _LIBCPP_STD_VER >= 20 323 324#if _LIBCPP_STD_VER >= 23 325 template <class _Range> 326 requires ( 327 !is_same_v<remove_cvref_t<_Range>, basic_string_view> && 328 ranges::contiguous_range<_Range> && 329 ranges::sized_range<_Range> && 330 is_same_v<ranges::range_value_t<_Range>, _CharT> && 331 !is_convertible_v<_Range, const _CharT*> && 332 (!requires(remove_cvref_t<_Range>& __d) { 333 __d.operator _VSTD::basic_string_view<_CharT, _Traits>(); 334 }) 335 ) 336 constexpr explicit _LIBCPP_HIDE_FROM_ABI 337 basic_string_view(_Range&& __r) : __data_(ranges::data(__r)), __size_(ranges::size(__r)) {} 338#endif // _LIBCPP_STD_VER >= 23 339 340 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 341 basic_string_view(const _CharT* __s) 342 : __data_(__s), __size_(_VSTD::__char_traits_length_checked<_Traits>(__s)) {} 343 344#if _LIBCPP_STD_VER >= 23 345 basic_string_view(nullptr_t) = delete; 346#endif 347 348 // [string.view.iterators], iterators 349 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 350 const_iterator begin() const _NOEXCEPT { return cbegin(); } 351 352 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 353 const_iterator end() const _NOEXCEPT { return cend(); } 354 355 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 356 const_iterator cbegin() const _NOEXCEPT { 357#ifdef _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING 358 return std::__make_bounded_iter(data(), data(), data() + size()); 359#else 360 return __data_; 361#endif 362 } 363 364 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 365 const_iterator cend() const _NOEXCEPT { 366#ifdef _LIBCPP_DEBUG_ITERATOR_BOUNDS_CHECKING 367 return std::__make_bounded_iter(data() + size(), data(), data() + size()); 368#else 369 return __data_ + __size_; 370#endif 371 } 372 373 _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_INLINE_VISIBILITY 374 const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } 375 376 _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_INLINE_VISIBILITY 377 const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } 378 379 _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_INLINE_VISIBILITY 380 const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } 381 382 _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_INLINE_VISIBILITY 383 const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } 384 385 // [string.view.capacity], capacity 386 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 387 size_type size() const _NOEXCEPT { return __size_; } 388 389 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 390 size_type length() const _NOEXCEPT { return __size_; } 391 392 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 393 size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max() / sizeof(value_type); } 394 395 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 396 bool empty() const _NOEXCEPT { return __size_ == 0; } 397 398 // [string.view.access], element access 399 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 400 const_reference operator[](size_type __pos) const _NOEXCEPT { 401 return _LIBCPP_ASSERT(__pos < size(), "string_view[] index out of bounds"), __data_[__pos]; 402 } 403 404 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 405 const_reference at(size_type __pos) const 406 { 407 return __pos >= size() 408 ? (__throw_out_of_range("string_view::at"), __data_[0]) 409 : __data_[__pos]; 410 } 411 412 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 413 const_reference front() const _NOEXCEPT 414 { 415 return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data_[0]; 416 } 417 418 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 419 const_reference back() const _NOEXCEPT 420 { 421 return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data_[__size_-1]; 422 } 423 424 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 425 const_pointer data() const _NOEXCEPT { return __data_; } 426 427 // [string.view.modifiers], modifiers: 428 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 429 void remove_prefix(size_type __n) _NOEXCEPT 430 { 431 _LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()"); 432 __data_ += __n; 433 __size_ -= __n; 434 } 435 436 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 437 void remove_suffix(size_type __n) _NOEXCEPT 438 { 439 _LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()"); 440 __size_ -= __n; 441 } 442 443 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 444 void swap(basic_string_view& __other) _NOEXCEPT 445 { 446 const value_type *__p = __data_; 447 __data_ = __other.__data_; 448 __other.__data_ = __p; 449 450 size_type __sz = __size_; 451 __size_ = __other.__size_; 452 __other.__size_ = __sz; 453 } 454 455 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20 456 size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const 457 { 458 if (__pos > size()) 459 __throw_out_of_range("string_view::copy"); 460 size_type __rlen = _VSTD::min(__n, size() - __pos); 461 _Traits::copy(__s, data() + __pos, __rlen); 462 return __rlen; 463 } 464 465 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 466 basic_string_view substr(size_type __pos = 0, size_type __n = npos) const 467 { 468 return __pos > size() 469 ? (__throw_out_of_range("string_view::substr"), basic_string_view()) 470 : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos)); 471 } 472 473 _LIBCPP_CONSTEXPR_SINCE_CXX14 int compare(basic_string_view __sv) const _NOEXCEPT 474 { 475 size_type __rlen = _VSTD::min(size(), __sv.size()); 476 int __retval = _Traits::compare(data(), __sv.data(), __rlen); 477 if (__retval == 0) // first __rlen chars matched 478 __retval = size() == __sv.size() ? 0 : (size() < __sv.size() ? -1 : 1); 479 return __retval; 480 } 481 482 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 483 int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const 484 { 485 return substr(__pos1, __n1).compare(__sv); 486 } 487 488 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 489 int compare( size_type __pos1, size_type __n1, 490 basic_string_view __sv, size_type __pos2, size_type __n2) const 491 { 492 return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); 493 } 494 495 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 496 int compare(const _CharT* __s) const _NOEXCEPT 497 { 498 return compare(basic_string_view(__s)); 499 } 500 501 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 502 int compare(size_type __pos1, size_type __n1, const _CharT* __s) const 503 { 504 return substr(__pos1, __n1).compare(basic_string_view(__s)); 505 } 506 507 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 508 int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const 509 { 510 return substr(__pos1, __n1).compare(basic_string_view(__s, __n2)); 511 } 512 513 // find 514 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 515 size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT 516 { 517 _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); 518 return std::__str_find<value_type, size_type, traits_type, npos> 519 (data(), size(), __s.data(), __pos, __s.size()); 520 } 521 522 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 523 size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT 524 { 525 return std::__str_find<value_type, size_type, traits_type, npos> 526 (data(), size(), __c, __pos); 527 } 528 529 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 530 size_type find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 531 { 532 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr"); 533 return std::__str_find<value_type, size_type, traits_type, npos> 534 (data(), size(), __s, __pos, __n); 535 } 536 537 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 538 size_type find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT 539 { 540 _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr"); 541 return std::__str_find<value_type, size_type, traits_type, npos> 542 (data(), size(), __s, __pos, traits_type::length(__s)); 543 } 544 545 // rfind 546 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 547 size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT 548 { 549 _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); 550 return std::__str_rfind<value_type, size_type, traits_type, npos> 551 (data(), size(), __s.data(), __pos, __s.size()); 552 } 553 554 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 555 size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT 556 { 557 return std::__str_rfind<value_type, size_type, traits_type, npos> 558 (data(), size(), __c, __pos); 559 } 560 561 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 562 size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 563 { 564 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr"); 565 return std::__str_rfind<value_type, size_type, traits_type, npos> 566 (data(), size(), __s, __pos, __n); 567 } 568 569 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 570 size_type rfind(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT 571 { 572 _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr"); 573 return std::__str_rfind<value_type, size_type, traits_type, npos> 574 (data(), size(), __s, __pos, traits_type::length(__s)); 575 } 576 577 // find_first_of 578 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 579 size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT 580 { 581 _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr"); 582 return std::__str_find_first_of<value_type, size_type, traits_type, npos> 583 (data(), size(), __s.data(), __pos, __s.size()); 584 } 585 586 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 587 size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT 588 { return find(__c, __pos); } 589 590 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 591 size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 592 { 593 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr"); 594 return std::__str_find_first_of<value_type, size_type, traits_type, npos> 595 (data(), size(), __s, __pos, __n); 596 } 597 598 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 599 size_type find_first_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT 600 { 601 _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr"); 602 return std::__str_find_first_of<value_type, size_type, traits_type, npos> 603 (data(), size(), __s, __pos, traits_type::length(__s)); 604 } 605 606 // find_last_of 607 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 608 size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT 609 { 610 _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr"); 611 return std::__str_find_last_of<value_type, size_type, traits_type, npos> 612 (data(), size(), __s.data(), __pos, __s.size()); 613 } 614 615 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 616 size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT 617 { return rfind(__c, __pos); } 618 619 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 620 size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 621 { 622 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr"); 623 return std::__str_find_last_of<value_type, size_type, traits_type, npos> 624 (data(), size(), __s, __pos, __n); 625 } 626 627 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 628 size_type find_last_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT 629 { 630 _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr"); 631 return std::__str_find_last_of<value_type, size_type, traits_type, npos> 632 (data(), size(), __s, __pos, traits_type::length(__s)); 633 } 634 635 // find_first_not_of 636 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 637 size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT 638 { 639 _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr"); 640 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> 641 (data(), size(), __s.data(), __pos, __s.size()); 642 } 643 644 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 645 size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT 646 { 647 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> 648 (data(), size(), __c, __pos); 649 } 650 651 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 652 size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 653 { 654 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr"); 655 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> 656 (data(), size(), __s, __pos, __n); 657 } 658 659 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 660 size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT 661 { 662 _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr"); 663 return std::__str_find_first_not_of<value_type, size_type, traits_type, npos> 664 (data(), size(), __s, __pos, traits_type::length(__s)); 665 } 666 667 // find_last_not_of 668 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 669 size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT 670 { 671 _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr"); 672 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> 673 (data(), size(), __s.data(), __pos, __s.size()); 674 } 675 676 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 677 size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT 678 { 679 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> 680 (data(), size(), __c, __pos); 681 } 682 683 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 684 size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 685 { 686 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr"); 687 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> 688 (data(), size(), __s, __pos, __n); 689 } 690 691 _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 692 size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT 693 { 694 _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr"); 695 return std::__str_find_last_not_of<value_type, size_type, traits_type, npos> 696 (data(), size(), __s, __pos, traits_type::length(__s)); 697 } 698 699#if _LIBCPP_STD_VER >= 20 700 constexpr _LIBCPP_INLINE_VISIBILITY 701 bool starts_with(basic_string_view __s) const noexcept 702 { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; } 703 704 constexpr _LIBCPP_INLINE_VISIBILITY 705 bool starts_with(value_type __c) const noexcept 706 { return !empty() && _Traits::eq(front(), __c); } 707 708 constexpr _LIBCPP_INLINE_VISIBILITY 709 bool starts_with(const value_type* __s) const noexcept 710 { return starts_with(basic_string_view(__s)); } 711 712 constexpr _LIBCPP_INLINE_VISIBILITY 713 bool ends_with(basic_string_view __s) const noexcept 714 { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; } 715 716 constexpr _LIBCPP_INLINE_VISIBILITY 717 bool ends_with(value_type __c) const noexcept 718 { return !empty() && _Traits::eq(back(), __c); } 719 720 constexpr _LIBCPP_INLINE_VISIBILITY 721 bool ends_with(const value_type* __s) const noexcept 722 { return ends_with(basic_string_view(__s)); } 723#endif 724 725#if _LIBCPP_STD_VER >= 23 726 constexpr _LIBCPP_INLINE_VISIBILITY 727 bool contains(basic_string_view __sv) const noexcept 728 { return find(__sv) != npos; } 729 730 constexpr _LIBCPP_INLINE_VISIBILITY 731 bool contains(value_type __c) const noexcept 732 { return find(__c) != npos; } 733 734 constexpr _LIBCPP_INLINE_VISIBILITY 735 bool contains(const value_type* __s) const 736 { return find(__s) != npos; } 737#endif 738 739private: 740 const value_type* __data_; 741 size_type __size_; 742}; 743_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_string_view); 744 745#if _LIBCPP_STD_VER >= 20 746template <class _CharT, class _Traits> 747inline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true; 748 749template <class _CharT, class _Traits> 750inline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true; 751#endif // _LIBCPP_STD_VER >= 20 752 753// [string.view.deduct] 754 755#if _LIBCPP_STD_VER >= 20 756template <contiguous_iterator _It, sized_sentinel_for<_It> _End> 757 basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>; 758#endif // _LIBCPP_STD_VER >= 20 759 760 761#if _LIBCPP_STD_VER >= 23 762template <ranges::contiguous_range _Range> 763 basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>; 764#endif 765 766// [string.view.comparison] 767// operator == 768template<class _CharT, class _Traits> 769_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 770bool operator==(basic_string_view<_CharT, _Traits> __lhs, 771 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 772{ 773 if (__lhs.size() != __rhs.size()) return false; 774 return __lhs.compare(__rhs) == 0; 775} 776 777// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details. 778// This applies to the other sufficient overloads below for the other comparison operators. 779template<class _CharT, class _Traits, int = 1> 780_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 781bool operator==(basic_string_view<_CharT, _Traits> __lhs, 782 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT 783{ 784 if (__lhs.size() != __rhs.size()) return false; 785 return __lhs.compare(__rhs) == 0; 786} 787 788#if _LIBCPP_STD_VER < 20 789// This overload is automatically generated in C++20. 790template<class _CharT, class _Traits, int = 2> 791_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 792bool operator==(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs, 793 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 794{ 795 if (__lhs.size() != __rhs.size()) return false; 796 return __lhs.compare(__rhs) == 0; 797} 798#endif // _LIBCPP_STD_VER >= 20 799 800// operator <=> 801 802#if _LIBCPP_STD_VER >= 20 803 804template <class _CharT, class _Traits> 805_LIBCPP_HIDE_FROM_ABI constexpr auto 806operator<=>(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) noexcept { 807 if constexpr (requires { typename _Traits::comparison_category; }) { 808 // [string.view]/4 809 static_assert( 810 __comparison_category<typename _Traits::comparison_category>, 811 "return type is not a comparison category type"); 812 return static_cast<typename _Traits::comparison_category>(__lhs.compare(__rhs) <=> 0); 813 } else { 814 return static_cast<weak_ordering>(__lhs.compare(__rhs) <=> 0); 815 } 816} 817 818template <class _CharT, class _Traits, int = 1> 819_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>( 820 basic_string_view<_CharT, _Traits> __lhs, type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) noexcept { 821 if constexpr (requires { typename _Traits::comparison_category; }) { 822 // [string.view]/4 823 static_assert( 824 __comparison_category<typename _Traits::comparison_category>, 825 "return type is not a comparison category type"); 826 return static_cast<typename _Traits::comparison_category>(__lhs.compare(__rhs) <=> 0); 827 } else { 828 return static_cast<weak_ordering>(__lhs.compare(__rhs) <=> 0); 829 } 830} 831 832#else // _LIBCPP_STD_VER >= 20 833 834// operator != 835template<class _CharT, class _Traits> 836_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 837bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 838{ 839 if (__lhs.size() != __rhs.size()) 840 return true; 841 return __lhs.compare(__rhs) != 0; 842} 843 844template<class _CharT, class _Traits, int = 1> 845_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 846bool operator!=(basic_string_view<_CharT, _Traits> __lhs, 847 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT 848{ 849 if (__lhs.size() != __rhs.size()) 850 return true; 851 return __lhs.compare(__rhs) != 0; 852} 853 854template<class _CharT, class _Traits, int = 2> 855_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 856bool operator!=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs, 857 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 858{ 859 if (__lhs.size() != __rhs.size()) 860 return true; 861 return __lhs.compare(__rhs) != 0; 862} 863 864 865// operator < 866template<class _CharT, class _Traits> 867_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 868bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 869{ 870 return __lhs.compare(__rhs) < 0; 871} 872 873template<class _CharT, class _Traits, int = 1> 874_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 875bool operator<(basic_string_view<_CharT, _Traits> __lhs, 876 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT 877{ 878 return __lhs.compare(__rhs) < 0; 879} 880 881template<class _CharT, class _Traits, int = 2> 882_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 883bool operator<(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs, 884 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 885{ 886 return __lhs.compare(__rhs) < 0; 887} 888 889 890// operator > 891template<class _CharT, class _Traits> 892_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 893bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 894{ 895 return __lhs.compare(__rhs) > 0; 896} 897 898template<class _CharT, class _Traits, int = 1> 899_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 900bool operator>(basic_string_view<_CharT, _Traits> __lhs, 901 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT 902{ 903 return __lhs.compare(__rhs) > 0; 904} 905 906template<class _CharT, class _Traits, int = 2> 907_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 908bool operator>(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs, 909 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 910{ 911 return __lhs.compare(__rhs) > 0; 912} 913 914 915// operator <= 916template<class _CharT, class _Traits> 917_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 918bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 919{ 920 return __lhs.compare(__rhs) <= 0; 921} 922 923template<class _CharT, class _Traits, int = 1> 924_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 925bool operator<=(basic_string_view<_CharT, _Traits> __lhs, 926 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT 927{ 928 return __lhs.compare(__rhs) <= 0; 929} 930 931template<class _CharT, class _Traits, int = 2> 932_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 933bool operator<=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs, 934 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 935{ 936 return __lhs.compare(__rhs) <= 0; 937} 938 939 940// operator >= 941template<class _CharT, class _Traits> 942_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 943bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 944{ 945 return __lhs.compare(__rhs) >= 0; 946} 947 948 949template<class _CharT, class _Traits, int = 1> 950_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 951bool operator>=(basic_string_view<_CharT, _Traits> __lhs, 952 __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT 953{ 954 return __lhs.compare(__rhs) >= 0; 955} 956 957template<class _CharT, class _Traits, int = 2> 958_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY 959bool operator>=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs, 960 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 961{ 962 return __lhs.compare(__rhs) >= 0; 963} 964 965#endif // _LIBCPP_STD_VER >= 20 966 967template<class _CharT, class _Traits> 968_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>& 969operator<<(basic_ostream<_CharT, _Traits>& __os, 970 basic_string_view<_CharT, _Traits> __str); 971 972// [string.view.hash] 973template<class _CharT> 974struct __string_view_hash : public __unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t> 975{ 976 _LIBCPP_INLINE_VISIBILITY 977 size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT { 978 return std::__do_string_hash(__val.data(), __val.data() + __val.size()); 979 } 980}; 981 982template <> 983struct hash<basic_string_view<char, char_traits<char> > > : __string_view_hash<char> {}; 984 985#ifndef _LIBCPP_HAS_NO_CHAR8_T 986template <> 987struct hash<basic_string_view<char8_t, char_traits<char8_t> > > : __string_view_hash<char8_t> {}; 988#endif 989 990template <> 991struct hash<basic_string_view<char16_t, char_traits<char16_t> > > : __string_view_hash<char16_t> {}; 992 993template <> 994struct hash<basic_string_view<char32_t, char_traits<char32_t> > > : __string_view_hash<char32_t> {}; 995 996#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 997template <> 998struct hash<basic_string_view<wchar_t, char_traits<wchar_t> > > : __string_view_hash<wchar_t> {}; 999#endif 1000 1001#if _LIBCPP_STD_VER >= 14 1002inline namespace literals 1003{ 1004 inline namespace string_view_literals 1005 { 1006 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1007 basic_string_view<char> operator "" sv(const char *__str, size_t __len) _NOEXCEPT 1008 { 1009 return basic_string_view<char> (__str, __len); 1010 } 1011 1012#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 1013 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1014 basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT 1015 { 1016 return basic_string_view<wchar_t> (__str, __len); 1017 } 1018#endif 1019 1020#ifndef _LIBCPP_HAS_NO_CHAR8_T 1021 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1022 basic_string_view<char8_t> operator "" sv(const char8_t *__str, size_t __len) _NOEXCEPT 1023 { 1024 return basic_string_view<char8_t> (__str, __len); 1025 } 1026#endif 1027 1028 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1029 basic_string_view<char16_t> operator "" sv(const char16_t *__str, size_t __len) _NOEXCEPT 1030 { 1031 return basic_string_view<char16_t> (__str, __len); 1032 } 1033 1034 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 1035 basic_string_view<char32_t> operator "" sv(const char32_t *__str, size_t __len) _NOEXCEPT 1036 { 1037 return basic_string_view<char32_t> (__str, __len); 1038 } 1039 } // namespace string_view_literals 1040} // namespace literals 1041#endif 1042_LIBCPP_END_NAMESPACE_STD 1043 1044_LIBCPP_POP_MACROS 1045 1046#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 1047# include <algorithm> 1048# include <concepts> 1049# include <cstdlib> 1050# include <functional> 1051# include <iterator> 1052# include <type_traits> 1053#endif 1054 1055#endif // _LIBCPP_STRING_VIEW 1056