xref: /freebsd-src/contrib/llvm-project/libcxx/include/string_view (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
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
259_LIBCPP_BEGIN_NAMESPACE_STD
260
261// TODO: This is a workaround for some vendors to carry a downstream diff to accept `nullptr` in
262//       string_view constructors. This can be refactored when this exact form isn't needed anymore.
263template <class _Traits>
264_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
265inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
266  // This needs to be a single statement for C++11 constexpr
267  return _LIBCPP_ASSERT_NON_NULL(
268             __s != nullptr, "null pointer passed to non-null argument of char_traits<...>::length"),
269         _Traits::length(__s);
270}
271
272template<class _CharT, class _Traits>
273class basic_string_view {
274public:
275    // types
276    using traits_type            = _Traits;
277    using value_type             = _CharT;
278    using pointer                = _CharT*;
279    using const_pointer          = const _CharT*;
280    using reference              = _CharT&;
281    using const_reference        = const _CharT&;
282#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
283    using const_iterator         = __bounded_iter<const_pointer>;
284#else
285    using const_iterator         = const_pointer; // See [string.view.iterators]
286#endif
287    using iterator               = const_iterator;
288    using const_reverse_iterator = std::reverse_iterator<const_iterator>;
289    using reverse_iterator       = const_reverse_iterator;
290    using size_type              = size_t;
291    using difference_type        = ptrdiff_t;
292    static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
293
294    static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array");
295    static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout");
296    static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial");
297    static_assert((is_same<_CharT, typename traits_type::char_type>::value),
298                  "traits_type::char_type must be the same type as CharT");
299
300    // [string.view.cons], construct/copy
301    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
302    basic_string_view() _NOEXCEPT : __data_(nullptr), __size_(0) {}
303
304    _LIBCPP_HIDE_FROM_ABI
305    basic_string_view(const basic_string_view&) _NOEXCEPT = default;
306
307    _LIBCPP_HIDE_FROM_ABI
308    basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
309
310    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
311    basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
312        : __data_(__s), __size_(__len)
313    {
314#if _LIBCPP_STD_VER >= 14
315    _LIBCPP_ASSERT_UNCATEGORIZED(
316        __len <= static_cast<size_type>(numeric_limits<difference_type>::max()),
317        "string_view::string_view(_CharT *, size_t): length does not fit in difference_type");
318    _LIBCPP_ASSERT_NON_NULL(
319        __len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
320#endif
321    }
322
323#if _LIBCPP_STD_VER >= 20
324    template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
325      requires (is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>)
326    constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end)
327       : __data_(std::to_address(__begin)), __size_(__end - __begin)
328    {
329      _LIBCPP_ASSERT_VALID_INPUT_RANGE((__end - __begin) >= 0,
330                                       "std::string_view::string_view(iterator, sentinel) received invalid range");
331    }
332#endif // _LIBCPP_STD_VER >= 20
333
334#if _LIBCPP_STD_VER >= 23
335    template <class _Range>
336      requires (
337        !is_same_v<remove_cvref_t<_Range>, basic_string_view> &&
338        ranges::contiguous_range<_Range> &&
339        ranges::sized_range<_Range> &&
340        is_same_v<ranges::range_value_t<_Range>, _CharT> &&
341        !is_convertible_v<_Range, const _CharT*> &&
342        (!requires(remove_cvref_t<_Range>& __d) {
343          __d.operator std::basic_string_view<_CharT, _Traits>();
344        })
345      )
346    constexpr explicit _LIBCPP_HIDE_FROM_ABI
347    basic_string_view(_Range&& __r) : __data_(ranges::data(__r)), __size_(ranges::size(__r)) {}
348#endif // _LIBCPP_STD_VER >= 23
349
350    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
351    basic_string_view(const _CharT* __s)
352        : __data_(__s), __size_(std::__char_traits_length_checked<_Traits>(__s)) {}
353
354#if _LIBCPP_STD_VER >= 23
355    basic_string_view(nullptr_t) = delete;
356#endif
357
358    // [string.view.iterators], iterators
359    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
360    const_iterator begin()  const _NOEXCEPT { return cbegin(); }
361
362    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
363    const_iterator end()    const _NOEXCEPT { return cend(); }
364
365    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
366    const_iterator cbegin() const _NOEXCEPT {
367#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
368        return std::__make_bounded_iter(data(), data(), data() + size());
369#else
370        return __data_;
371#endif
372    }
373
374    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
375    const_iterator cend()   const _NOEXCEPT {
376#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
377        return std::__make_bounded_iter(data() + size(), data(), data() + size());
378#else
379        return __data_ + __size_;
380#endif
381    }
382
383    _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI
384    const_reverse_iterator rbegin()   const _NOEXCEPT { return const_reverse_iterator(cend()); }
385
386    _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI
387    const_reverse_iterator rend()     const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
388
389    _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI
390    const_reverse_iterator crbegin()  const _NOEXCEPT { return const_reverse_iterator(cend()); }
391
392    _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI
393    const_reverse_iterator crend()    const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
394
395    // [string.view.capacity], capacity
396    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
397    size_type size()     const _NOEXCEPT { return __size_; }
398
399    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
400    size_type length()   const _NOEXCEPT { return __size_; }
401
402    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
403    size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max() / sizeof(value_type); }
404
405    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
406    bool empty()         const _NOEXCEPT { return __size_ == 0; }
407
408    // [string.view.access], element access
409    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
410    const_reference operator[](size_type __pos) const _NOEXCEPT {
411      return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__pos < size(), "string_view[] index out of bounds"), __data_[__pos];
412    }
413
414    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
415    const_reference at(size_type __pos) const
416    {
417        return __pos >= size()
418            ? (__throw_out_of_range("string_view::at"), __data_[0])
419            : __data_[__pos];
420    }
421
422    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
423    const_reference front() const _NOEXCEPT
424    {
425        return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::front(): string is empty"), __data_[0];
426    }
427
428    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
429    const_reference back() const _NOEXCEPT
430    {
431        return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::back(): string is empty"),
432               __data_[__size_ - 1];
433    }
434
435    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
436    const_pointer data() const _NOEXCEPT { return __data_; }
437
438    // [string.view.modifiers], modifiers:
439    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
440    void remove_prefix(size_type __n) _NOEXCEPT
441    {
442        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n <= size(), "remove_prefix() can't remove more than size()");
443        __data_ += __n;
444        __size_ -= __n;
445    }
446
447    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
448    void remove_suffix(size_type __n) _NOEXCEPT
449    {
450        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n <= size(), "remove_suffix() can't remove more than size()");
451        __size_ -= __n;
452    }
453
454    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
455    void swap(basic_string_view& __other) _NOEXCEPT
456    {
457        const value_type *__p = __data_;
458        __data_ = __other.__data_;
459        __other.__data_ = __p;
460
461        size_type __sz = __size_;
462        __size_ = __other.__size_;
463        __other.__size_ = __sz;
464    }
465
466    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
467    size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const
468    {
469        if (__pos > size())
470            __throw_out_of_range("string_view::copy");
471        size_type __rlen = std::min(__n, size() - __pos);
472        _Traits::copy(__s, data() + __pos, __rlen);
473        return __rlen;
474    }
475
476    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
477    basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
478    {
479        return __pos > size()
480            ? (__throw_out_of_range("string_view::substr"), basic_string_view())
481            : basic_string_view(data() + __pos, std::min(__n, size() - __pos));
482    }
483
484    _LIBCPP_CONSTEXPR_SINCE_CXX14 int compare(basic_string_view __sv) const _NOEXCEPT
485    {
486        size_type __rlen = std::min(size(), __sv.size());
487        int __retval = _Traits::compare(data(), __sv.data(), __rlen);
488        if (__retval == 0) // first __rlen chars matched
489            __retval = size() == __sv.size() ? 0 : (size() < __sv.size() ? -1 : 1);
490        return __retval;
491    }
492
493    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
494    int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const
495    {
496        return substr(__pos1, __n1).compare(__sv);
497    }
498
499    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
500    int compare(                       size_type __pos1, size_type __n1,
501                basic_string_view __sv, size_type __pos2, size_type __n2) const
502    {
503        return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
504    }
505
506    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
507    int compare(const _CharT* __s) const _NOEXCEPT
508    {
509        return compare(basic_string_view(__s));
510    }
511
512    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
513    int compare(size_type __pos1, size_type __n1, const _CharT* __s) const
514    {
515        return substr(__pos1, __n1).compare(basic_string_view(__s));
516    }
517
518    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
519    int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
520    {
521        return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
522    }
523
524    // find
525    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
526    size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
527    {
528        _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
529        return std::__str_find<value_type, size_type, traits_type, npos>
530            (data(), size(), __s.data(), __pos, __s.size());
531    }
532
533    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
534    size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT
535    {
536        return std::__str_find<value_type, size_type, traits_type, npos>
537            (data(), size(), __c, __pos);
538    }
539
540    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
541    size_type find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
542    {
543        _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
544        return std::__str_find<value_type, size_type, traits_type, npos>
545            (data(), size(), __s, __pos, __n);
546    }
547
548    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
549    size_type find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT
550    {
551        _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find(): received nullptr");
552        return std::__str_find<value_type, size_type, traits_type, npos>
553            (data(), size(), __s, __pos, traits_type::length(__s));
554    }
555
556    // rfind
557    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
558    size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT
559    {
560        _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
561        return std::__str_rfind<value_type, size_type, traits_type, npos>
562            (data(), size(), __s.data(), __pos, __s.size());
563    }
564
565    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
566    size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT
567    {
568        return std::__str_rfind<value_type, size_type, traits_type, npos>
569            (data(), size(), __c, __pos);
570    }
571
572    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
573    size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
574    {
575        _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
576        return std::__str_rfind<value_type, size_type, traits_type, npos>
577            (data(), size(), __s, __pos, __n);
578    }
579
580    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
581    size_type rfind(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
582    {
583        _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::rfind(): received nullptr");
584        return std::__str_rfind<value_type, size_type, traits_type, npos>
585            (data(), size(), __s, __pos, traits_type::length(__s));
586    }
587
588    // find_first_of
589    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
590    size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
591    {
592        _LIBCPP_ASSERT_NON_NULL(
593            __s.size() == 0 || __s.data() != 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.data(), __pos, __s.size());
596    }
597
598    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
599    size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT
600    { return find(__c, __pos); }
601
602    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
603    size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
604    {
605        _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
606        return std::__str_find_first_of<value_type, size_type, traits_type, npos>
607            (data(), size(), __s, __pos, __n);
608    }
609
610    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
611    size_type find_first_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT
612    {
613        _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_of(): received nullptr");
614        return std::__str_find_first_of<value_type, size_type, traits_type, npos>
615            (data(), size(), __s, __pos, traits_type::length(__s));
616    }
617
618    // find_last_of
619    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
620    size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
621    {
622        _LIBCPP_ASSERT_NON_NULL(
623            __s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
624        return std::__str_find_last_of<value_type, size_type, traits_type, npos>
625            (data(), size(), __s.data(), __pos, __s.size());
626    }
627
628    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
629    size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT
630    { return rfind(__c, __pos); }
631
632    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
633    size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
634    {
635        _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
636        return std::__str_find_last_of<value_type, size_type, traits_type, npos>
637            (data(), size(), __s, __pos, __n);
638    }
639
640    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
641    size_type find_last_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
642    {
643        _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_of(): received nullptr");
644        return std::__str_find_last_of<value_type, size_type, traits_type, npos>
645            (data(), size(), __s, __pos, traits_type::length(__s));
646    }
647
648    // find_first_not_of
649    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
650    size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT
651    {
652        _LIBCPP_ASSERT_NON_NULL(
653            __s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
654        return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>
655            (data(), size(), __s.data(), __pos, __s.size());
656    }
657
658    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
659    size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT
660    {
661        return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>
662            (data(), size(), __c, __pos);
663    }
664
665    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
666    size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
667    {
668        _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
669        return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>
670            (data(), size(), __s, __pos, __n);
671    }
672
673    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
674    size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT
675    {
676        _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
677        return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>
678            (data(), size(), __s, __pos, traits_type::length(__s));
679    }
680
681    // find_last_not_of
682    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
683    size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
684    {
685        _LIBCPP_ASSERT_NON_NULL(
686            __s.size() == 0 || __s.data() != 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.data(), __pos, __s.size());
689    }
690
691    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
692    size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT
693    {
694        return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>
695            (data(), size(), __c, __pos);
696    }
697
698    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
699    size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
700    {
701        _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
702        return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>
703            (data(), size(), __s, __pos, __n);
704    }
705
706    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
707    size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
708    {
709        _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
710        return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>
711            (data(), size(), __s, __pos, traits_type::length(__s));
712    }
713
714#if _LIBCPP_STD_VER >= 20
715    constexpr _LIBCPP_HIDE_FROM_ABI
716    bool starts_with(basic_string_view __s) const noexcept
717    { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; }
718
719    constexpr _LIBCPP_HIDE_FROM_ABI
720    bool starts_with(value_type __c) const noexcept
721    { return !empty() && _Traits::eq(front(), __c); }
722
723    constexpr _LIBCPP_HIDE_FROM_ABI
724    bool starts_with(const value_type* __s) const noexcept
725    { return starts_with(basic_string_view(__s)); }
726
727    constexpr _LIBCPP_HIDE_FROM_ABI
728    bool ends_with(basic_string_view __s) const noexcept
729    { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; }
730
731    constexpr _LIBCPP_HIDE_FROM_ABI
732    bool ends_with(value_type __c) const noexcept
733    { return !empty() && _Traits::eq(back(), __c); }
734
735    constexpr _LIBCPP_HIDE_FROM_ABI
736    bool ends_with(const value_type* __s) const noexcept
737    { return ends_with(basic_string_view(__s)); }
738#endif
739
740#if _LIBCPP_STD_VER >= 23
741    constexpr _LIBCPP_HIDE_FROM_ABI
742    bool contains(basic_string_view __sv) const noexcept
743    { return find(__sv) != npos; }
744
745    constexpr _LIBCPP_HIDE_FROM_ABI
746    bool contains(value_type __c) const noexcept
747    { return find(__c) != npos; }
748
749    constexpr _LIBCPP_HIDE_FROM_ABI
750    bool contains(const value_type* __s) const
751    { return find(__s) != npos; }
752#endif
753
754private:
755    const   value_type* __data_;
756    size_type           __size_;
757};
758_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_string_view);
759
760#if _LIBCPP_STD_VER >= 20
761template <class _CharT, class _Traits>
762inline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true;
763
764template <class _CharT, class _Traits>
765inline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true;
766#endif // _LIBCPP_STD_VER >= 20
767
768// [string.view.deduct]
769
770#if _LIBCPP_STD_VER >= 20
771template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
772  basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
773#endif // _LIBCPP_STD_VER >= 20
774
775
776#if _LIBCPP_STD_VER >= 23
777template <ranges::contiguous_range _Range>
778  basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>;
779#endif
780
781// [string.view.comparison]
782
783#if _LIBCPP_STD_VER >= 20
784
785template<class _CharT, class _Traits>
786_LIBCPP_HIDE_FROM_ABI constexpr
787bool operator==(basic_string_view<_CharT, _Traits> __lhs,
788                type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) noexcept {
789    if (__lhs.size() != __rhs.size()) return false;
790    return __lhs.compare(__rhs) == 0;
791}
792
793template <class _CharT, class _Traits>
794_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(
795    basic_string_view<_CharT, _Traits> __lhs, type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) noexcept {
796    if constexpr (requires { typename _Traits::comparison_category; }) {
797        // [string.view]/4
798        static_assert(
799            __comparison_category<typename _Traits::comparison_category>,
800            "return type is not a comparison category type");
801        return static_cast<typename _Traits::comparison_category>(__lhs.compare(__rhs) <=> 0);
802    } else {
803        return static_cast<weak_ordering>(__lhs.compare(__rhs) <=> 0);
804    }
805}
806
807#else
808
809// operator ==
810
811template<class _CharT, class _Traits>
812_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
813bool operator==(basic_string_view<_CharT, _Traits> __lhs,
814                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
815{
816    if (__lhs.size() != __rhs.size()) return false;
817    return __lhs.compare(__rhs) == 0;
818}
819
820// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details.
821// This applies to the other sufficient overloads below for the other comparison operators.
822template<class _CharT, class _Traits, int = 1>
823_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
824bool operator==(basic_string_view<_CharT, _Traits> __lhs,
825                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
826{
827    if (__lhs.size() != __rhs.size()) return false;
828    return __lhs.compare(__rhs) == 0;
829}
830
831template<class _CharT, class _Traits, int = 2>
832_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
833bool operator==(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
834                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
835{
836    if (__lhs.size() != __rhs.size()) return false;
837    return __lhs.compare(__rhs) == 0;
838}
839
840// operator !=
841template<class _CharT, class _Traits>
842_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
843bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
844{
845    if (__lhs.size() != __rhs.size())
846        return true;
847    return __lhs.compare(__rhs) != 0;
848}
849
850template<class _CharT, class _Traits, int = 1>
851_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
852bool operator!=(basic_string_view<_CharT, _Traits> __lhs,
853                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
854{
855    if (__lhs.size() != __rhs.size())
856        return true;
857    return __lhs.compare(__rhs) != 0;
858}
859
860template<class _CharT, class _Traits, int = 2>
861_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
862bool operator!=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
863                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
864{
865    if (__lhs.size() != __rhs.size())
866        return true;
867    return __lhs.compare(__rhs) != 0;
868}
869
870
871// operator <
872template<class _CharT, class _Traits>
873_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
874bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
875{
876    return __lhs.compare(__rhs) < 0;
877}
878
879template<class _CharT, class _Traits, int = 1>
880_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
881bool operator<(basic_string_view<_CharT, _Traits> __lhs,
882                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
883{
884    return __lhs.compare(__rhs) < 0;
885}
886
887template<class _CharT, class _Traits, int = 2>
888_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
889bool operator<(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
890                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
891{
892    return __lhs.compare(__rhs) < 0;
893}
894
895
896// operator >
897template<class _CharT, class _Traits>
898_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
899bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
900{
901    return __lhs.compare(__rhs) > 0;
902}
903
904template<class _CharT, class _Traits, int = 1>
905_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
906bool operator>(basic_string_view<_CharT, _Traits> __lhs,
907                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
908{
909    return __lhs.compare(__rhs) > 0;
910}
911
912template<class _CharT, class _Traits, int = 2>
913_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
914bool operator>(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
915                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
916{
917    return __lhs.compare(__rhs) > 0;
918}
919
920
921// operator <=
922template<class _CharT, class _Traits>
923_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
924bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
925{
926    return __lhs.compare(__rhs) <= 0;
927}
928
929template<class _CharT, class _Traits, int = 1>
930_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
931bool operator<=(basic_string_view<_CharT, _Traits> __lhs,
932                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
933{
934    return __lhs.compare(__rhs) <= 0;
935}
936
937template<class _CharT, class _Traits, int = 2>
938_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
939bool operator<=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
940                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
941{
942    return __lhs.compare(__rhs) <= 0;
943}
944
945
946// operator >=
947template<class _CharT, class _Traits>
948_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
949bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
950{
951    return __lhs.compare(__rhs) >= 0;
952}
953
954
955template<class _CharT, class _Traits, int = 1>
956_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
957bool operator>=(basic_string_view<_CharT, _Traits> __lhs,
958                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
959{
960    return __lhs.compare(__rhs) >= 0;
961}
962
963template<class _CharT, class _Traits, int = 2>
964_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
965bool operator>=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
966                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
967{
968    return __lhs.compare(__rhs) >= 0;
969}
970
971#endif //  _LIBCPP_STD_VER >= 20
972
973template<class _CharT, class _Traits>
974_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
975operator<<(basic_ostream<_CharT, _Traits>& __os,
976           basic_string_view<_CharT, _Traits> __str);
977
978// [string.view.hash]
979template<class _CharT>
980struct __string_view_hash : public __unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t>
981{
982    _LIBCPP_HIDE_FROM_ABI
983    size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT {
984        return std::__do_string_hash(__val.data(), __val.data() + __val.size());
985    }
986};
987
988template <>
989struct hash<basic_string_view<char, char_traits<char> > > : __string_view_hash<char> {};
990
991#ifndef _LIBCPP_HAS_NO_CHAR8_T
992template <>
993struct hash<basic_string_view<char8_t, char_traits<char8_t> > > : __string_view_hash<char8_t> {};
994#endif
995
996template <>
997struct hash<basic_string_view<char16_t, char_traits<char16_t> > > : __string_view_hash<char16_t> {};
998
999template <>
1000struct hash<basic_string_view<char32_t, char_traits<char32_t> > > : __string_view_hash<char32_t> {};
1001
1002#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1003template <>
1004struct hash<basic_string_view<wchar_t, char_traits<wchar_t> > > : __string_view_hash<wchar_t> {};
1005#endif
1006
1007#if _LIBCPP_STD_VER >= 14
1008inline namespace literals
1009{
1010  inline namespace string_view_literals
1011  {
1012    inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
1013    basic_string_view<char> operator""sv(const char *__str, size_t __len) _NOEXCEPT
1014    {
1015        return basic_string_view<char> (__str, __len);
1016    }
1017
1018#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1019    inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
1020    basic_string_view<wchar_t> operator""sv(const wchar_t *__str, size_t __len) _NOEXCEPT
1021    {
1022        return basic_string_view<wchar_t> (__str, __len);
1023    }
1024#endif
1025
1026#ifndef _LIBCPP_HAS_NO_CHAR8_T
1027    inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
1028    basic_string_view<char8_t> operator""sv(const char8_t *__str, size_t __len) _NOEXCEPT
1029    {
1030        return basic_string_view<char8_t> (__str, __len);
1031    }
1032#endif
1033
1034    inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
1035    basic_string_view<char16_t> operator""sv(const char16_t *__str, size_t __len) _NOEXCEPT
1036    {
1037        return basic_string_view<char16_t> (__str, __len);
1038    }
1039
1040    inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
1041    basic_string_view<char32_t> operator""sv(const char32_t *__str, size_t __len) _NOEXCEPT
1042    {
1043        return basic_string_view<char32_t> (__str, __len);
1044    }
1045  } // namespace string_view_literals
1046} // namespace literals
1047#endif
1048_LIBCPP_END_NAMESPACE_STD
1049
1050_LIBCPP_POP_MACROS
1051
1052#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1053#  include <algorithm>
1054#  include <concepts>
1055#  include <cstdlib>
1056#  include <iterator>
1057#  include <type_traits>
1058#endif
1059
1060#endif // _LIBCPP_STRING_VIEW
1061