xref: /freebsd/contrib/llvm-project/libcxx/include/string_view (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
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
13*5f757f3fSDimitry Andric// clang-format off
14*5f757f3fSDimitry Andric
150b57cec5SDimitry Andric/*
1681ad6265SDimitry Andric
170b57cec5SDimitry Andric    string_view synopsis
180b57cec5SDimitry Andric
19bdd1243dSDimitry Andric#include <compare>
20bdd1243dSDimitry Andric
210b57cec5SDimitry Andricnamespace std {
220b57cec5SDimitry Andric
230b57cec5SDimitry Andric    // 7.2, Class template basic_string_view
240b57cec5SDimitry Andric    template<class charT, class traits = char_traits<charT>>
250b57cec5SDimitry Andric        class basic_string_view;
260b57cec5SDimitry Andric
27fe6060f1SDimitry Andric    template<class charT, class traits>
28fe6060f1SDimitry Andric    inline constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true;
29fe6060f1SDimitry Andric
30fe6060f1SDimitry Andric    template<class charT, class traits>
31fe6060f1SDimitry Andric    inline constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true;  // C++20
32fe6060f1SDimitry Andric
330b57cec5SDimitry Andric    // 7.9, basic_string_view non-member comparison functions
340b57cec5SDimitry Andric    template<class charT, class traits>
350b57cec5SDimitry Andric    constexpr bool operator==(basic_string_view<charT, traits> x,
360b57cec5SDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
37bdd1243dSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
380b57cec5SDimitry Andric    constexpr bool operator!=(basic_string_view<charT, traits> x,
390b57cec5SDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
40bdd1243dSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
410b57cec5SDimitry Andric    constexpr bool operator< (basic_string_view<charT, traits> x,
420b57cec5SDimitry Andric                                 basic_string_view<charT, traits> y) noexcept;
43bdd1243dSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
440b57cec5SDimitry Andric    constexpr bool operator> (basic_string_view<charT, traits> x,
450b57cec5SDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
46bdd1243dSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
470b57cec5SDimitry Andric    constexpr bool operator<=(basic_string_view<charT, traits> x,
480b57cec5SDimitry Andric                                 basic_string_view<charT, traits> y) noexcept;
49bdd1243dSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
500b57cec5SDimitry Andric    constexpr bool operator>=(basic_string_view<charT, traits> x,
510b57cec5SDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
52bdd1243dSDimitry Andric    template<class charT, class traits>                                                            // Since C++20
53bdd1243dSDimitry Andric    constexpr see below operator<=>(basic_string_view<charT, traits> x,
54bdd1243dSDimitry Andric                                    basic_string_view<charT, traits> y) noexcept;
55bdd1243dSDimitry Andric
560b57cec5SDimitry Andric    // see below, sufficient additional overloads of comparison functions
570b57cec5SDimitry Andric
580b57cec5SDimitry Andric    // 7.10, Inserters and extractors
590b57cec5SDimitry Andric    template<class charT, class traits>
600b57cec5SDimitry Andric      basic_ostream<charT, traits>&
610b57cec5SDimitry Andric        operator<<(basic_ostream<charT, traits>& os,
620b57cec5SDimitry Andric                   basic_string_view<charT, traits> str);
630b57cec5SDimitry Andric
640b57cec5SDimitry Andric    // basic_string_view typedef names
650b57cec5SDimitry Andric    typedef basic_string_view<char> string_view;
66fe6060f1SDimitry Andric    typedef basic_string_view<char8_t> u8string_view; // C++20
670b57cec5SDimitry Andric    typedef basic_string_view<char16_t> u16string_view;
680b57cec5SDimitry Andric    typedef basic_string_view<char32_t> u32string_view;
690b57cec5SDimitry Andric    typedef basic_string_view<wchar_t> wstring_view;
700b57cec5SDimitry Andric
710b57cec5SDimitry Andric    template<class charT, class traits = char_traits<charT>>
720b57cec5SDimitry Andric    class basic_string_view {
730b57cec5SDimitry Andric      public:
740b57cec5SDimitry Andric      // types
750b57cec5SDimitry Andric      typedef traits traits_type;
760b57cec5SDimitry Andric      typedef charT value_type;
770b57cec5SDimitry Andric      typedef charT* pointer;
780b57cec5SDimitry Andric      typedef const charT* const_pointer;
790b57cec5SDimitry Andric      typedef charT& reference;
800b57cec5SDimitry Andric      typedef const charT& const_reference;
810b57cec5SDimitry Andric      typedef implementation-defined const_iterator;
820b57cec5SDimitry Andric      typedef const_iterator iterator;
830b57cec5SDimitry Andric      typedef reverse_iterator<const_iterator> const_reverse_iterator;
840b57cec5SDimitry Andric      typedef const_reverse_iterator reverse_iterator;
850b57cec5SDimitry Andric      typedef size_t size_type;
860b57cec5SDimitry Andric      typedef ptrdiff_t difference_type;
870b57cec5SDimitry Andric      static constexpr size_type npos = size_type(-1);
880b57cec5SDimitry Andric
890b57cec5SDimitry Andric      // 7.3, basic_string_view constructors and assignment operators
900b57cec5SDimitry Andric      constexpr basic_string_view() noexcept;
910b57cec5SDimitry Andric      constexpr basic_string_view(const basic_string_view&) noexcept = default;
920b57cec5SDimitry Andric      basic_string_view& operator=(const basic_string_view&) noexcept = default;
930b57cec5SDimitry Andric      template<class Allocator>
940b57cec5SDimitry Andric      constexpr basic_string_view(const charT* str);
9506c3fb27SDimitry Andric      basic_string_view(nullptr_t) = delete; // C++23
960b57cec5SDimitry Andric      constexpr basic_string_view(const charT* str, size_type len);
97349cc55cSDimitry Andric      template <class It, class End>
98349cc55cSDimitry Andric      constexpr basic_string_view(It begin, End end); // C++20
994824e7fdSDimitry Andric      template <class Range>
1004824e7fdSDimitry Andric      constexpr basic_string_view(Range&& r); // C++23
1010b57cec5SDimitry Andric
1020b57cec5SDimitry Andric      // 7.4, basic_string_view iterator support
1030b57cec5SDimitry Andric      constexpr const_iterator begin() const noexcept;
1040b57cec5SDimitry Andric      constexpr const_iterator end() const noexcept;
1050b57cec5SDimitry Andric      constexpr const_iterator cbegin() const noexcept;
1060b57cec5SDimitry Andric      constexpr const_iterator cend() const noexcept;
1070b57cec5SDimitry Andric      const_reverse_iterator rbegin() const noexcept;
1080b57cec5SDimitry Andric      const_reverse_iterator rend() const noexcept;
1090b57cec5SDimitry Andric      const_reverse_iterator crbegin() const noexcept;
1100b57cec5SDimitry Andric      const_reverse_iterator crend() const noexcept;
1110b57cec5SDimitry Andric
1120b57cec5SDimitry Andric      // 7.5, basic_string_view capacity
1130b57cec5SDimitry Andric      constexpr size_type size() const noexcept;
1140b57cec5SDimitry Andric      constexpr size_type length() const noexcept;
1150b57cec5SDimitry Andric      constexpr size_type max_size() const noexcept;
1160b57cec5SDimitry Andric      constexpr bool empty() const noexcept;
1170b57cec5SDimitry Andric
1180b57cec5SDimitry Andric      // 7.6, basic_string_view element access
1190b57cec5SDimitry Andric      constexpr const_reference operator[](size_type pos) const;
1200b57cec5SDimitry Andric      constexpr const_reference at(size_type pos) const;
1210b57cec5SDimitry Andric      constexpr const_reference front() const;
1220b57cec5SDimitry Andric      constexpr const_reference back() const;
1230b57cec5SDimitry Andric      constexpr const_pointer data() const noexcept;
1240b57cec5SDimitry Andric
1250b57cec5SDimitry Andric      // 7.7, basic_string_view modifiers
1260b57cec5SDimitry Andric      constexpr void remove_prefix(size_type n);
1270b57cec5SDimitry Andric      constexpr void remove_suffix(size_type n);
1280b57cec5SDimitry Andric      constexpr void swap(basic_string_view& s) noexcept;
1290b57cec5SDimitry Andric
130fe6060f1SDimitry Andric      size_type copy(charT* s, size_type n, size_type pos = 0) const;  // constexpr in C++20
1310b57cec5SDimitry Andric
1320b57cec5SDimitry Andric      constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
1330b57cec5SDimitry Andric      constexpr int compare(basic_string_view s) const noexcept;
1340b57cec5SDimitry Andric      constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
1350b57cec5SDimitry Andric      constexpr int compare(size_type pos1, size_type n1,
1360b57cec5SDimitry Andric                            basic_string_view s, size_type pos2, size_type n2) const;
1370b57cec5SDimitry Andric      constexpr int compare(const charT* s) const;
1380b57cec5SDimitry Andric      constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
1390b57cec5SDimitry Andric      constexpr int compare(size_type pos1, size_type n1,
1400b57cec5SDimitry Andric                            const charT* s, size_type n2) const;
1410b57cec5SDimitry Andric      constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
1420b57cec5SDimitry Andric      constexpr size_type find(charT c, size_type pos = 0) const noexcept;
143fe6060f1SDimitry Andric      constexpr size_type find(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
144fe6060f1SDimitry Andric      constexpr size_type find(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
1450b57cec5SDimitry Andric      constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
1460b57cec5SDimitry Andric      constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
147fe6060f1SDimitry Andric      constexpr size_type rfind(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
148fe6060f1SDimitry Andric      constexpr size_type rfind(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
1490b57cec5SDimitry Andric      constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
1500b57cec5SDimitry Andric      constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
151fe6060f1SDimitry Andric      constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
152fe6060f1SDimitry Andric      constexpr size_type find_first_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
1530b57cec5SDimitry Andric      constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
1540b57cec5SDimitry Andric      constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
155fe6060f1SDimitry Andric      constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
156fe6060f1SDimitry Andric      constexpr size_type find_last_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
1570b57cec5SDimitry Andric      constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
1580b57cec5SDimitry Andric      constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
159fe6060f1SDimitry Andric      constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
160fe6060f1SDimitry Andric      constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
1610b57cec5SDimitry Andric      constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
1620b57cec5SDimitry Andric      constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
163fe6060f1SDimitry Andric      constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
164fe6060f1SDimitry Andric      constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
1650b57cec5SDimitry Andric
166e8d8bef9SDimitry Andric      constexpr bool starts_with(basic_string_view s) const noexcept; // C++20
167e8d8bef9SDimitry Andric      constexpr bool starts_with(charT c) const noexcept;             // C++20
168e8d8bef9SDimitry Andric      constexpr bool starts_with(const charT* s) const;               // C++20
169e8d8bef9SDimitry Andric      constexpr bool ends_with(basic_string_view s) const noexcept;   // C++20
170e8d8bef9SDimitry Andric      constexpr bool ends_with(charT c) const noexcept;               // C++20
171e8d8bef9SDimitry Andric      constexpr bool ends_with(const charT* s) const;                 // C++20
172e8d8bef9SDimitry Andric
17306c3fb27SDimitry Andric      constexpr bool contains(basic_string_view s) const noexcept; // C++23
17406c3fb27SDimitry Andric      constexpr bool contains(charT c) const noexcept;             // C++23
17506c3fb27SDimitry Andric      constexpr bool contains(const charT* s) const;               // C++23
1760b57cec5SDimitry Andric
1770b57cec5SDimitry Andric     private:
1780b57cec5SDimitry Andric      const_pointer data_;  // exposition only
1790b57cec5SDimitry Andric      size_type     size_;  // exposition only
1800b57cec5SDimitry Andric    };
1810b57cec5SDimitry Andric
182349cc55cSDimitry Andric  // basic_string_view deduction guides
183349cc55cSDimitry Andric  template<class It, class End>
184349cc55cSDimitry Andric    basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>; // C++20
1854824e7fdSDimitry Andric  template<class Range>
1864824e7fdSDimitry Andric    basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23
187349cc55cSDimitry Andric
1880b57cec5SDimitry Andric  // 7.11, Hash support
1890b57cec5SDimitry Andric  template <class T> struct hash;
1900b57cec5SDimitry Andric  template <> struct hash<string_view>;
191fe6060f1SDimitry Andric  template <> struct hash<u8string_view>; // C++20
1920b57cec5SDimitry Andric  template <> struct hash<u16string_view>;
1930b57cec5SDimitry Andric  template <> struct hash<u32string_view>;
1940b57cec5SDimitry Andric  template <> struct hash<wstring_view>;
1950b57cec5SDimitry Andric
1960b57cec5SDimitry Andric  constexpr basic_string_view<char>     operator""sv(const char *str,     size_t len) noexcept;
1970b57cec5SDimitry Andric  constexpr basic_string_view<wchar_t>  operator""sv(const wchar_t *str,  size_t len) noexcept;
198fe6060f1SDimitry Andric  constexpr basic_string_view<char8_t>  operator""sv(const char8_t *str,  size_t len) noexcept; // C++20
1990b57cec5SDimitry Andric  constexpr basic_string_view<char16_t> operator""sv(const char16_t *str, size_t len) noexcept;
2000b57cec5SDimitry Andric  constexpr basic_string_view<char32_t> operator""sv(const char32_t *str, size_t len) noexcept;
2010b57cec5SDimitry Andric
2020b57cec5SDimitry Andric}  // namespace std
2030b57cec5SDimitry Andric
2040b57cec5SDimitry Andric*/
2050b57cec5SDimitry Andric
206*5f757f3fSDimitry Andric// clang-format on
207*5f757f3fSDimitry Andric
20881ad6265SDimitry Andric#include <__algorithm/min.h>
20981ad6265SDimitry Andric#include <__assert> // all public C++ headers provide the assertion handler
2100b57cec5SDimitry Andric#include <__config>
21181ad6265SDimitry Andric#include <__functional/hash.h>
21281ad6265SDimitry Andric#include <__functional/unary_function.h>
21381ad6265SDimitry Andric#include <__fwd/string_view.h>
21406c3fb27SDimitry Andric#include <__iterator/bounded_iter.h>
21581ad6265SDimitry Andric#include <__iterator/concepts.h>
21606c3fb27SDimitry Andric#include <__iterator/iterator_traits.h>
21781ad6265SDimitry Andric#include <__iterator/reverse_iterator.h>
21881ad6265SDimitry Andric#include <__memory/pointer_traits.h>
2194824e7fdSDimitry Andric#include <__ranges/concepts.h>
2204824e7fdSDimitry Andric#include <__ranges/data.h>
221fe6060f1SDimitry Andric#include <__ranges/enable_borrowed_range.h>
222fe6060f1SDimitry Andric#include <__ranges/enable_view.h>
2234824e7fdSDimitry Andric#include <__ranges/size.h>
22481ad6265SDimitry Andric#include <__string/char_traits.h>
22506c3fb27SDimitry Andric#include <__type_traits/is_array.h>
22606c3fb27SDimitry Andric#include <__type_traits/is_convertible.h>
22706c3fb27SDimitry Andric#include <__type_traits/is_same.h>
22806c3fb27SDimitry Andric#include <__type_traits/is_standard_layout.h>
22906c3fb27SDimitry Andric#include <__type_traits/is_trivial.h>
23006c3fb27SDimitry Andric#include <__type_traits/remove_cvref.h>
23106c3fb27SDimitry Andric#include <__type_traits/remove_reference.h>
23206c3fb27SDimitry Andric#include <__type_traits/type_identity.h>
23306c3fb27SDimitry Andric#include <cstddef>
234fe6060f1SDimitry Andric#include <iosfwd>
2350b57cec5SDimitry Andric#include <limits>
2360b57cec5SDimitry Andric#include <stdexcept>
2370b57cec5SDimitry Andric#include <version>
2380b57cec5SDimitry Andric
23981ad6265SDimitry Andric// standard-mandated includes
24081ad6265SDimitry Andric
24181ad6265SDimitry Andric// [iterator.range]
24281ad6265SDimitry Andric#include <__iterator/access.h>
24381ad6265SDimitry Andric#include <__iterator/data.h>
24481ad6265SDimitry Andric#include <__iterator/empty.h>
24581ad6265SDimitry Andric#include <__iterator/reverse_access.h>
24681ad6265SDimitry Andric#include <__iterator/size.h>
24781ad6265SDimitry Andric
24881ad6265SDimitry Andric// [string.view.synop]
24981ad6265SDimitry Andric#include <compare>
25081ad6265SDimitry Andric
2510b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2520b57cec5SDimitry Andric#  pragma GCC system_header
2530b57cec5SDimitry Andric#endif
2540b57cec5SDimitry Andric
2550b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
2560b57cec5SDimitry Andric#include <__undef_macros>
2570b57cec5SDimitry Andric
2580b57cec5SDimitry Andric
2590b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
2600b57cec5SDimitry Andric
26181ad6265SDimitry Andric// TODO: This is a workaround for some vendors to carry a downstream diff to accept `nullptr` in
26281ad6265SDimitry Andric//       string_view constructors. This can be refactored when this exact form isn't needed anymore.
26381ad6265SDimitry Andrictemplate <class _Traits>
26481ad6265SDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
26581ad6265SDimitry Andricinline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
26681ad6265SDimitry Andric  // This needs to be a single statement for C++11 constexpr
267*5f757f3fSDimitry Andric  return _LIBCPP_ASSERT_NON_NULL(
268*5f757f3fSDimitry Andric             __s != nullptr, "null pointer passed to non-null argument of char_traits<...>::length"),
26906c3fb27SDimitry Andric         _Traits::length(__s);
27081ad6265SDimitry Andric}
271e8d8bef9SDimitry Andric
272e8d8bef9SDimitry Andrictemplate<class _CharT, class _Traits>
273bdd1243dSDimitry Andricclass basic_string_view {
2740b57cec5SDimitry Andricpublic:
2750b57cec5SDimitry Andric    // types
276bdd1243dSDimitry Andric    using traits_type            = _Traits;
277bdd1243dSDimitry Andric    using value_type             = _CharT;
278bdd1243dSDimitry Andric    using pointer                = _CharT*;
279bdd1243dSDimitry Andric    using const_pointer          = const _CharT*;
280bdd1243dSDimitry Andric    using reference              = _CharT&;
281bdd1243dSDimitry Andric    using const_reference        = const _CharT&;
28206c3fb27SDimitry Andric#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
28306c3fb27SDimitry Andric    using const_iterator         = __bounded_iter<const_pointer>;
28406c3fb27SDimitry Andric#else
285bdd1243dSDimitry Andric    using const_iterator         = const_pointer; // See [string.view.iterators]
28606c3fb27SDimitry Andric#endif
287bdd1243dSDimitry Andric    using iterator               = const_iterator;
288*5f757f3fSDimitry Andric    using const_reverse_iterator = std::reverse_iterator<const_iterator>;
289bdd1243dSDimitry Andric    using reverse_iterator       = const_reverse_iterator;
290bdd1243dSDimitry Andric    using size_type              = size_t;
291bdd1243dSDimitry Andric    using difference_type        = ptrdiff_t;
2920b57cec5SDimitry Andric    static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
2930b57cec5SDimitry Andric
2940b57cec5SDimitry Andric    static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array");
2950b57cec5SDimitry Andric    static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout");
2960b57cec5SDimitry Andric    static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial");
2970b57cec5SDimitry Andric    static_assert((is_same<_CharT, typename traits_type::char_type>::value),
2980b57cec5SDimitry Andric                  "traits_type::char_type must be the same type as CharT");
2990b57cec5SDimitry Andric
3000b57cec5SDimitry Andric    // [string.view.cons], construct/copy
301*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
302bdd1243dSDimitry Andric    basic_string_view() _NOEXCEPT : __data_(nullptr), __size_(0) {}
3030b57cec5SDimitry Andric
304*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
3050b57cec5SDimitry Andric    basic_string_view(const basic_string_view&) _NOEXCEPT = default;
3060b57cec5SDimitry Andric
307*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
3080b57cec5SDimitry Andric    basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
3090b57cec5SDimitry Andric
310*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
3110b57cec5SDimitry Andric    basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
312bdd1243dSDimitry Andric        : __data_(__s), __size_(__len)
3130b57cec5SDimitry Andric    {
31406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
31506c3fb27SDimitry Andric    _LIBCPP_ASSERT_UNCATEGORIZED(
31606c3fb27SDimitry Andric        __len <= static_cast<size_type>(numeric_limits<difference_type>::max()),
31706c3fb27SDimitry Andric        "string_view::string_view(_CharT *, size_t): length does not fit in difference_type");
318*5f757f3fSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(
319*5f757f3fSDimitry Andric        __len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
3200b57cec5SDimitry Andric#endif
3210b57cec5SDimitry Andric    }
3220b57cec5SDimitry Andric
32306c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
324349cc55cSDimitry Andric    template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
3254824e7fdSDimitry Andric      requires (is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>)
326349cc55cSDimitry Andric    constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end)
327*5f757f3fSDimitry Andric       : __data_(std::to_address(__begin)), __size_(__end - __begin)
328349cc55cSDimitry Andric    {
32906c3fb27SDimitry Andric      _LIBCPP_ASSERT_VALID_INPUT_RANGE((__end - __begin) >= 0,
33006c3fb27SDimitry Andric                                       "std::string_view::string_view(iterator, sentinel) received invalid range");
331349cc55cSDimitry Andric    }
33206c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
333349cc55cSDimitry Andric
33406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
3354824e7fdSDimitry Andric    template <class _Range>
3364824e7fdSDimitry Andric      requires (
3374824e7fdSDimitry Andric        !is_same_v<remove_cvref_t<_Range>, basic_string_view> &&
3384824e7fdSDimitry Andric        ranges::contiguous_range<_Range> &&
3394824e7fdSDimitry Andric        ranges::sized_range<_Range> &&
3404824e7fdSDimitry Andric        is_same_v<ranges::range_value_t<_Range>, _CharT> &&
3414824e7fdSDimitry Andric        !is_convertible_v<_Range, const _CharT*> &&
342753f127fSDimitry Andric        (!requires(remove_cvref_t<_Range>& __d) {
343*5f757f3fSDimitry Andric          __d.operator std::basic_string_view<_CharT, _Traits>();
34406c3fb27SDimitry Andric        })
3454824e7fdSDimitry Andric      )
346bdd1243dSDimitry Andric    constexpr explicit _LIBCPP_HIDE_FROM_ABI
347bdd1243dSDimitry Andric    basic_string_view(_Range&& __r) : __data_(ranges::data(__r)), __size_(ranges::size(__r)) {}
34806c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 23
3494824e7fdSDimitry Andric
350*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
3510b57cec5SDimitry Andric    basic_string_view(const _CharT* __s)
352*5f757f3fSDimitry Andric        : __data_(__s), __size_(std::__char_traits_length_checked<_Traits>(__s)) {}
3530b57cec5SDimitry Andric
35406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
355fe6060f1SDimitry Andric    basic_string_view(nullptr_t) = delete;
356fe6060f1SDimitry Andric#endif
357fe6060f1SDimitry Andric
3580b57cec5SDimitry Andric    // [string.view.iterators], iterators
359*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
3600b57cec5SDimitry Andric    const_iterator begin()  const _NOEXCEPT { return cbegin(); }
3610b57cec5SDimitry Andric
362*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
3630b57cec5SDimitry Andric    const_iterator end()    const _NOEXCEPT { return cend(); }
3640b57cec5SDimitry Andric
365*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
36606c3fb27SDimitry Andric    const_iterator cbegin() const _NOEXCEPT {
36706c3fb27SDimitry Andric#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
36806c3fb27SDimitry Andric        return std::__make_bounded_iter(data(), data(), data() + size());
36906c3fb27SDimitry Andric#else
37006c3fb27SDimitry Andric        return __data_;
37106c3fb27SDimitry Andric#endif
37206c3fb27SDimitry Andric    }
3730b57cec5SDimitry Andric
374*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
37506c3fb27SDimitry Andric    const_iterator cend()   const _NOEXCEPT {
37606c3fb27SDimitry Andric#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
37706c3fb27SDimitry Andric        return std::__make_bounded_iter(data() + size(), data(), data() + size());
37806c3fb27SDimitry Andric#else
37906c3fb27SDimitry Andric        return __data_ + __size_;
38006c3fb27SDimitry Andric#endif
38106c3fb27SDimitry Andric    }
3820b57cec5SDimitry Andric
383*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI
3840b57cec5SDimitry Andric    const_reverse_iterator rbegin()   const _NOEXCEPT { return const_reverse_iterator(cend()); }
3850b57cec5SDimitry Andric
386*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI
3870b57cec5SDimitry Andric    const_reverse_iterator rend()     const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
3880b57cec5SDimitry Andric
389*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI
3900b57cec5SDimitry Andric    const_reverse_iterator crbegin()  const _NOEXCEPT { return const_reverse_iterator(cend()); }
3910b57cec5SDimitry Andric
392*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX17 _LIBCPP_HIDE_FROM_ABI
3930b57cec5SDimitry Andric    const_reverse_iterator crend()    const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
3940b57cec5SDimitry Andric
3950b57cec5SDimitry Andric    // [string.view.capacity], capacity
396*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
397bdd1243dSDimitry Andric    size_type size()     const _NOEXCEPT { return __size_; }
3980b57cec5SDimitry Andric
399*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
400bdd1243dSDimitry Andric    size_type length()   const _NOEXCEPT { return __size_; }
4010b57cec5SDimitry Andric
402*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
4030eae32dcSDimitry Andric    size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max() / sizeof(value_type); }
4040b57cec5SDimitry Andric
405*5f757f3fSDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
406bdd1243dSDimitry Andric    bool empty()         const _NOEXCEPT { return __size_ == 0; }
4070b57cec5SDimitry Andric
4080b57cec5SDimitry Andric    // [string.view.access], element access
409*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
410e8d8bef9SDimitry Andric    const_reference operator[](size_type __pos) const _NOEXCEPT {
41106c3fb27SDimitry Andric      return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__pos < size(), "string_view[] index out of bounds"), __data_[__pos];
412e8d8bef9SDimitry Andric    }
4130b57cec5SDimitry Andric
414*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
4150b57cec5SDimitry Andric    const_reference at(size_type __pos) const
4160b57cec5SDimitry Andric    {
4170b57cec5SDimitry Andric        return __pos >= size()
418bdd1243dSDimitry Andric            ? (__throw_out_of_range("string_view::at"), __data_[0])
419bdd1243dSDimitry Andric            : __data_[__pos];
4200b57cec5SDimitry Andric    }
4210b57cec5SDimitry Andric
422*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
4230b57cec5SDimitry Andric    const_reference front() const _NOEXCEPT
4240b57cec5SDimitry Andric    {
42506c3fb27SDimitry Andric        return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::front(): string is empty"), __data_[0];
4260b57cec5SDimitry Andric    }
4270b57cec5SDimitry Andric
428*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
4290b57cec5SDimitry Andric    const_reference back() const _NOEXCEPT
4300b57cec5SDimitry Andric    {
43106c3fb27SDimitry Andric        return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::back(): string is empty"),
43206c3fb27SDimitry Andric               __data_[__size_ - 1];
4330b57cec5SDimitry Andric    }
4340b57cec5SDimitry Andric
435*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
436bdd1243dSDimitry Andric    const_pointer data() const _NOEXCEPT { return __data_; }
4370b57cec5SDimitry Andric
4380b57cec5SDimitry Andric    // [string.view.modifiers], modifiers:
439*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
4400b57cec5SDimitry Andric    void remove_prefix(size_type __n) _NOEXCEPT
4410b57cec5SDimitry Andric    {
44206c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n <= size(), "remove_prefix() can't remove more than size()");
443bdd1243dSDimitry Andric        __data_ += __n;
444bdd1243dSDimitry Andric        __size_ -= __n;
4450b57cec5SDimitry Andric    }
4460b57cec5SDimitry Andric
447*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
4480b57cec5SDimitry Andric    void remove_suffix(size_type __n) _NOEXCEPT
4490b57cec5SDimitry Andric    {
45006c3fb27SDimitry Andric        _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n <= size(), "remove_suffix() can't remove more than size()");
451bdd1243dSDimitry Andric        __size_ -= __n;
4520b57cec5SDimitry Andric    }
4530b57cec5SDimitry Andric
454*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
4550b57cec5SDimitry Andric    void swap(basic_string_view& __other) _NOEXCEPT
4560b57cec5SDimitry Andric    {
457bdd1243dSDimitry Andric        const value_type *__p = __data_;
458bdd1243dSDimitry Andric        __data_ = __other.__data_;
459bdd1243dSDimitry Andric        __other.__data_ = __p;
4600b57cec5SDimitry Andric
461bdd1243dSDimitry Andric        size_type __sz = __size_;
462bdd1243dSDimitry Andric        __size_ = __other.__size_;
463bdd1243dSDimitry Andric        __other.__size_ = __sz;
4640b57cec5SDimitry Andric    }
4650b57cec5SDimitry Andric
466*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
4670b57cec5SDimitry Andric    size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const
4680b57cec5SDimitry Andric    {
4690b57cec5SDimitry Andric        if (__pos > size())
4700b57cec5SDimitry Andric            __throw_out_of_range("string_view::copy");
471*5f757f3fSDimitry Andric        size_type __rlen = std::min(__n, size() - __pos);
4720b57cec5SDimitry Andric        _Traits::copy(__s, data() + __pos, __rlen);
4730b57cec5SDimitry Andric        return __rlen;
4740b57cec5SDimitry Andric    }
4750b57cec5SDimitry Andric
476*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_HIDE_FROM_ABI
4770b57cec5SDimitry Andric    basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
4780b57cec5SDimitry Andric    {
4790b57cec5SDimitry Andric        return __pos > size()
4800b57cec5SDimitry Andric            ? (__throw_out_of_range("string_view::substr"), basic_string_view())
481*5f757f3fSDimitry Andric            : basic_string_view(data() + __pos, std::min(__n, size() - __pos));
4820b57cec5SDimitry Andric    }
4830b57cec5SDimitry Andric
484bdd1243dSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 int compare(basic_string_view __sv) const _NOEXCEPT
4850b57cec5SDimitry Andric    {
486*5f757f3fSDimitry Andric        size_type __rlen = std::min(size(), __sv.size());
4870b57cec5SDimitry Andric        int __retval = _Traits::compare(data(), __sv.data(), __rlen);
4880b57cec5SDimitry Andric        if (__retval == 0) // first __rlen chars matched
4890b57cec5SDimitry Andric            __retval = size() == __sv.size() ? 0 : (size() < __sv.size() ? -1 : 1);
4900b57cec5SDimitry Andric        return __retval;
4910b57cec5SDimitry Andric    }
4920b57cec5SDimitry Andric
493*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
4940b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const
4950b57cec5SDimitry Andric    {
4960b57cec5SDimitry Andric        return substr(__pos1, __n1).compare(__sv);
4970b57cec5SDimitry Andric    }
4980b57cec5SDimitry Andric
499*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
5000b57cec5SDimitry Andric    int compare(                       size_type __pos1, size_type __n1,
5010b57cec5SDimitry Andric                basic_string_view __sv, size_type __pos2, size_type __n2) const
5020b57cec5SDimitry Andric    {
5030b57cec5SDimitry Andric        return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
5040b57cec5SDimitry Andric    }
5050b57cec5SDimitry Andric
506*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
5070b57cec5SDimitry Andric    int compare(const _CharT* __s) const _NOEXCEPT
5080b57cec5SDimitry Andric    {
5090b57cec5SDimitry Andric        return compare(basic_string_view(__s));
5100b57cec5SDimitry Andric    }
5110b57cec5SDimitry Andric
512*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
5130b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const _CharT* __s) const
5140b57cec5SDimitry Andric    {
5150b57cec5SDimitry Andric        return substr(__pos1, __n1).compare(basic_string_view(__s));
5160b57cec5SDimitry Andric    }
5170b57cec5SDimitry Andric
518*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
5190b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
5200b57cec5SDimitry Andric    {
5210b57cec5SDimitry Andric        return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
5220b57cec5SDimitry Andric    }
5230b57cec5SDimitry Andric
5240b57cec5SDimitry Andric    // find
525*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
5260b57cec5SDimitry Andric    size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
5270b57cec5SDimitry Andric    {
528*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
529bdd1243dSDimitry Andric        return std::__str_find<value_type, size_type, traits_type, npos>
5300b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
5310b57cec5SDimitry Andric    }
5320b57cec5SDimitry Andric
533*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
5340b57cec5SDimitry Andric    size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT
5350b57cec5SDimitry Andric    {
536bdd1243dSDimitry Andric        return std::__str_find<value_type, size_type, traits_type, npos>
5370b57cec5SDimitry Andric            (data(), size(), __c, __pos);
5380b57cec5SDimitry Andric    }
5390b57cec5SDimitry Andric
540*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
541fe6060f1SDimitry Andric    size_type find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
5420b57cec5SDimitry Andric    {
543*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
544bdd1243dSDimitry Andric        return std::__str_find<value_type, size_type, traits_type, npos>
5450b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
5460b57cec5SDimitry Andric    }
5470b57cec5SDimitry Andric
548*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
549fe6060f1SDimitry Andric    size_type find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT
5500b57cec5SDimitry Andric    {
551*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find(): received nullptr");
552bdd1243dSDimitry Andric        return std::__str_find<value_type, size_type, traits_type, npos>
5530b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
5540b57cec5SDimitry Andric    }
5550b57cec5SDimitry Andric
5560b57cec5SDimitry Andric    // rfind
557*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
5580b57cec5SDimitry Andric    size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT
5590b57cec5SDimitry Andric    {
560*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
561bdd1243dSDimitry Andric        return std::__str_rfind<value_type, size_type, traits_type, npos>
5620b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
5630b57cec5SDimitry Andric    }
5640b57cec5SDimitry Andric
565*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
5660b57cec5SDimitry Andric    size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT
5670b57cec5SDimitry Andric    {
568bdd1243dSDimitry Andric        return std::__str_rfind<value_type, size_type, traits_type, npos>
5690b57cec5SDimitry Andric            (data(), size(), __c, __pos);
5700b57cec5SDimitry Andric    }
5710b57cec5SDimitry Andric
572*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
573fe6060f1SDimitry Andric    size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
5740b57cec5SDimitry Andric    {
575*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
576bdd1243dSDimitry Andric        return std::__str_rfind<value_type, size_type, traits_type, npos>
5770b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
5780b57cec5SDimitry Andric    }
5790b57cec5SDimitry Andric
580*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
581fe6060f1SDimitry Andric    size_type rfind(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
5820b57cec5SDimitry Andric    {
583*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::rfind(): received nullptr");
584bdd1243dSDimitry Andric        return std::__str_rfind<value_type, size_type, traits_type, npos>
5850b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
5860b57cec5SDimitry Andric    }
5870b57cec5SDimitry Andric
5880b57cec5SDimitry Andric    // find_first_of
589*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
5900b57cec5SDimitry Andric    size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
5910b57cec5SDimitry Andric    {
592*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(
593*5f757f3fSDimitry Andric            __s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
594bdd1243dSDimitry Andric        return std::__str_find_first_of<value_type, size_type, traits_type, npos>
5950b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
5960b57cec5SDimitry Andric    }
5970b57cec5SDimitry Andric
598*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
5990b57cec5SDimitry Andric    size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT
6000b57cec5SDimitry Andric    { return find(__c, __pos); }
6010b57cec5SDimitry Andric
602*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
603fe6060f1SDimitry Andric    size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
6040b57cec5SDimitry Andric    {
605*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
606bdd1243dSDimitry Andric        return std::__str_find_first_of<value_type, size_type, traits_type, npos>
6070b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
6080b57cec5SDimitry Andric    }
6090b57cec5SDimitry Andric
610*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
611fe6060f1SDimitry Andric    size_type find_first_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT
6120b57cec5SDimitry Andric    {
613*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_of(): received nullptr");
614bdd1243dSDimitry Andric        return std::__str_find_first_of<value_type, size_type, traits_type, npos>
6150b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
6160b57cec5SDimitry Andric    }
6170b57cec5SDimitry Andric
6180b57cec5SDimitry Andric    // find_last_of
619*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
6200b57cec5SDimitry Andric    size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
6210b57cec5SDimitry Andric    {
622*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(
623*5f757f3fSDimitry Andric            __s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
624bdd1243dSDimitry Andric        return std::__str_find_last_of<value_type, size_type, traits_type, npos>
6250b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
6260b57cec5SDimitry Andric    }
6270b57cec5SDimitry Andric
628*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
6290b57cec5SDimitry Andric    size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT
6300b57cec5SDimitry Andric    { return rfind(__c, __pos); }
6310b57cec5SDimitry Andric
632*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
633fe6060f1SDimitry Andric    size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
6340b57cec5SDimitry Andric    {
635*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
636bdd1243dSDimitry Andric        return std::__str_find_last_of<value_type, size_type, traits_type, npos>
6370b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
6380b57cec5SDimitry Andric    }
6390b57cec5SDimitry Andric
640*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
641fe6060f1SDimitry Andric    size_type find_last_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
6420b57cec5SDimitry Andric    {
643*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_of(): received nullptr");
644bdd1243dSDimitry Andric        return std::__str_find_last_of<value_type, size_type, traits_type, npos>
6450b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
6460b57cec5SDimitry Andric    }
6470b57cec5SDimitry Andric
6480b57cec5SDimitry Andric    // find_first_not_of
649*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
6500b57cec5SDimitry Andric    size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT
6510b57cec5SDimitry Andric    {
652*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(
653*5f757f3fSDimitry Andric            __s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
654bdd1243dSDimitry Andric        return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>
6550b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
6560b57cec5SDimitry Andric    }
6570b57cec5SDimitry Andric
658*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
6590b57cec5SDimitry Andric    size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT
6600b57cec5SDimitry Andric    {
661bdd1243dSDimitry Andric        return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>
6620b57cec5SDimitry Andric            (data(), size(), __c, __pos);
6630b57cec5SDimitry Andric    }
6640b57cec5SDimitry Andric
665*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
666fe6060f1SDimitry Andric    size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
6670b57cec5SDimitry Andric    {
668*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
669bdd1243dSDimitry Andric        return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>
6700b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
6710b57cec5SDimitry Andric    }
6720b57cec5SDimitry Andric
673*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
674fe6060f1SDimitry Andric    size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT
6750b57cec5SDimitry Andric    {
676*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
677bdd1243dSDimitry Andric        return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>
6780b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
6790b57cec5SDimitry Andric    }
6800b57cec5SDimitry Andric
6810b57cec5SDimitry Andric    // find_last_not_of
682*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
6830b57cec5SDimitry Andric    size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
6840b57cec5SDimitry Andric    {
685*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(
686*5f757f3fSDimitry Andric            __s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
687bdd1243dSDimitry Andric        return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>
6880b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
6890b57cec5SDimitry Andric    }
6900b57cec5SDimitry Andric
691*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
6920b57cec5SDimitry Andric    size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT
6930b57cec5SDimitry Andric    {
694bdd1243dSDimitry Andric        return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>
6950b57cec5SDimitry Andric            (data(), size(), __c, __pos);
6960b57cec5SDimitry Andric    }
6970b57cec5SDimitry Andric
698*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
699fe6060f1SDimitry Andric    size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
7000b57cec5SDimitry Andric    {
701*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
702bdd1243dSDimitry Andric        return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>
7030b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
7040b57cec5SDimitry Andric    }
7050b57cec5SDimitry Andric
706*5f757f3fSDimitry Andric    _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
707fe6060f1SDimitry Andric    size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
7080b57cec5SDimitry Andric    {
709*5f757f3fSDimitry Andric        _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
710bdd1243dSDimitry Andric        return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>
7110b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
7120b57cec5SDimitry Andric    }
7130b57cec5SDimitry Andric
71406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
715*5f757f3fSDimitry Andric    constexpr _LIBCPP_HIDE_FROM_ABI
716349cc55cSDimitry Andric    bool starts_with(basic_string_view __s) const noexcept
7170b57cec5SDimitry Andric    { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; }
7180b57cec5SDimitry Andric
719*5f757f3fSDimitry Andric    constexpr _LIBCPP_HIDE_FROM_ABI
720349cc55cSDimitry Andric    bool starts_with(value_type __c) const noexcept
7210b57cec5SDimitry Andric    { return !empty() && _Traits::eq(front(), __c); }
7220b57cec5SDimitry Andric
723*5f757f3fSDimitry Andric    constexpr _LIBCPP_HIDE_FROM_ABI
724349cc55cSDimitry Andric    bool starts_with(const value_type* __s) const noexcept
7250b57cec5SDimitry Andric    { return starts_with(basic_string_view(__s)); }
7260b57cec5SDimitry Andric
727*5f757f3fSDimitry Andric    constexpr _LIBCPP_HIDE_FROM_ABI
728349cc55cSDimitry Andric    bool ends_with(basic_string_view __s) const noexcept
7290b57cec5SDimitry Andric    { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; }
7300b57cec5SDimitry Andric
731*5f757f3fSDimitry Andric    constexpr _LIBCPP_HIDE_FROM_ABI
732349cc55cSDimitry Andric    bool ends_with(value_type __c) const noexcept
7330b57cec5SDimitry Andric    { return !empty() && _Traits::eq(back(), __c); }
7340b57cec5SDimitry Andric
735*5f757f3fSDimitry Andric    constexpr _LIBCPP_HIDE_FROM_ABI
736349cc55cSDimitry Andric    bool ends_with(const value_type* __s) const noexcept
7370b57cec5SDimitry Andric    { return ends_with(basic_string_view(__s)); }
7380b57cec5SDimitry Andric#endif
7390b57cec5SDimitry Andric
74006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
741*5f757f3fSDimitry Andric    constexpr _LIBCPP_HIDE_FROM_ABI
742e8d8bef9SDimitry Andric    bool contains(basic_string_view __sv) const noexcept
743e8d8bef9SDimitry Andric    { return find(__sv) != npos; }
744e8d8bef9SDimitry Andric
745*5f757f3fSDimitry Andric    constexpr _LIBCPP_HIDE_FROM_ABI
746e8d8bef9SDimitry Andric    bool contains(value_type __c) const noexcept
747e8d8bef9SDimitry Andric    { return find(__c) != npos; }
748e8d8bef9SDimitry Andric
749*5f757f3fSDimitry Andric    constexpr _LIBCPP_HIDE_FROM_ABI
750e8d8bef9SDimitry Andric    bool contains(const value_type* __s) const
751e8d8bef9SDimitry Andric    { return find(__s) != npos; }
752e8d8bef9SDimitry Andric#endif
753e8d8bef9SDimitry Andric
7540b57cec5SDimitry Andricprivate:
755bdd1243dSDimitry Andric    const   value_type* __data_;
756bdd1243dSDimitry Andric    size_type           __size_;
7570b57cec5SDimitry Andric};
758bdd1243dSDimitry Andric_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_string_view);
7590b57cec5SDimitry Andric
76006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
761fe6060f1SDimitry Andrictemplate <class _CharT, class _Traits>
762fe6060f1SDimitry Andricinline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true;
763fe6060f1SDimitry Andric
764fe6060f1SDimitry Andrictemplate <class _CharT, class _Traits>
765fe6060f1SDimitry Andricinline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true;
76606c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
7670b57cec5SDimitry Andric
768349cc55cSDimitry Andric// [string.view.deduct]
769349cc55cSDimitry Andric
77006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
771349cc55cSDimitry Andrictemplate <contiguous_iterator _It, sized_sentinel_for<_It> _End>
772349cc55cSDimitry Andric  basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
77306c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
774349cc55cSDimitry Andric
7754824e7fdSDimitry Andric
77606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 23
7774824e7fdSDimitry Andrictemplate <ranges::contiguous_range _Range>
7784824e7fdSDimitry Andric  basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>;
779bdd1243dSDimitry Andric#endif
7804824e7fdSDimitry Andric
7810b57cec5SDimitry Andric// [string.view.comparison]
782bdd1243dSDimitry Andric
78306c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
784bdd1243dSDimitry Andric
785bdd1243dSDimitry Andrictemplate<class _CharT, class _Traits>
786*5f757f3fSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr
787*5f757f3fSDimitry Andricbool operator==(basic_string_view<_CharT, _Traits> __lhs,
788*5f757f3fSDimitry Andric                type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) noexcept {
789*5f757f3fSDimitry Andric    if (__lhs.size() != __rhs.size()) return false;
790*5f757f3fSDimitry Andric    return __lhs.compare(__rhs) == 0;
791bdd1243dSDimitry Andric}
792bdd1243dSDimitry Andric
793*5f757f3fSDimitry Andrictemplate <class _CharT, class _Traits>
794bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI constexpr auto operator<=>(
795bdd1243dSDimitry Andric    basic_string_view<_CharT, _Traits> __lhs, type_identity_t<basic_string_view<_CharT, _Traits>> __rhs) noexcept {
796bdd1243dSDimitry Andric    if constexpr (requires { typename _Traits::comparison_category; }) {
797bdd1243dSDimitry Andric        // [string.view]/4
798bdd1243dSDimitry Andric        static_assert(
799bdd1243dSDimitry Andric            __comparison_category<typename _Traits::comparison_category>,
800bdd1243dSDimitry Andric            "return type is not a comparison category type");
801bdd1243dSDimitry Andric        return static_cast<typename _Traits::comparison_category>(__lhs.compare(__rhs) <=> 0);
802bdd1243dSDimitry Andric    } else {
803bdd1243dSDimitry Andric        return static_cast<weak_ordering>(__lhs.compare(__rhs) <=> 0);
804bdd1243dSDimitry Andric    }
805bdd1243dSDimitry Andric}
806bdd1243dSDimitry Andric
807*5f757f3fSDimitry Andric#else
808*5f757f3fSDimitry Andric
809*5f757f3fSDimitry Andric// operator ==
810*5f757f3fSDimitry Andric
811*5f757f3fSDimitry Andrictemplate<class _CharT, class _Traits>
812*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
813*5f757f3fSDimitry Andricbool operator==(basic_string_view<_CharT, _Traits> __lhs,
814*5f757f3fSDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
815*5f757f3fSDimitry Andric{
816*5f757f3fSDimitry Andric    if (__lhs.size() != __rhs.size()) return false;
817*5f757f3fSDimitry Andric    return __lhs.compare(__rhs) == 0;
818*5f757f3fSDimitry Andric}
819*5f757f3fSDimitry Andric
820*5f757f3fSDimitry Andric// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details.
821*5f757f3fSDimitry Andric// This applies to the other sufficient overloads below for the other comparison operators.
822*5f757f3fSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
823*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
824*5f757f3fSDimitry Andricbool operator==(basic_string_view<_CharT, _Traits> __lhs,
825*5f757f3fSDimitry Andric                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
826*5f757f3fSDimitry Andric{
827*5f757f3fSDimitry Andric    if (__lhs.size() != __rhs.size()) return false;
828*5f757f3fSDimitry Andric    return __lhs.compare(__rhs) == 0;
829*5f757f3fSDimitry Andric}
830*5f757f3fSDimitry Andric
831*5f757f3fSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
832*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
833*5f757f3fSDimitry Andricbool operator==(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
834*5f757f3fSDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
835*5f757f3fSDimitry Andric{
836*5f757f3fSDimitry Andric    if (__lhs.size() != __rhs.size()) return false;
837*5f757f3fSDimitry Andric    return __lhs.compare(__rhs) == 0;
838*5f757f3fSDimitry Andric}
8390b57cec5SDimitry Andric
8400b57cec5SDimitry Andric// operator !=
8410b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
842*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
8430b57cec5SDimitry Andricbool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8440b57cec5SDimitry Andric{
8450b57cec5SDimitry Andric    if (__lhs.size() != __rhs.size())
8460b57cec5SDimitry Andric        return true;
8470b57cec5SDimitry Andric    return __lhs.compare(__rhs) != 0;
8480b57cec5SDimitry Andric}
8490b57cec5SDimitry Andric
8504824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
851*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
8520b57cec5SDimitry Andricbool operator!=(basic_string_view<_CharT, _Traits> __lhs,
853bdd1243dSDimitry Andric                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
8540b57cec5SDimitry Andric{
8550b57cec5SDimitry Andric    if (__lhs.size() != __rhs.size())
8560b57cec5SDimitry Andric        return true;
8570b57cec5SDimitry Andric    return __lhs.compare(__rhs) != 0;
8580b57cec5SDimitry Andric}
8590b57cec5SDimitry Andric
8604824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
861*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
862bdd1243dSDimitry Andricbool operator!=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
8630b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8640b57cec5SDimitry Andric{
8650b57cec5SDimitry Andric    if (__lhs.size() != __rhs.size())
8660b57cec5SDimitry Andric        return true;
8670b57cec5SDimitry Andric    return __lhs.compare(__rhs) != 0;
8680b57cec5SDimitry Andric}
8690b57cec5SDimitry Andric
8700b57cec5SDimitry Andric
8710b57cec5SDimitry Andric// operator <
8720b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
873*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
8740b57cec5SDimitry Andricbool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8750b57cec5SDimitry Andric{
8760b57cec5SDimitry Andric    return __lhs.compare(__rhs) < 0;
8770b57cec5SDimitry Andric}
8780b57cec5SDimitry Andric
8794824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
880*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
8810b57cec5SDimitry Andricbool operator<(basic_string_view<_CharT, _Traits> __lhs,
882bdd1243dSDimitry Andric                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
8830b57cec5SDimitry Andric{
8840b57cec5SDimitry Andric    return __lhs.compare(__rhs) < 0;
8850b57cec5SDimitry Andric}
8860b57cec5SDimitry Andric
8874824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
888*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
889bdd1243dSDimitry Andricbool operator<(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
8900b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8910b57cec5SDimitry Andric{
8920b57cec5SDimitry Andric    return __lhs.compare(__rhs) < 0;
8930b57cec5SDimitry Andric}
8940b57cec5SDimitry Andric
8950b57cec5SDimitry Andric
8960b57cec5SDimitry Andric// operator >
8970b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
898*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
8990b57cec5SDimitry Andricbool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
9000b57cec5SDimitry Andric{
9010b57cec5SDimitry Andric    return __lhs.compare(__rhs) > 0;
9020b57cec5SDimitry Andric}
9030b57cec5SDimitry Andric
9044824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
905*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
9060b57cec5SDimitry Andricbool operator>(basic_string_view<_CharT, _Traits> __lhs,
907bdd1243dSDimitry Andric                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
9080b57cec5SDimitry Andric{
9090b57cec5SDimitry Andric    return __lhs.compare(__rhs) > 0;
9100b57cec5SDimitry Andric}
9110b57cec5SDimitry Andric
9124824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
913*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
914bdd1243dSDimitry Andricbool operator>(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
9150b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
9160b57cec5SDimitry Andric{
9170b57cec5SDimitry Andric    return __lhs.compare(__rhs) > 0;
9180b57cec5SDimitry Andric}
9190b57cec5SDimitry Andric
9200b57cec5SDimitry Andric
9210b57cec5SDimitry Andric// operator <=
9220b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
923*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
9240b57cec5SDimitry Andricbool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
9250b57cec5SDimitry Andric{
9260b57cec5SDimitry Andric    return __lhs.compare(__rhs) <= 0;
9270b57cec5SDimitry Andric}
9280b57cec5SDimitry Andric
9294824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
930*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
9310b57cec5SDimitry Andricbool operator<=(basic_string_view<_CharT, _Traits> __lhs,
932bdd1243dSDimitry Andric                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
9330b57cec5SDimitry Andric{
9340b57cec5SDimitry Andric    return __lhs.compare(__rhs) <= 0;
9350b57cec5SDimitry Andric}
9360b57cec5SDimitry Andric
9374824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
938*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
939bdd1243dSDimitry Andricbool operator<=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
9400b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
9410b57cec5SDimitry Andric{
9420b57cec5SDimitry Andric    return __lhs.compare(__rhs) <= 0;
9430b57cec5SDimitry Andric}
9440b57cec5SDimitry Andric
9450b57cec5SDimitry Andric
9460b57cec5SDimitry Andric// operator >=
9470b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
948*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
9490b57cec5SDimitry Andricbool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
9500b57cec5SDimitry Andric{
9510b57cec5SDimitry Andric    return __lhs.compare(__rhs) >= 0;
9520b57cec5SDimitry Andric}
9530b57cec5SDimitry Andric
9540b57cec5SDimitry Andric
9554824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
956*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
9570b57cec5SDimitry Andricbool operator>=(basic_string_view<_CharT, _Traits> __lhs,
958bdd1243dSDimitry Andric                __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT
9590b57cec5SDimitry Andric{
9600b57cec5SDimitry Andric    return __lhs.compare(__rhs) >= 0;
9610b57cec5SDimitry Andric}
9620b57cec5SDimitry Andric
9634824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
964*5f757f3fSDimitry Andric_LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI
965bdd1243dSDimitry Andricbool operator>=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
9660b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
9670b57cec5SDimitry Andric{
9680b57cec5SDimitry Andric    return __lhs.compare(__rhs) >= 0;
9690b57cec5SDimitry Andric}
9700b57cec5SDimitry Andric
97106c3fb27SDimitry Andric#endif //  _LIBCPP_STD_VER >= 20
972e40139ffSDimitry Andric
973e40139ffSDimitry Andrictemplate<class _CharT, class _Traits>
974bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
975e40139ffSDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os,
976e40139ffSDimitry Andric           basic_string_view<_CharT, _Traits> __str);
977e40139ffSDimitry Andric
9780b57cec5SDimitry Andric// [string.view.hash]
9790b57cec5SDimitry Andrictemplate<class _CharT>
980bdd1243dSDimitry Andricstruct __string_view_hash : public __unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t>
9810b57cec5SDimitry Andric{
982*5f757f3fSDimitry Andric    _LIBCPP_HIDE_FROM_ABI
9830b57cec5SDimitry Andric    size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT {
984bdd1243dSDimitry Andric        return std::__do_string_hash(__val.data(), __val.data() + __val.size());
9850b57cec5SDimitry Andric    }
9860b57cec5SDimitry Andric};
9870b57cec5SDimitry Andric
988bdd1243dSDimitry Andrictemplate <>
989bdd1243dSDimitry Andricstruct hash<basic_string_view<char, char_traits<char> > > : __string_view_hash<char> {};
990bdd1243dSDimitry Andric
991bdd1243dSDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
992bdd1243dSDimitry Andrictemplate <>
993bdd1243dSDimitry Andricstruct hash<basic_string_view<char8_t, char_traits<char8_t> > > : __string_view_hash<char8_t> {};
994bdd1243dSDimitry Andric#endif
995bdd1243dSDimitry Andric
996bdd1243dSDimitry Andrictemplate <>
997bdd1243dSDimitry Andricstruct hash<basic_string_view<char16_t, char_traits<char16_t> > > : __string_view_hash<char16_t> {};
998bdd1243dSDimitry Andric
999bdd1243dSDimitry Andrictemplate <>
1000bdd1243dSDimitry Andricstruct hash<basic_string_view<char32_t, char_traits<char32_t> > > : __string_view_hash<char32_t> {};
1001bdd1243dSDimitry Andric
1002bdd1243dSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1003bdd1243dSDimitry Andrictemplate <>
1004bdd1243dSDimitry Andricstruct hash<basic_string_view<wchar_t, char_traits<wchar_t> > > : __string_view_hash<wchar_t> {};
1005bdd1243dSDimitry Andric#endif
1006bdd1243dSDimitry Andric
100706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
10080b57cec5SDimitry Andricinline namespace literals
10090b57cec5SDimitry Andric{
10100b57cec5SDimitry Andric  inline namespace string_view_literals
10110b57cec5SDimitry Andric  {
1012*5f757f3fSDimitry Andric    inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
10130b57cec5SDimitry Andric    basic_string_view<char> operator""sv(const char *__str, size_t __len) _NOEXCEPT
10140b57cec5SDimitry Andric    {
10150b57cec5SDimitry Andric        return basic_string_view<char> (__str, __len);
10160b57cec5SDimitry Andric    }
10170b57cec5SDimitry Andric
1018349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1019*5f757f3fSDimitry Andric    inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
10200b57cec5SDimitry Andric    basic_string_view<wchar_t> operator""sv(const wchar_t *__str, size_t __len) _NOEXCEPT
10210b57cec5SDimitry Andric    {
10220b57cec5SDimitry Andric        return basic_string_view<wchar_t> (__str, __len);
10230b57cec5SDimitry Andric    }
1024349cc55cSDimitry Andric#endif
10250b57cec5SDimitry Andric
1026fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
1027*5f757f3fSDimitry Andric    inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
10280b57cec5SDimitry Andric    basic_string_view<char8_t> operator""sv(const char8_t *__str, size_t __len) _NOEXCEPT
10290b57cec5SDimitry Andric    {
10300b57cec5SDimitry Andric        return basic_string_view<char8_t> (__str, __len);
10310b57cec5SDimitry Andric    }
10320b57cec5SDimitry Andric#endif
10330b57cec5SDimitry Andric
1034*5f757f3fSDimitry Andric    inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
10350b57cec5SDimitry Andric    basic_string_view<char16_t> operator""sv(const char16_t *__str, size_t __len) _NOEXCEPT
10360b57cec5SDimitry Andric    {
10370b57cec5SDimitry Andric        return basic_string_view<char16_t> (__str, __len);
10380b57cec5SDimitry Andric    }
10390b57cec5SDimitry Andric
1040*5f757f3fSDimitry Andric    inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR
10410b57cec5SDimitry Andric    basic_string_view<char32_t> operator""sv(const char32_t *__str, size_t __len) _NOEXCEPT
10420b57cec5SDimitry Andric    {
10430b57cec5SDimitry Andric        return basic_string_view<char32_t> (__str, __len);
10440b57cec5SDimitry Andric    }
10450eae32dcSDimitry Andric  } // namespace string_view_literals
10460eae32dcSDimitry Andric} // namespace literals
10470b57cec5SDimitry Andric#endif
10480b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
10490b57cec5SDimitry Andric
10500b57cec5SDimitry Andric_LIBCPP_POP_MACROS
10510b57cec5SDimitry Andric
1052bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1053bdd1243dSDimitry Andric#  include <algorithm>
1054bdd1243dSDimitry Andric#  include <concepts>
105506c3fb27SDimitry Andric#  include <cstdlib>
1056bdd1243dSDimitry Andric#  include <iterator>
105706c3fb27SDimitry Andric#  include <type_traits>
1058bdd1243dSDimitry Andric#endif
1059bdd1243dSDimitry Andric
10600b57cec5SDimitry Andric#endif // _LIBCPP_STRING_VIEW
1061