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