xref: /freebsd/contrib/llvm-project/libcxx/include/string_view (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_STRING_VIEW
110b57cec5SDimitry Andric#define _LIBCPP_STRING_VIEW
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
1481ad6265SDimitry Andric
150b57cec5SDimitry Andric    string_view synopsis
160b57cec5SDimitry Andric
17bdd1243dSDimitry Andric#include <compare>
18bdd1243dSDimitry Andric
190b57cec5SDimitry Andricnamespace std {
200b57cec5SDimitry Andric
210b57cec5SDimitry Andric    // 7.2, Class template basic_string_view
220b57cec5SDimitry Andric    template<class charT, class traits = char_traits<charT>>
230b57cec5SDimitry Andric        class basic_string_view;
240b57cec5SDimitry Andric
25fe6060f1SDimitry Andric    template<class charT, class traits>
26fe6060f1SDimitry Andric    inline constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true;
27fe6060f1SDimitry Andric
28fe6060f1SDimitry Andric    template<class charT, class traits>
29fe6060f1SDimitry Andric    inline constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true;  // C++20
30fe6060f1SDimitry Andric
310b57cec5SDimitry Andric    // 7.9, basic_string_view non-member comparison functions
320b57cec5SDimitry Andric    template<class charT, class traits>
330b57cec5SDimitry Andric    constexpr bool operator==(basic_string_view<charT, traits> x,
340b57cec5SDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
35bdd1243dSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
360b57cec5SDimitry Andric    constexpr bool operator!=(basic_string_view<charT, traits> x,
370b57cec5SDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
38bdd1243dSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
390b57cec5SDimitry Andric    constexpr bool operator< (basic_string_view<charT, traits> x,
400b57cec5SDimitry Andric                                 basic_string_view<charT, traits> y) noexcept;
41bdd1243dSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
420b57cec5SDimitry Andric    constexpr bool operator> (basic_string_view<charT, traits> x,
430b57cec5SDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
44bdd1243dSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
450b57cec5SDimitry Andric    constexpr bool operator<=(basic_string_view<charT, traits> x,
460b57cec5SDimitry Andric                                 basic_string_view<charT, traits> y) noexcept;
47bdd1243dSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
480b57cec5SDimitry Andric    constexpr bool operator>=(basic_string_view<charT, traits> x,
490b57cec5SDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
50bdd1243dSDimitry Andric    template<class charT, class traits>                                                            // Since C++20
51bdd1243dSDimitry Andric    constexpr see below operator<=>(basic_string_view<charT, traits> x,
52bdd1243dSDimitry Andric                                    basic_string_view<charT, traits> y) noexcept;
53bdd1243dSDimitry Andric
540b57cec5SDimitry Andric    // see below, sufficient additional overloads of comparison functions
550b57cec5SDimitry Andric
560b57cec5SDimitry Andric    // 7.10, Inserters and extractors
570b57cec5SDimitry Andric    template<class charT, class traits>
580b57cec5SDimitry Andric      basic_ostream<charT, traits>&
590b57cec5SDimitry Andric        operator<<(basic_ostream<charT, traits>& os,
600b57cec5SDimitry Andric                   basic_string_view<charT, traits> str);
610b57cec5SDimitry Andric
620b57cec5SDimitry Andric    // basic_string_view typedef names
630b57cec5SDimitry Andric    typedef basic_string_view<char> string_view;
64fe6060f1SDimitry Andric    typedef basic_string_view<char8_t> u8string_view; // C++20
650b57cec5SDimitry Andric    typedef basic_string_view<char16_t> u16string_view;
660b57cec5SDimitry Andric    typedef basic_string_view<char32_t> u32string_view;
670b57cec5SDimitry Andric    typedef basic_string_view<wchar_t> wstring_view;
680b57cec5SDimitry Andric
690b57cec5SDimitry Andric    template<class charT, class traits = char_traits<charT>>
700b57cec5SDimitry Andric    class basic_string_view {
710b57cec5SDimitry Andric      public:
720b57cec5SDimitry Andric      // types
730b57cec5SDimitry Andric      typedef traits traits_type;
740b57cec5SDimitry Andric      typedef charT value_type;
750b57cec5SDimitry Andric      typedef charT* pointer;
760b57cec5SDimitry Andric      typedef const charT* const_pointer;
770b57cec5SDimitry Andric      typedef charT& reference;
780b57cec5SDimitry Andric      typedef const charT& const_reference;
790b57cec5SDimitry Andric      typedef implementation-defined const_iterator;
800b57cec5SDimitry Andric      typedef const_iterator iterator;
810b57cec5SDimitry Andric      typedef reverse_iterator<const_iterator> const_reverse_iterator;
820b57cec5SDimitry Andric      typedef const_reverse_iterator reverse_iterator;
830b57cec5SDimitry Andric      typedef size_t size_type;
840b57cec5SDimitry Andric      typedef ptrdiff_t difference_type;
850b57cec5SDimitry Andric      static constexpr size_type npos = size_type(-1);
860b57cec5SDimitry Andric
870b57cec5SDimitry Andric      // 7.3, basic_string_view constructors and assignment operators
880b57cec5SDimitry Andric      constexpr basic_string_view() noexcept;
890b57cec5SDimitry Andric      constexpr basic_string_view(const basic_string_view&) noexcept = default;
900b57cec5SDimitry Andric      basic_string_view& operator=(const basic_string_view&) noexcept = default;
910b57cec5SDimitry Andric      template<class Allocator>
920b57cec5SDimitry Andric      constexpr basic_string_view(const charT* str);
93*06c3fb27SDimitry Andric      basic_string_view(nullptr_t) = delete; // C++23
940b57cec5SDimitry Andric      constexpr basic_string_view(const charT* str, size_type len);
95349cc55cSDimitry Andric      template <class It, class End>
96349cc55cSDimitry Andric      constexpr basic_string_view(It begin, End end); // C++20
974824e7fdSDimitry Andric      template <class Range>
984824e7fdSDimitry Andric      constexpr basic_string_view(Range&& r); // C++23
990b57cec5SDimitry Andric
1000b57cec5SDimitry Andric      // 7.4, basic_string_view iterator support
1010b57cec5SDimitry Andric      constexpr const_iterator begin() const noexcept;
1020b57cec5SDimitry Andric      constexpr const_iterator end() const noexcept;
1030b57cec5SDimitry Andric      constexpr const_iterator cbegin() const noexcept;
1040b57cec5SDimitry Andric      constexpr const_iterator cend() const noexcept;
1050b57cec5SDimitry Andric      const_reverse_iterator rbegin() const noexcept;
1060b57cec5SDimitry Andric      const_reverse_iterator rend() const noexcept;
1070b57cec5SDimitry Andric      const_reverse_iterator crbegin() const noexcept;
1080b57cec5SDimitry Andric      const_reverse_iterator crend() const noexcept;
1090b57cec5SDimitry Andric
1100b57cec5SDimitry Andric      // 7.5, basic_string_view capacity
1110b57cec5SDimitry Andric      constexpr size_type size() const noexcept;
1120b57cec5SDimitry Andric      constexpr size_type length() const noexcept;
1130b57cec5SDimitry Andric      constexpr size_type max_size() const noexcept;
1140b57cec5SDimitry Andric      constexpr bool empty() const noexcept;
1150b57cec5SDimitry Andric
1160b57cec5SDimitry Andric      // 7.6, basic_string_view element access
1170b57cec5SDimitry Andric      constexpr const_reference operator[](size_type pos) const;
1180b57cec5SDimitry Andric      constexpr const_reference at(size_type pos) const;
1190b57cec5SDimitry Andric      constexpr const_reference front() const;
1200b57cec5SDimitry Andric      constexpr const_reference back() const;
1210b57cec5SDimitry Andric      constexpr const_pointer data() const noexcept;
1220b57cec5SDimitry Andric
1230b57cec5SDimitry Andric      // 7.7, basic_string_view modifiers
1240b57cec5SDimitry Andric      constexpr void remove_prefix(size_type n);
1250b57cec5SDimitry Andric      constexpr void remove_suffix(size_type n);
1260b57cec5SDimitry Andric      constexpr void swap(basic_string_view& s) noexcept;
1270b57cec5SDimitry Andric
128fe6060f1SDimitry Andric      size_type copy(charT* s, size_type n, size_type pos = 0) const;  // constexpr in C++20
1290b57cec5SDimitry Andric
1300b57cec5SDimitry Andric      constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
1310b57cec5SDimitry Andric      constexpr int compare(basic_string_view s) const noexcept;
1320b57cec5SDimitry Andric      constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
1330b57cec5SDimitry Andric      constexpr int compare(size_type pos1, size_type n1,
1340b57cec5SDimitry Andric                            basic_string_view s, size_type pos2, size_type n2) const;
1350b57cec5SDimitry Andric      constexpr int compare(const charT* s) const;
1360b57cec5SDimitry Andric      constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
1370b57cec5SDimitry Andric      constexpr int compare(size_type pos1, size_type n1,
1380b57cec5SDimitry Andric                            const charT* s, size_type n2) const;
1390b57cec5SDimitry Andric      constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
1400b57cec5SDimitry Andric      constexpr size_type find(charT c, size_type pos = 0) const noexcept;
141fe6060f1SDimitry Andric      constexpr size_type find(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
142fe6060f1SDimitry Andric      constexpr size_type find(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
1430b57cec5SDimitry Andric      constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
1440b57cec5SDimitry Andric      constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
145fe6060f1SDimitry Andric      constexpr size_type rfind(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
146fe6060f1SDimitry Andric      constexpr size_type rfind(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
1470b57cec5SDimitry Andric      constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
1480b57cec5SDimitry Andric      constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
149fe6060f1SDimitry Andric      constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
150fe6060f1SDimitry Andric      constexpr size_type find_first_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
1510b57cec5SDimitry Andric      constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
1520b57cec5SDimitry Andric      constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
153fe6060f1SDimitry Andric      constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
154fe6060f1SDimitry Andric      constexpr size_type find_last_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
1550b57cec5SDimitry Andric      constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
1560b57cec5SDimitry Andric      constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
157fe6060f1SDimitry Andric      constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
158fe6060f1SDimitry Andric      constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
1590b57cec5SDimitry Andric      constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
1600b57cec5SDimitry Andric      constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
161fe6060f1SDimitry Andric      constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
162fe6060f1SDimitry Andric      constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
1630b57cec5SDimitry Andric
164e8d8bef9SDimitry Andric      constexpr bool starts_with(basic_string_view s) const noexcept; // C++20
165e8d8bef9SDimitry Andric      constexpr bool starts_with(charT c) const noexcept;             // C++20
166e8d8bef9SDimitry Andric      constexpr bool starts_with(const charT* s) const;               // C++20
167e8d8bef9SDimitry Andric      constexpr bool ends_with(basic_string_view s) const noexcept;   // C++20
168e8d8bef9SDimitry Andric      constexpr bool ends_with(charT c) const noexcept;               // C++20
169e8d8bef9SDimitry Andric      constexpr bool ends_with(const charT* s) const;                 // C++20
170e8d8bef9SDimitry Andric
171*06c3fb27SDimitry Andric      constexpr bool contains(basic_string_view s) const noexcept; // C++23
172*06c3fb27SDimitry Andric      constexpr bool contains(charT c) const noexcept;             // C++23
173*06c3fb27SDimitry Andric      constexpr bool contains(const charT* s) const;               // C++23
1740b57cec5SDimitry Andric
1750b57cec5SDimitry Andric     private:
1760b57cec5SDimitry Andric      const_pointer data_;  // exposition only
1770b57cec5SDimitry Andric      size_type     size_;  // exposition only
1780b57cec5SDimitry Andric    };
1790b57cec5SDimitry Andric
180349cc55cSDimitry Andric  // basic_string_view deduction guides
181349cc55cSDimitry Andric  template<class It, class End>
182349cc55cSDimitry Andric    basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>; // C++20
1834824e7fdSDimitry Andric  template<class Range>
1844824e7fdSDimitry Andric    basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23
185349cc55cSDimitry Andric
1860b57cec5SDimitry Andric  // 7.11, Hash support
1870b57cec5SDimitry Andric  template <class T> struct hash;
1880b57cec5SDimitry Andric  template <> struct hash<string_view>;
189fe6060f1SDimitry Andric  template <> struct hash<u8string_view>; // C++20
1900b57cec5SDimitry Andric  template <> struct hash<u16string_view>;
1910b57cec5SDimitry Andric  template <> struct hash<u32string_view>;
1920b57cec5SDimitry Andric  template <> struct hash<wstring_view>;
1930b57cec5SDimitry Andric
1940b57cec5SDimitry Andric  constexpr basic_string_view<char>     operator""sv(const char *str,     size_t len) noexcept;
1950b57cec5SDimitry Andric  constexpr basic_string_view<wchar_t>  operator""sv(const wchar_t *str,  size_t len) noexcept;
196fe6060f1SDimitry Andric  constexpr basic_string_view<char8_t>  operator""sv(const char8_t *str,  size_t len) noexcept; // C++20
1970b57cec5SDimitry Andric  constexpr basic_string_view<char16_t> operator""sv(const char16_t *str, size_t len) noexcept;
1980b57cec5SDimitry Andric  constexpr basic_string_view<char32_t> operator""sv(const char32_t *str, size_t len) noexcept;
1990b57cec5SDimitry Andric
2000b57cec5SDimitry Andric}  // namespace std
2010b57cec5SDimitry Andric
2020b57cec5SDimitry Andric
2030b57cec5SDimitry Andric*/
2040b57cec5SDimitry Andric
20581ad6265SDimitry Andric#include <__algorithm/min.h>
20681ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
2070b57cec5SDimitry Andric#include <__config>
20881ad6265SDimitry Andric#include <__functional/hash.h>
20981ad6265SDimitry Andric#include <__functional/unary_function.h>
21081ad6265SDimitry Andric#include <__fwd/string_view.h>
211*06c3fb27SDimitry Andric#include <__iterator/bounded_iter.h>
21281ad6265SDimitry Andric#include <__iterator/concepts.h>
213*06c3fb27SDimitry Andric#include <__iterator/iterator_traits.h>
21481ad6265SDimitry Andric#include <__iterator/reverse_iterator.h>
21581ad6265SDimitry Andric#include <__memory/pointer_traits.h>
2164824e7fdSDimitry Andric#include <__ranges/concepts.h>
2174824e7fdSDimitry Andric#include <__ranges/data.h>
218fe6060f1SDimitry Andric#include <__ranges/enable_borrowed_range.h>
219fe6060f1SDimitry Andric#include <__ranges/enable_view.h>
2204824e7fdSDimitry Andric#include <__ranges/size.h>
22181ad6265SDimitry Andric#include <__string/char_traits.h>
222*06c3fb27SDimitry Andric#include <__type_traits/is_array.h>
223*06c3fb27SDimitry Andric#include <__type_traits/is_convertible.h>
224*06c3fb27SDimitry Andric#include <__type_traits/is_same.h>
225*06c3fb27SDimitry Andric#include <__type_traits/is_standard_layout.h>
226*06c3fb27SDimitry Andric#include <__type_traits/is_trivial.h>
227*06c3fb27SDimitry Andric#include <__type_traits/remove_cvref.h>
228*06c3fb27SDimitry Andric#include <__type_traits/remove_reference.h>
229*06c3fb27SDimitry Andric#include <__type_traits/type_identity.h>
230*06c3fb27SDimitry Andric#include <cstddef>
231fe6060f1SDimitry Andric#include <iosfwd>
2320b57cec5SDimitry Andric#include <limits>
2330b57cec5SDimitry Andric#include <stdexcept>
2340b57cec5SDimitry Andric#include <version>
2350b57cec5SDimitry Andric
23681ad6265SDimitry Andric// standard-mandated includes
23781ad6265SDimitry Andric
23881ad6265SDimitry Andric// [iterator.range]
23981ad6265SDimitry Andric#include <__iterator/access.h>
24081ad6265SDimitry Andric#include <__iterator/data.h>
24181ad6265SDimitry Andric#include <__iterator/empty.h>
24281ad6265SDimitry Andric#include <__iterator/reverse_access.h>
24381ad6265SDimitry Andric#include <__iterator/size.h>
24481ad6265SDimitry Andric
24581ad6265SDimitry Andric// [string.view.synop]
24681ad6265SDimitry Andric#include <compare>
24781ad6265SDimitry Andric
2480b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2490b57cec5SDimitry Andric#  pragma GCC system_header
2500b57cec5SDimitry Andric#endif
2510b57cec5SDimitry Andric
2520b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
2530b57cec5SDimitry Andric#include <__undef_macros>
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andric
2560b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
2570b57cec5SDimitry Andric
25881ad6265SDimitry Andric// TODO: This is a workaround for some vendors to carry a downstream diff to accept `nullptr` in
25981ad6265SDimitry Andric//       string_view constructors. This can be refactored when this exact form isn't needed anymore.
26081ad6265SDimitry Andrictemplate <class _Traits>
26181ad6265SDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
26281ad6265SDimitry Andricinline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
26381ad6265SDimitry Andric  // This needs to be a single statement for C++11 constexpr
264*06c3fb27SDimitry Andric  return _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr,
265*06c3fb27SDimitry Andric                                      "null pointer passed to non-null argument of char_traits<...>::length"),
266*06c3fb27SDimitry Andric      _Traits::length(__s);
26781ad6265SDimitry Andric}
268e8d8bef9SDimitry Andric
269e8d8bef9SDimitry Andrictemplate<class _CharT, class _Traits>
270bdd1243dSDimitry Andricclass basic_string_view {
2710b57cec5SDimitry Andricpublic:
2720b57cec5SDimitry Andric    // types
273bdd1243dSDimitry Andric    using traits_type            = _Traits;
274bdd1243dSDimitry Andric    using value_type             = _CharT;
275bdd1243dSDimitry Andric    using pointer                = _CharT*;
276bdd1243dSDimitry Andric    using const_pointer          = const _CharT*;
277bdd1243dSDimitry Andric    using reference              = _CharT&;
278bdd1243dSDimitry Andric    using const_reference        = const _CharT&;
279*06c3fb27SDimitry Andric#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
280*06c3fb27SDimitry Andric    using const_iterator         = __bounded_iter<const_pointer>;
281*06c3fb27SDimitry Andric#else
282bdd1243dSDimitry Andric    using const_iterator         = const_pointer; // See [string.view.iterators]
283*06c3fb27SDimitry Andric#endif
284bdd1243dSDimitry Andric    using iterator               = const_iterator;
285bdd1243dSDimitry Andric    using const_reverse_iterator = _VSTD::reverse_iterator<const_iterator>;
286bdd1243dSDimitry Andric    using reverse_iterator       = const_reverse_iterator;
287bdd1243dSDimitry Andric    using size_type              = size_t;
288bdd1243dSDimitry Andric    using difference_type        = ptrdiff_t;
2890b57cec5SDimitry Andric    static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
2900b57cec5SDimitry Andric
2910b57cec5SDimitry Andric    static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array");
2920b57cec5SDimitry Andric    static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout");
2930b57cec5SDimitry Andric    static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial");
2940b57cec5SDimitry Andric    static_assert((is_same<_CharT, typename traits_type::char_type>::value),
2950b57cec5SDimitry Andric                  "traits_type::char_type must be the same type as CharT");
2960b57cec5SDimitry Andric
2970b57cec5SDimitry Andric    // [string.view.cons], construct/copy
2980b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
299bdd1243dSDimitry Andric    basic_string_view() _NOEXCEPT : __data_(nullptr), __size_(0) {}
3000b57cec5SDimitry Andric
301349cc55cSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3020b57cec5SDimitry Andric    basic_string_view(const basic_string_view&) _NOEXCEPT = default;
3030b57cec5SDimitry Andric
304349cc55cSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
3050b57cec5SDimitry Andric    basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
3060b57cec5SDimitry Andric
3070b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3080b57cec5SDimitry Andric    basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
309bdd1243dSDimitry Andric        : __data_(__s), __size_(__len)
3100b57cec5SDimitry Andric    {
311*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
312*06c3fb27SDimitry Andric    _LIBCPP_ASSERT_UNCATEGORIZED(
313*06c3fb27SDimitry Andric        __len <= static_cast<size_type>(numeric_limits<difference_type>::max()),
314*06c3fb27SDimitry Andric        "string_view::string_view(_CharT *, size_t): length does not fit in difference_type");
315*06c3fb27SDimitry Andric    _LIBCPP_ASSERT_UNCATEGORIZED(__len == 0 || __s != nullptr,
316*06c3fb27SDimitry Andric                                 "string_view::string_view(_CharT *, size_t): received nullptr");
3170b57cec5SDimitry Andric#endif
3180b57cec5SDimitry Andric    }
3190b57cec5SDimitry Andric
320*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
321349cc55cSDimitry Andric    template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
3224824e7fdSDimitry Andric      requires (is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>)
323349cc55cSDimitry Andric    constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end)
324bdd1243dSDimitry Andric       : __data_(_VSTD::to_address(__begin)), __size_(__end - __begin)
325349cc55cSDimitry Andric    {
326*06c3fb27SDimitry Andric      _LIBCPP_ASSERT_VALID_INPUT_RANGE((__end - __begin) >= 0,
327*06c3fb27SDimitry Andric                                       "std::string_view::string_view(iterator, sentinel) received invalid range");
328349cc55cSDimitry Andric    }
329*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
330349cc55cSDimitry Andric
331*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
3324824e7fdSDimitry Andric    template <class _Range>
3334824e7fdSDimitry Andric      requires (
3344824e7fdSDimitry Andric        !is_same_v<remove_cvref_t<_Range>, basic_string_view> &&
3354824e7fdSDimitry Andric        ranges::contiguous_range<_Range> &&
3364824e7fdSDimitry Andric        ranges::sized_range<_Range> &&
3374824e7fdSDimitry Andric        is_same_v<ranges::range_value_t<_Range>, _CharT> &&
3384824e7fdSDimitry Andric        !is_convertible_v<_Range, const _CharT*> &&
339753f127fSDimitry Andric        (!requires(remove_cvref_t<_Range>& __d) {
340753f127fSDimitry Andric          __d.operator _VSTD::basic_string_view<_CharT, _Traits>();
341*06c3fb27SDimitry Andric        })
3424824e7fdSDimitry Andric      )
343bdd1243dSDimitry Andric    constexpr explicit _LIBCPP_HIDE_FROM_ABI
344bdd1243dSDimitry Andric    basic_string_view(_Range&& __r) : __data_(ranges::data(__r)), __size_(ranges::size(__r)) {}
345*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 23
3464824e7fdSDimitry Andric
3470b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3480b57cec5SDimitry Andric    basic_string_view(const _CharT* __s)
349bdd1243dSDimitry Andric        : __data_(__s), __size_(_VSTD::__char_traits_length_checked<_Traits>(__s)) {}
3500b57cec5SDimitry Andric
351*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
352fe6060f1SDimitry Andric    basic_string_view(nullptr_t) = delete;
353fe6060f1SDimitry Andric#endif
354fe6060f1SDimitry Andric
3550b57cec5SDimitry Andric    // [string.view.iterators], iterators
3560b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3570b57cec5SDimitry Andric    const_iterator begin()  const _NOEXCEPT { return cbegin(); }
3580b57cec5SDimitry Andric
3590b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3600b57cec5SDimitry Andric    const_iterator end()    const _NOEXCEPT { return cend(); }
3610b57cec5SDimitry Andric
3620b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
363*06c3fb27SDimitry Andric    const_iterator cbegin() const _NOEXCEPT {
364*06c3fb27SDimitry Andric#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
365*06c3fb27SDimitry Andric        return std::__make_bounded_iter(data(), data(), data() + size());
366*06c3fb27SDimitry Andric#else
367*06c3fb27SDimitry Andric        return __data_;
368*06c3fb27SDimitry Andric#endif
369*06c3fb27SDimitry Andric    }
3700b57cec5SDimitry Andric
3710b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
372*06c3fb27SDimitry Andric    const_iterator cend()   const _NOEXCEPT {
373*06c3fb27SDimitry Andric#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
374*06c3fb27SDimitry Andric        return std::__make_bounded_iter(data() + size(), data(), data() + size());
375*06c3fb27SDimitry Andric#else
376*06c3fb27SDimitry Andric        return __data_ + __size_;
377*06c3fb27SDimitry Andric#endif
378*06c3fb27SDimitry Andric    }
3790b57cec5SDimitry Andric
380bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_INLINE_VISIBILITY
3810b57cec5SDimitry Andric    const_reverse_iterator rbegin()   const _NOEXCEPT { return const_reverse_iterator(cend()); }
3820b57cec5SDimitry Andric
383bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_INLINE_VISIBILITY
3840b57cec5SDimitry Andric    const_reverse_iterator rend()     const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
3850b57cec5SDimitry Andric
386bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_INLINE_VISIBILITY
3870b57cec5SDimitry Andric    const_reverse_iterator crbegin()  const _NOEXCEPT { return const_reverse_iterator(cend()); }
3880b57cec5SDimitry Andric
389bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_INLINE_VISIBILITY
3900b57cec5SDimitry Andric    const_reverse_iterator crend()    const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
3910b57cec5SDimitry Andric
3920b57cec5SDimitry Andric    // [string.view.capacity], capacity
3930b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
394bdd1243dSDimitry Andric    size_type size()     const _NOEXCEPT { return __size_; }
3950b57cec5SDimitry Andric
3960b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
397bdd1243dSDimitry Andric    size_type length()   const _NOEXCEPT { return __size_; }
3980b57cec5SDimitry Andric
3990b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
4000eae32dcSDimitry Andric    size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max() / sizeof(value_type); }
4010b57cec5SDimitry Andric
4020b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
403bdd1243dSDimitry Andric    bool empty()         const _NOEXCEPT { return __size_ == 0; }
4040b57cec5SDimitry Andric
4050b57cec5SDimitry Andric    // [string.view.access], element access
4060b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
407e8d8bef9SDimitry Andric    const_reference operator[](size_type __pos) const _NOEXCEPT {
408*06c3fb27SDimitry Andric      return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__pos < size(), "string_view[] index out of bounds"), __data_[__pos];
409e8d8bef9SDimitry Andric    }
4100b57cec5SDimitry Andric
4110b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
4120b57cec5SDimitry Andric    const_reference at(size_type __pos) const
4130b57cec5SDimitry Andric    {
4140b57cec5SDimitry Andric        return __pos >= size()
415bdd1243dSDimitry Andric            ? (__throw_out_of_range("string_view::at"), __data_[0])
416bdd1243dSDimitry Andric            : __data_[__pos];
4170b57cec5SDimitry Andric    }
4180b57cec5SDimitry Andric
4190b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
4200b57cec5SDimitry Andric    const_reference front() const _NOEXCEPT
4210b57cec5SDimitry Andric    {
422*06c3fb27SDimitry Andric        return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::front(): string is empty"), __data_[0];
4230b57cec5SDimitry Andric    }
4240b57cec5SDimitry Andric
4250b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
4260b57cec5SDimitry Andric    const_reference back() const _NOEXCEPT
4270b57cec5SDimitry Andric    {
428*06c3fb27SDimitry Andric        return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::back(): string is empty"),
429*06c3fb27SDimitry Andric               __data_[__size_ - 1];
4300b57cec5SDimitry Andric    }
4310b57cec5SDimitry Andric
4320b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
433bdd1243dSDimitry Andric    const_pointer data() const _NOEXCEPT { return __data_; }
4340b57cec5SDimitry Andric
4350b57cec5SDimitry Andric    // [string.view.modifiers], modifiers:
436bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
4370b57cec5SDimitry Andric    void remove_prefix(size_type __n) _NOEXCEPT
4380b57cec5SDimitry Andric    {
439*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n <= size(), "remove_prefix() can't remove more than size()");
440bdd1243dSDimitry Andric        __data_ += __n;
441bdd1243dSDimitry Andric        __size_ -= __n;
4420b57cec5SDimitry Andric    }
4430b57cec5SDimitry Andric
444bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
4450b57cec5SDimitry Andric    void remove_suffix(size_type __n) _NOEXCEPT
4460b57cec5SDimitry Andric    {
447*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n <= size(), "remove_suffix() can't remove more than size()");
448bdd1243dSDimitry Andric        __size_ -= __n;
4490b57cec5SDimitry Andric    }
4500b57cec5SDimitry Andric
451bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
4520b57cec5SDimitry Andric    void swap(basic_string_view& __other) _NOEXCEPT
4530b57cec5SDimitry Andric    {
454bdd1243dSDimitry Andric        const value_type *__p = __data_;
455bdd1243dSDimitry Andric        __data_ = __other.__data_;
456bdd1243dSDimitry Andric        __other.__data_ = __p;
4570b57cec5SDimitry Andric
458bdd1243dSDimitry Andric        size_type __sz = __size_;
459bdd1243dSDimitry Andric        __size_ = __other.__size_;
460bdd1243dSDimitry Andric        __other.__size_ = __sz;
4610b57cec5SDimitry Andric    }
4620b57cec5SDimitry Andric
463bdd1243dSDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX20
4640b57cec5SDimitry Andric    size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const
4650b57cec5SDimitry Andric    {
4660b57cec5SDimitry Andric        if (__pos > size())
4670b57cec5SDimitry Andric            __throw_out_of_range("string_view::copy");
4680b57cec5SDimitry Andric        size_type __rlen = _VSTD::min(__n, size() - __pos);
4690b57cec5SDimitry Andric        _Traits::copy(__s, data() + __pos, __rlen);
4700b57cec5SDimitry Andric        return __rlen;
4710b57cec5SDimitry Andric    }
4720b57cec5SDimitry Andric
4730b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
4740b57cec5SDimitry Andric    basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
4750b57cec5SDimitry Andric    {
4760b57cec5SDimitry Andric        return __pos > size()
4770b57cec5SDimitry Andric            ? (__throw_out_of_range("string_view::substr"), basic_string_view())
4780b57cec5SDimitry Andric            : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos));
4790b57cec5SDimitry Andric    }
4800b57cec5SDimitry Andric
481bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 int compare(basic_string_view __sv) const _NOEXCEPT
4820b57cec5SDimitry Andric    {
4830b57cec5SDimitry Andric        size_type __rlen = _VSTD::min(size(), __sv.size());
4840b57cec5SDimitry Andric        int __retval = _Traits::compare(data(), __sv.data(), __rlen);
4850b57cec5SDimitry Andric        if (__retval == 0) // first __rlen chars matched
4860b57cec5SDimitry Andric            __retval = size() == __sv.size() ? 0 : (size() < __sv.size() ? -1 : 1);
4870b57cec5SDimitry Andric        return __retval;
4880b57cec5SDimitry Andric    }
4890b57cec5SDimitry Andric
490bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
4910b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const
4920b57cec5SDimitry Andric    {
4930b57cec5SDimitry Andric        return substr(__pos1, __n1).compare(__sv);
4940b57cec5SDimitry Andric    }
4950b57cec5SDimitry Andric
496bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
4970b57cec5SDimitry Andric    int compare(                       size_type __pos1, size_type __n1,
4980b57cec5SDimitry Andric                basic_string_view __sv, size_type __pos2, size_type __n2) const
4990b57cec5SDimitry Andric    {
5000b57cec5SDimitry Andric        return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
5010b57cec5SDimitry Andric    }
5020b57cec5SDimitry Andric
503bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
5040b57cec5SDimitry Andric    int compare(const _CharT* __s) const _NOEXCEPT
5050b57cec5SDimitry Andric    {
5060b57cec5SDimitry Andric        return compare(basic_string_view(__s));
5070b57cec5SDimitry Andric    }
5080b57cec5SDimitry Andric
509bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
5100b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const _CharT* __s) const
5110b57cec5SDimitry Andric    {
5120b57cec5SDimitry Andric        return substr(__pos1, __n1).compare(basic_string_view(__s));
5130b57cec5SDimitry Andric    }
5140b57cec5SDimitry Andric
515bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
5160b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
5170b57cec5SDimitry Andric    {
5180b57cec5SDimitry Andric        return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
5190b57cec5SDimitry Andric    }
5200b57cec5SDimitry Andric
5210b57cec5SDimitry Andric    // find
522bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
5230b57cec5SDimitry Andric    size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
5240b57cec5SDimitry Andric    {
525*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
526bdd1243dSDimitry Andric        return std::__str_find<value_type, size_type, traits_type, npos>
5270b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
5280b57cec5SDimitry Andric    }
5290b57cec5SDimitry Andric
530bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
5310b57cec5SDimitry Andric    size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT
5320b57cec5SDimitry Andric    {
533bdd1243dSDimitry Andric        return std::__str_find<value_type, size_type, traits_type, npos>
5340b57cec5SDimitry Andric            (data(), size(), __c, __pos);
5350b57cec5SDimitry Andric    }
5360b57cec5SDimitry Andric
537bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
538fe6060f1SDimitry Andric    size_type find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
5390b57cec5SDimitry Andric    {
540*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
541bdd1243dSDimitry Andric        return std::__str_find<value_type, size_type, traits_type, npos>
5420b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
5430b57cec5SDimitry Andric    }
5440b57cec5SDimitry Andric
545bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
546fe6060f1SDimitry Andric    size_type find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT
5470b57cec5SDimitry Andric    {
548*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string_view::find(): received nullptr");
549bdd1243dSDimitry Andric        return std::__str_find<value_type, size_type, traits_type, npos>
5500b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
5510b57cec5SDimitry Andric    }
5520b57cec5SDimitry Andric
5530b57cec5SDimitry Andric    // rfind
554bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
5550b57cec5SDimitry Andric    size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT
5560b57cec5SDimitry Andric    {
557*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
558bdd1243dSDimitry Andric        return std::__str_rfind<value_type, size_type, traits_type, npos>
5590b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
5600b57cec5SDimitry Andric    }
5610b57cec5SDimitry Andric
562bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
5630b57cec5SDimitry Andric    size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT
5640b57cec5SDimitry Andric    {
565bdd1243dSDimitry Andric        return std::__str_rfind<value_type, size_type, traits_type, npos>
5660b57cec5SDimitry Andric            (data(), size(), __c, __pos);
5670b57cec5SDimitry Andric    }
5680b57cec5SDimitry Andric
569bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
570fe6060f1SDimitry Andric    size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
5710b57cec5SDimitry Andric    {
572*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
573bdd1243dSDimitry Andric        return std::__str_rfind<value_type, size_type, traits_type, npos>
5740b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
5750b57cec5SDimitry Andric    }
5760b57cec5SDimitry Andric
577bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
578fe6060f1SDimitry Andric    size_type rfind(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
5790b57cec5SDimitry Andric    {
580*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string_view::rfind(): received nullptr");
581bdd1243dSDimitry Andric        return std::__str_rfind<value_type, size_type, traits_type, npos>
5820b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
5830b57cec5SDimitry Andric    }
5840b57cec5SDimitry Andric
5850b57cec5SDimitry Andric    // find_first_of
586bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
5870b57cec5SDimitry Andric    size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
5880b57cec5SDimitry Andric    {
589*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__s.size() == 0 || __s.data() != nullptr,
590*06c3fb27SDimitry Andric                                     "string_view::find_first_of(): received nullptr");
591bdd1243dSDimitry Andric        return std::__str_find_first_of<value_type, size_type, traits_type, npos>
5920b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
5930b57cec5SDimitry Andric    }
5940b57cec5SDimitry Andric
595bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
5960b57cec5SDimitry Andric    size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT
5970b57cec5SDimitry Andric    { return find(__c, __pos); }
5980b57cec5SDimitry Andric
599bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
600fe6060f1SDimitry Andric    size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
6010b57cec5SDimitry Andric    {
602*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
603bdd1243dSDimitry Andric        return std::__str_find_first_of<value_type, size_type, traits_type, npos>
6040b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
6050b57cec5SDimitry Andric    }
6060b57cec5SDimitry Andric
607bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
608fe6060f1SDimitry Andric    size_type find_first_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT
6090b57cec5SDimitry Andric    {
610*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string_view::find_first_of(): received nullptr");
611bdd1243dSDimitry Andric        return std::__str_find_first_of<value_type, size_type, traits_type, npos>
6120b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
6130b57cec5SDimitry Andric    }
6140b57cec5SDimitry Andric
6150b57cec5SDimitry Andric    // find_last_of
616bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
6170b57cec5SDimitry Andric    size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
6180b57cec5SDimitry Andric    {
619*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__s.size() == 0 || __s.data() != nullptr,
620*06c3fb27SDimitry Andric                                     "string_view::find_last_of(): received nullptr");
621bdd1243dSDimitry Andric        return std::__str_find_last_of<value_type, size_type, traits_type, npos>
6220b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
6230b57cec5SDimitry Andric    }
6240b57cec5SDimitry Andric
625bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
6260b57cec5SDimitry Andric    size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT
6270b57cec5SDimitry Andric    { return rfind(__c, __pos); }
6280b57cec5SDimitry Andric
629bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
630fe6060f1SDimitry Andric    size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
6310b57cec5SDimitry Andric    {
632*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
633bdd1243dSDimitry Andric        return std::__str_find_last_of<value_type, size_type, traits_type, npos>
6340b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
6350b57cec5SDimitry Andric    }
6360b57cec5SDimitry Andric
637bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
638fe6060f1SDimitry Andric    size_type find_last_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
6390b57cec5SDimitry Andric    {
640*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string_view::find_last_of(): received nullptr");
641bdd1243dSDimitry Andric        return std::__str_find_last_of<value_type, size_type, traits_type, npos>
6420b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
6430b57cec5SDimitry Andric    }
6440b57cec5SDimitry Andric
6450b57cec5SDimitry Andric    // find_first_not_of
646bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
6470b57cec5SDimitry Andric    size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT
6480b57cec5SDimitry Andric    {
649*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__s.size() == 0 || __s.data() != nullptr,
650*06c3fb27SDimitry Andric                                     "string_view::find_first_not_of(): received nullptr");
651bdd1243dSDimitry Andric        return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>
6520b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
6530b57cec5SDimitry Andric    }
6540b57cec5SDimitry Andric
655bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
6560b57cec5SDimitry Andric    size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT
6570b57cec5SDimitry Andric    {
658bdd1243dSDimitry Andric        return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>
6590b57cec5SDimitry Andric            (data(), size(), __c, __pos);
6600b57cec5SDimitry Andric    }
6610b57cec5SDimitry Andric
662bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
663fe6060f1SDimitry Andric    size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
6640b57cec5SDimitry Andric    {
665*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
666bdd1243dSDimitry Andric        return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>
6670b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
6680b57cec5SDimitry Andric    }
6690b57cec5SDimitry Andric
670bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
671fe6060f1SDimitry Andric    size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT
6720b57cec5SDimitry Andric    {
673*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
674bdd1243dSDimitry Andric        return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>
6750b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
6760b57cec5SDimitry Andric    }
6770b57cec5SDimitry Andric
6780b57cec5SDimitry Andric    // find_last_not_of
679bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
6800b57cec5SDimitry Andric    size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
6810b57cec5SDimitry Andric    {
682*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__s.size() == 0 || __s.data() != nullptr,
683*06c3fb27SDimitry Andric                                     "string_view::find_last_not_of(): received nullptr");
684bdd1243dSDimitry Andric        return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>
6850b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
6860b57cec5SDimitry Andric    }
6870b57cec5SDimitry Andric
688bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
6890b57cec5SDimitry Andric    size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT
6900b57cec5SDimitry Andric    {
691bdd1243dSDimitry Andric        return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>
6920b57cec5SDimitry Andric            (data(), size(), __c, __pos);
6930b57cec5SDimitry Andric    }
6940b57cec5SDimitry Andric
695bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
696fe6060f1SDimitry Andric    size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
6970b57cec5SDimitry Andric    {
698*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
699bdd1243dSDimitry Andric        return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>
7000b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
7010b57cec5SDimitry Andric    }
7020b57cec5SDimitry Andric
703bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
704fe6060f1SDimitry Andric    size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
7050b57cec5SDimitry Andric    {
706*06c3fb27SDimitry Andric        _LIBCPP_ASSERT_UNCATEGORIZED(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
707bdd1243dSDimitry Andric        return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>
7080b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
7090b57cec5SDimitry Andric    }
7100b57cec5SDimitry Andric
711*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
712349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
713349cc55cSDimitry Andric    bool starts_with(basic_string_view __s) const noexcept
7140b57cec5SDimitry Andric    { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; }
7150b57cec5SDimitry Andric
716349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
717349cc55cSDimitry Andric    bool starts_with(value_type __c) const noexcept
7180b57cec5SDimitry Andric    { return !empty() && _Traits::eq(front(), __c); }
7190b57cec5SDimitry Andric
720349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
721349cc55cSDimitry Andric    bool starts_with(const value_type* __s) const noexcept
7220b57cec5SDimitry Andric    { return starts_with(basic_string_view(__s)); }
7230b57cec5SDimitry Andric
724349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
725349cc55cSDimitry Andric    bool ends_with(basic_string_view __s) const noexcept
7260b57cec5SDimitry Andric    { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; }
7270b57cec5SDimitry Andric
728349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
729349cc55cSDimitry Andric    bool ends_with(value_type __c) const noexcept
7300b57cec5SDimitry Andric    { return !empty() && _Traits::eq(back(), __c); }
7310b57cec5SDimitry Andric
732349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
733349cc55cSDimitry Andric    bool ends_with(const value_type* __s) const noexcept
7340b57cec5SDimitry Andric    { return ends_with(basic_string_view(__s)); }
7350b57cec5SDimitry Andric#endif
7360b57cec5SDimitry Andric
737*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
738e8d8bef9SDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
739e8d8bef9SDimitry Andric    bool contains(basic_string_view __sv) const noexcept
740e8d8bef9SDimitry Andric    { return find(__sv) != npos; }
741e8d8bef9SDimitry Andric
742e8d8bef9SDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
743e8d8bef9SDimitry Andric    bool contains(value_type __c) const noexcept
744e8d8bef9SDimitry Andric    { return find(__c) != npos; }
745e8d8bef9SDimitry Andric
746e8d8bef9SDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
747e8d8bef9SDimitry Andric    bool contains(const value_type* __s) const
748e8d8bef9SDimitry Andric    { return find(__s) != npos; }
749e8d8bef9SDimitry Andric#endif
750e8d8bef9SDimitry Andric
7510b57cec5SDimitry Andricprivate:
752bdd1243dSDimitry Andric    const   value_type* __data_;
753bdd1243dSDimitry Andric    size_type           __size_;
7540b57cec5SDimitry Andric};
755bdd1243dSDimitry Andric_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_string_view);
7560b57cec5SDimitry Andric
757*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
758fe6060f1SDimitry Andrictemplate <class _CharT, class _Traits>
759fe6060f1SDimitry Andricinline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true;
760fe6060f1SDimitry Andric
761fe6060f1SDimitry Andrictemplate <class _CharT, class _Traits>
762fe6060f1SDimitry Andricinline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true;
763*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
7640b57cec5SDimitry Andric
765349cc55cSDimitry Andric// [string.view.deduct]
766349cc55cSDimitry Andric
767*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
768349cc55cSDimitry Andrictemplate <contiguous_iterator _It, sized_sentinel_for<_It> _End>
769349cc55cSDimitry Andric  basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
770*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
771349cc55cSDimitry Andric
7724824e7fdSDimitry Andric
773*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
7744824e7fdSDimitry Andrictemplate <ranges::contiguous_range _Range>
7754824e7fdSDimitry Andric  basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>;
776bdd1243dSDimitry Andric#endif
7774824e7fdSDimitry Andric
7780b57cec5SDimitry Andric// [string.view.comparison]
7790b57cec5SDimitry Andric// operator ==
7800b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
781bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
7820b57cec5SDimitry Andricbool operator==(basic_string_view<_CharT, _Traits> __lhs,
7830b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
7840b57cec5SDimitry Andric{
7850b57cec5SDimitry Andric    if (__lhs.size() != __rhs.size()) return false;
7860b57cec5SDimitry Andric    return __lhs.compare(__rhs) == 0;
7870b57cec5SDimitry Andric}
7880b57cec5SDimitry Andric
7894824e7fdSDimitry Andric// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details.
7904824e7fdSDimitry Andric// This applies to the other sufficient overloads below for the other comparison operators.
7914824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
792bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
7930b57cec5SDimitry Andricbool operator==(basic_string_view<_CharT, _Traits> __lhs,
794bdd1243dSDimitry Andric                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
7950b57cec5SDimitry Andric{
7960b57cec5SDimitry Andric    if (__lhs.size() != __rhs.size()) return false;
7970b57cec5SDimitry Andric    return __lhs.compare(__rhs) == 0;
7980b57cec5SDimitry Andric}
7990b57cec5SDimitry Andric
800bdd1243dSDimitry Andric#if _LIBCPP_STD_VER < 20
801bdd1243dSDimitry Andric// This overload is automatically generated in C++20.
8024824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
803bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
804bdd1243dSDimitry Andricbool operator==(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
8050b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8060b57cec5SDimitry Andric{
8070b57cec5SDimitry Andric    if (__lhs.size() != __rhs.size()) return false;
8080b57cec5SDimitry Andric    return __lhs.compare(__rhs) == 0;
8090b57cec5SDimitry Andric}
810*06c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
8110b57cec5SDimitry Andric
812bdd1243dSDimitry Andric// operator <=>
813bdd1243dSDimitry Andric
814*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
815bdd1243dSDimitry Andric
816bdd1243dSDimitry Andrictemplate <class _CharT, class _Traits>
817bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr auto
818bdd1243dSDimitry Andricoperator<=>(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) noexcept {
819bdd1243dSDimitry Andric    if constexpr (requires { typename _Traits::comparison_category; }) {
820bdd1243dSDimitry Andric        // [string.view]/4
821bdd1243dSDimitry Andric        static_assert(
822bdd1243dSDimitry Andric            __comparison_category<typename _Traits::comparison_category>,
823bdd1243dSDimitry Andric            "return type is not a comparison category type");
824bdd1243dSDimitry Andric        return static_cast<typename _Traits::comparison_category>(__lhs.compare(__rhs) <=> 0);
825bdd1243dSDimitry Andric    } else {
826bdd1243dSDimitry Andric        return static_cast<weak_ordering>(__lhs.compare(__rhs) <=> 0);
827bdd1243dSDimitry Andric    }
828bdd1243dSDimitry Andric}
829bdd1243dSDimitry Andric
830bdd1243dSDimitry Andrictemplate <class _CharT, class _Traits, int = 1>
831bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(
832bdd1243dSDimitry Andric    basic_string_view<_CharT, _Traits> __lhs, type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) noexcept {
833bdd1243dSDimitry Andric    if constexpr (requires { typename _Traits::comparison_category; }) {
834bdd1243dSDimitry Andric        // [string.view]/4
835bdd1243dSDimitry Andric        static_assert(
836bdd1243dSDimitry Andric            __comparison_category<typename _Traits::comparison_category>,
837bdd1243dSDimitry Andric            "return type is not a comparison category type");
838bdd1243dSDimitry Andric        return static_cast<typename _Traits::comparison_category>(__lhs.compare(__rhs) <=> 0);
839bdd1243dSDimitry Andric    } else {
840bdd1243dSDimitry Andric        return static_cast<weak_ordering>(__lhs.compare(__rhs) <=> 0);
841bdd1243dSDimitry Andric    }
842bdd1243dSDimitry Andric}
843bdd1243dSDimitry Andric
844*06c3fb27SDimitry Andric#else //  _LIBCPP_STD_VER >= 20
8450b57cec5SDimitry Andric
8460b57cec5SDimitry Andric// operator !=
8470b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
848bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
8490b57cec5SDimitry Andricbool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8500b57cec5SDimitry Andric{
8510b57cec5SDimitry Andric    if (__lhs.size() != __rhs.size())
8520b57cec5SDimitry Andric        return true;
8530b57cec5SDimitry Andric    return __lhs.compare(__rhs) != 0;
8540b57cec5SDimitry Andric}
8550b57cec5SDimitry Andric
8564824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
857bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
8580b57cec5SDimitry Andricbool operator!=(basic_string_view<_CharT, _Traits> __lhs,
859bdd1243dSDimitry Andric                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
8600b57cec5SDimitry Andric{
8610b57cec5SDimitry Andric    if (__lhs.size() != __rhs.size())
8620b57cec5SDimitry Andric        return true;
8630b57cec5SDimitry Andric    return __lhs.compare(__rhs) != 0;
8640b57cec5SDimitry Andric}
8650b57cec5SDimitry Andric
8664824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
867bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
868bdd1243dSDimitry Andricbool operator!=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
8690b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8700b57cec5SDimitry Andric{
8710b57cec5SDimitry Andric    if (__lhs.size() != __rhs.size())
8720b57cec5SDimitry Andric        return true;
8730b57cec5SDimitry Andric    return __lhs.compare(__rhs) != 0;
8740b57cec5SDimitry Andric}
8750b57cec5SDimitry Andric
8760b57cec5SDimitry Andric
8770b57cec5SDimitry Andric// operator <
8780b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
879bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
8800b57cec5SDimitry Andricbool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8810b57cec5SDimitry Andric{
8820b57cec5SDimitry Andric    return __lhs.compare(__rhs) < 0;
8830b57cec5SDimitry Andric}
8840b57cec5SDimitry Andric
8854824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
886bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
8870b57cec5SDimitry Andricbool operator<(basic_string_view<_CharT, _Traits> __lhs,
888bdd1243dSDimitry Andric                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
8890b57cec5SDimitry Andric{
8900b57cec5SDimitry Andric    return __lhs.compare(__rhs) < 0;
8910b57cec5SDimitry Andric}
8920b57cec5SDimitry Andric
8934824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
894bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
895bdd1243dSDimitry Andricbool operator<(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
8960b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8970b57cec5SDimitry Andric{
8980b57cec5SDimitry Andric    return __lhs.compare(__rhs) < 0;
8990b57cec5SDimitry Andric}
9000b57cec5SDimitry Andric
9010b57cec5SDimitry Andric
9020b57cec5SDimitry Andric// operator >
9030b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
904bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
9050b57cec5SDimitry Andricbool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
9060b57cec5SDimitry Andric{
9070b57cec5SDimitry Andric    return __lhs.compare(__rhs) > 0;
9080b57cec5SDimitry Andric}
9090b57cec5SDimitry Andric
9104824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
911bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
9120b57cec5SDimitry Andricbool operator>(basic_string_view<_CharT, _Traits> __lhs,
913bdd1243dSDimitry Andric                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
9140b57cec5SDimitry Andric{
9150b57cec5SDimitry Andric    return __lhs.compare(__rhs) > 0;
9160b57cec5SDimitry Andric}
9170b57cec5SDimitry Andric
9184824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
919bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
920bdd1243dSDimitry Andricbool operator>(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
9210b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
9220b57cec5SDimitry Andric{
9230b57cec5SDimitry Andric    return __lhs.compare(__rhs) > 0;
9240b57cec5SDimitry Andric}
9250b57cec5SDimitry Andric
9260b57cec5SDimitry Andric
9270b57cec5SDimitry Andric// operator <=
9280b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
929bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
9300b57cec5SDimitry Andricbool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
9310b57cec5SDimitry Andric{
9320b57cec5SDimitry Andric    return __lhs.compare(__rhs) <= 0;
9330b57cec5SDimitry Andric}
9340b57cec5SDimitry Andric
9354824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
936bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
9370b57cec5SDimitry Andricbool operator<=(basic_string_view<_CharT, _Traits> __lhs,
938bdd1243dSDimitry Andric                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
9390b57cec5SDimitry Andric{
9400b57cec5SDimitry Andric    return __lhs.compare(__rhs) <= 0;
9410b57cec5SDimitry Andric}
9420b57cec5SDimitry Andric
9434824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
944bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
945bdd1243dSDimitry Andricbool operator<=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
9460b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
9470b57cec5SDimitry Andric{
9480b57cec5SDimitry Andric    return __lhs.compare(__rhs) <= 0;
9490b57cec5SDimitry Andric}
9500b57cec5SDimitry Andric
9510b57cec5SDimitry Andric
9520b57cec5SDimitry Andric// operator >=
9530b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
954bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
9550b57cec5SDimitry Andricbool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
9560b57cec5SDimitry Andric{
9570b57cec5SDimitry Andric    return __lhs.compare(__rhs) >= 0;
9580b57cec5SDimitry Andric}
9590b57cec5SDimitry Andric
9600b57cec5SDimitry Andric
9614824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
962bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
9630b57cec5SDimitry Andricbool operator>=(basic_string_view<_CharT, _Traits> __lhs,
964bdd1243dSDimitry Andric                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
9650b57cec5SDimitry Andric{
9660b57cec5SDimitry Andric    return __lhs.compare(__rhs) >= 0;
9670b57cec5SDimitry Andric}
9680b57cec5SDimitry Andric
9694824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
970bdd1243dSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_INLINE_VISIBILITY
971bdd1243dSDimitry Andricbool operator>=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
9720b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
9730b57cec5SDimitry Andric{
9740b57cec5SDimitry Andric    return __lhs.compare(__rhs) >= 0;
9750b57cec5SDimitry Andric}
9760b57cec5SDimitry Andric
977*06c3fb27SDimitry Andric#endif //  _LIBCPP_STD_VER >= 20
978e40139ffSDimitry Andric
979e40139ffSDimitry Andrictemplate<class _CharT, class _Traits>
980bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
981e40139ffSDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os,
982e40139ffSDimitry Andric           basic_string_view<_CharT, _Traits> __str);
983e40139ffSDimitry Andric
9840b57cec5SDimitry Andric// [string.view.hash]
9850b57cec5SDimitry Andrictemplate<class _CharT>
986bdd1243dSDimitry Andricstruct __string_view_hash : public __unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t>
9870b57cec5SDimitry Andric{
9880b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9890b57cec5SDimitry Andric    size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT {
990bdd1243dSDimitry Andric        return std::__do_string_hash(__val.data(), __val.data() + __val.size());
9910b57cec5SDimitry Andric    }
9920b57cec5SDimitry Andric};
9930b57cec5SDimitry Andric
994bdd1243dSDimitry Andrictemplate <>
995bdd1243dSDimitry Andricstruct hash<basic_string_view<char, char_traits<char> > > : __string_view_hash<char> {};
996bdd1243dSDimitry Andric
997bdd1243dSDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
998bdd1243dSDimitry Andrictemplate <>
999bdd1243dSDimitry Andricstruct hash<basic_string_view<char8_t, char_traits<char8_t> > > : __string_view_hash<char8_t> {};
1000bdd1243dSDimitry Andric#endif
1001bdd1243dSDimitry Andric
1002bdd1243dSDimitry Andrictemplate <>
1003bdd1243dSDimitry Andricstruct hash<basic_string_view<char16_t, char_traits<char16_t> > > : __string_view_hash<char16_t> {};
1004bdd1243dSDimitry Andric
1005bdd1243dSDimitry Andrictemplate <>
1006bdd1243dSDimitry Andricstruct hash<basic_string_view<char32_t, char_traits<char32_t> > > : __string_view_hash<char32_t> {};
1007bdd1243dSDimitry Andric
1008bdd1243dSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1009bdd1243dSDimitry Andrictemplate <>
1010bdd1243dSDimitry Andricstruct hash<basic_string_view<wchar_t, char_traits<wchar_t> > > : __string_view_hash<wchar_t> {};
1011bdd1243dSDimitry Andric#endif
1012bdd1243dSDimitry Andric
1013*06c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
10140b57cec5SDimitry Andricinline namespace literals
10150b57cec5SDimitry Andric{
10160b57cec5SDimitry Andric  inline namespace string_view_literals
10170b57cec5SDimitry Andric  {
10180b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
10190b57cec5SDimitry Andric    basic_string_view<char> operator""sv(const char *__str, size_t __len) _NOEXCEPT
10200b57cec5SDimitry Andric    {
10210b57cec5SDimitry Andric        return basic_string_view<char> (__str, __len);
10220b57cec5SDimitry Andric    }
10230b57cec5SDimitry Andric
1024349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
10250b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
10260b57cec5SDimitry Andric    basic_string_view<wchar_t> operator""sv(const wchar_t *__str, size_t __len) _NOEXCEPT
10270b57cec5SDimitry Andric    {
10280b57cec5SDimitry Andric        return basic_string_view<wchar_t> (__str, __len);
10290b57cec5SDimitry Andric    }
1030349cc55cSDimitry Andric#endif
10310b57cec5SDimitry Andric
1032fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
10330b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
10340b57cec5SDimitry Andric    basic_string_view<char8_t> operator""sv(const char8_t *__str, size_t __len) _NOEXCEPT
10350b57cec5SDimitry Andric    {
10360b57cec5SDimitry Andric        return basic_string_view<char8_t> (__str, __len);
10370b57cec5SDimitry Andric    }
10380b57cec5SDimitry Andric#endif
10390b57cec5SDimitry Andric
10400b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
10410b57cec5SDimitry Andric    basic_string_view<char16_t> operator""sv(const char16_t *__str, size_t __len) _NOEXCEPT
10420b57cec5SDimitry Andric    {
10430b57cec5SDimitry Andric        return basic_string_view<char16_t> (__str, __len);
10440b57cec5SDimitry Andric    }
10450b57cec5SDimitry Andric
10460b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
10470b57cec5SDimitry Andric    basic_string_view<char32_t> operator""sv(const char32_t *__str, size_t __len) _NOEXCEPT
10480b57cec5SDimitry Andric    {
10490b57cec5SDimitry Andric        return basic_string_view<char32_t> (__str, __len);
10500b57cec5SDimitry Andric    }
10510eae32dcSDimitry Andric  } // namespace string_view_literals
10520eae32dcSDimitry Andric} // namespace literals
10530b57cec5SDimitry Andric#endif
10540b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
10550b57cec5SDimitry Andric
10560b57cec5SDimitry Andric_LIBCPP_POP_MACROS
10570b57cec5SDimitry Andric
1058bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1059bdd1243dSDimitry Andric#  include <algorithm>
1060bdd1243dSDimitry Andric#  include <concepts>
1061*06c3fb27SDimitry Andric#  include <cstdlib>
1062bdd1243dSDimitry Andric#  include <iterator>
1063*06c3fb27SDimitry Andric#  include <type_traits>
1064bdd1243dSDimitry Andric#endif
1065bdd1243dSDimitry Andric
10660b57cec5SDimitry Andric#endif // _LIBCPP_STRING_VIEW
1067