xref: /freebsd/contrib/llvm-project/libcxx/include/__cxx03/string_view (revision 700637cbb5e582861067a11aaca4d053546871d2)
1*700637cbSDimitry Andric// -*- C++ -*-
2*700637cbSDimitry Andric//===----------------------------------------------------------------------===//
3*700637cbSDimitry Andric//
4*700637cbSDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5*700637cbSDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
6*700637cbSDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7*700637cbSDimitry Andric//
8*700637cbSDimitry Andric//===----------------------------------------------------------------------===//
9*700637cbSDimitry Andric
10*700637cbSDimitry Andric#ifndef _LIBCPP___CXX03_STRING_VIEW
11*700637cbSDimitry Andric#define _LIBCPP___CXX03_STRING_VIEW
12*700637cbSDimitry Andric
13*700637cbSDimitry Andric// clang-format off
14*700637cbSDimitry Andric
15*700637cbSDimitry Andric/*
16*700637cbSDimitry Andric
17*700637cbSDimitry Andric    string_view synopsis
18*700637cbSDimitry Andric
19*700637cbSDimitry Andric#include <__cxx03/compare>
20*700637cbSDimitry Andric
21*700637cbSDimitry Andricnamespace std {
22*700637cbSDimitry Andric
23*700637cbSDimitry Andric    // 7.2, Class template basic_string_view
24*700637cbSDimitry Andric    template<class charT, class traits = char_traits<charT>>
25*700637cbSDimitry Andric        class basic_string_view;
26*700637cbSDimitry Andric
27*700637cbSDimitry Andric    template<class charT, class traits>
28*700637cbSDimitry Andric    inline constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true;
29*700637cbSDimitry Andric
30*700637cbSDimitry Andric    template<class charT, class traits>
31*700637cbSDimitry Andric    inline constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true;  // C++20
32*700637cbSDimitry Andric
33*700637cbSDimitry Andric    // 7.9, basic_string_view non-member comparison functions
34*700637cbSDimitry Andric    template<class charT, class traits>
35*700637cbSDimitry Andric    constexpr bool operator==(basic_string_view<charT, traits> x,
36*700637cbSDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
37*700637cbSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
38*700637cbSDimitry Andric    constexpr bool operator!=(basic_string_view<charT, traits> x,
39*700637cbSDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
40*700637cbSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
41*700637cbSDimitry Andric    constexpr bool operator< (basic_string_view<charT, traits> x,
42*700637cbSDimitry Andric                                 basic_string_view<charT, traits> y) noexcept;
43*700637cbSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
44*700637cbSDimitry Andric    constexpr bool operator> (basic_string_view<charT, traits> x,
45*700637cbSDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
46*700637cbSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
47*700637cbSDimitry Andric    constexpr bool operator<=(basic_string_view<charT, traits> x,
48*700637cbSDimitry Andric                                 basic_string_view<charT, traits> y) noexcept;
49*700637cbSDimitry Andric    template<class charT, class traits>                                                            // Removed in C++20
50*700637cbSDimitry Andric    constexpr bool operator>=(basic_string_view<charT, traits> x,
51*700637cbSDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
52*700637cbSDimitry Andric    template<class charT, class traits>                                                            // Since C++20
53*700637cbSDimitry Andric    constexpr see below operator<=>(basic_string_view<charT, traits> x,
54*700637cbSDimitry Andric                                    basic_string_view<charT, traits> y) noexcept;
55*700637cbSDimitry Andric
56*700637cbSDimitry Andric    // see below, sufficient additional overloads of comparison functions
57*700637cbSDimitry Andric
58*700637cbSDimitry Andric    // 7.10, Inserters and extractors
59*700637cbSDimitry Andric    template<class charT, class traits>
60*700637cbSDimitry Andric      basic_ostream<charT, traits>&
61*700637cbSDimitry Andric        operator<<(basic_ostream<charT, traits>& os,
62*700637cbSDimitry Andric                   basic_string_view<charT, traits> str);
63*700637cbSDimitry Andric
64*700637cbSDimitry Andric    // basic_string_view typedef names
65*700637cbSDimitry Andric    typedef basic_string_view<char> string_view;
66*700637cbSDimitry Andric    typedef basic_string_view<char8_t> u8string_view; // C++20
67*700637cbSDimitry Andric    typedef basic_string_view<char16_t> u16string_view;
68*700637cbSDimitry Andric    typedef basic_string_view<char32_t> u32string_view;
69*700637cbSDimitry Andric    typedef basic_string_view<wchar_t> wstring_view;
70*700637cbSDimitry Andric
71*700637cbSDimitry Andric    template<class charT, class traits = char_traits<charT>>
72*700637cbSDimitry Andric    class basic_string_view {
73*700637cbSDimitry Andric      public:
74*700637cbSDimitry Andric      // types
75*700637cbSDimitry Andric      typedef traits traits_type;
76*700637cbSDimitry Andric      typedef charT value_type;
77*700637cbSDimitry Andric      typedef charT* pointer;
78*700637cbSDimitry Andric      typedef const charT* const_pointer;
79*700637cbSDimitry Andric      typedef charT& reference;
80*700637cbSDimitry Andric      typedef const charT& const_reference;
81*700637cbSDimitry Andric      typedef implementation-defined const_iterator;
82*700637cbSDimitry Andric      typedef const_iterator iterator;
83*700637cbSDimitry Andric      typedef reverse_iterator<const_iterator> const_reverse_iterator;
84*700637cbSDimitry Andric      typedef const_reverse_iterator reverse_iterator;
85*700637cbSDimitry Andric      typedef size_t size_type;
86*700637cbSDimitry Andric      typedef ptrdiff_t difference_type;
87*700637cbSDimitry Andric      static constexpr size_type npos = size_type(-1);
88*700637cbSDimitry Andric
89*700637cbSDimitry Andric      // 7.3, basic_string_view constructors and assignment operators
90*700637cbSDimitry Andric      constexpr basic_string_view() noexcept;
91*700637cbSDimitry Andric      constexpr basic_string_view(const basic_string_view&) noexcept = default;
92*700637cbSDimitry Andric      basic_string_view& operator=(const basic_string_view&) noexcept = default;
93*700637cbSDimitry Andric      template<class Allocator>
94*700637cbSDimitry Andric      constexpr basic_string_view(const charT* str);
95*700637cbSDimitry Andric      basic_string_view(nullptr_t) = delete; // C++23
96*700637cbSDimitry Andric      constexpr basic_string_view(const charT* str, size_type len);
97*700637cbSDimitry Andric      template <class It, class End>
98*700637cbSDimitry Andric      constexpr basic_string_view(It begin, End end); // C++20
99*700637cbSDimitry Andric      template <class Range>
100*700637cbSDimitry Andric      constexpr basic_string_view(Range&& r); // C++23
101*700637cbSDimitry Andric
102*700637cbSDimitry Andric      // 7.4, basic_string_view iterator support
103*700637cbSDimitry Andric      constexpr const_iterator begin() const noexcept;
104*700637cbSDimitry Andric      constexpr const_iterator end() const noexcept;
105*700637cbSDimitry Andric      constexpr const_iterator cbegin() const noexcept;
106*700637cbSDimitry Andric      constexpr const_iterator cend() const noexcept;
107*700637cbSDimitry Andric      const_reverse_iterator rbegin() const noexcept;
108*700637cbSDimitry Andric      const_reverse_iterator rend() const noexcept;
109*700637cbSDimitry Andric      const_reverse_iterator crbegin() const noexcept;
110*700637cbSDimitry Andric      const_reverse_iterator crend() const noexcept;
111*700637cbSDimitry Andric
112*700637cbSDimitry Andric      // 7.5, basic_string_view capacity
113*700637cbSDimitry Andric      constexpr size_type size() const noexcept;
114*700637cbSDimitry Andric      constexpr size_type length() const noexcept;
115*700637cbSDimitry Andric      constexpr size_type max_size() const noexcept;
116*700637cbSDimitry Andric      constexpr bool empty() const noexcept;
117*700637cbSDimitry Andric
118*700637cbSDimitry Andric      // 7.6, basic_string_view element access
119*700637cbSDimitry Andric      constexpr const_reference operator[](size_type pos) const;
120*700637cbSDimitry Andric      constexpr const_reference at(size_type pos) const;
121*700637cbSDimitry Andric      constexpr const_reference front() const;
122*700637cbSDimitry Andric      constexpr const_reference back() const;
123*700637cbSDimitry Andric      constexpr const_pointer data() const noexcept;
124*700637cbSDimitry Andric
125*700637cbSDimitry Andric      // 7.7, basic_string_view modifiers
126*700637cbSDimitry Andric      constexpr void remove_prefix(size_type n);
127*700637cbSDimitry Andric      constexpr void remove_suffix(size_type n);
128*700637cbSDimitry Andric      constexpr void swap(basic_string_view& s) noexcept;
129*700637cbSDimitry Andric
130*700637cbSDimitry Andric      size_type copy(charT* s, size_type n, size_type pos = 0) const;  // constexpr in C++20
131*700637cbSDimitry Andric
132*700637cbSDimitry Andric      constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
133*700637cbSDimitry Andric      constexpr int compare(basic_string_view s) const noexcept;
134*700637cbSDimitry Andric      constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
135*700637cbSDimitry Andric      constexpr int compare(size_type pos1, size_type n1,
136*700637cbSDimitry Andric                            basic_string_view s, size_type pos2, size_type n2) const;
137*700637cbSDimitry Andric      constexpr int compare(const charT* s) const;
138*700637cbSDimitry Andric      constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
139*700637cbSDimitry Andric      constexpr int compare(size_type pos1, size_type n1,
140*700637cbSDimitry Andric                            const charT* s, size_type n2) const;
141*700637cbSDimitry Andric      constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
142*700637cbSDimitry Andric      constexpr size_type find(charT c, size_type pos = 0) const noexcept;
143*700637cbSDimitry Andric      constexpr size_type find(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
144*700637cbSDimitry Andric      constexpr size_type find(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
145*700637cbSDimitry Andric      constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
146*700637cbSDimitry Andric      constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
147*700637cbSDimitry Andric      constexpr size_type rfind(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
148*700637cbSDimitry Andric      constexpr size_type rfind(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
149*700637cbSDimitry Andric      constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
150*700637cbSDimitry Andric      constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
151*700637cbSDimitry Andric      constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
152*700637cbSDimitry Andric      constexpr size_type find_first_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
153*700637cbSDimitry Andric      constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
154*700637cbSDimitry Andric      constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
155*700637cbSDimitry Andric      constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
156*700637cbSDimitry Andric      constexpr size_type find_last_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
157*700637cbSDimitry Andric      constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
158*700637cbSDimitry Andric      constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
159*700637cbSDimitry Andric      constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
160*700637cbSDimitry Andric      constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
161*700637cbSDimitry Andric      constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
162*700637cbSDimitry Andric      constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
163*700637cbSDimitry Andric      constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
164*700637cbSDimitry Andric      constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
165*700637cbSDimitry Andric
166*700637cbSDimitry Andric      constexpr bool starts_with(basic_string_view s) const noexcept; // C++20
167*700637cbSDimitry Andric      constexpr bool starts_with(charT c) const noexcept;             // C++20
168*700637cbSDimitry Andric      constexpr bool starts_with(const charT* s) const;               // C++20
169*700637cbSDimitry Andric      constexpr bool ends_with(basic_string_view s) const noexcept;   // C++20
170*700637cbSDimitry Andric      constexpr bool ends_with(charT c) const noexcept;               // C++20
171*700637cbSDimitry Andric      constexpr bool ends_with(const charT* s) const;                 // C++20
172*700637cbSDimitry Andric
173*700637cbSDimitry Andric      constexpr bool contains(basic_string_view s) const noexcept; // C++23
174*700637cbSDimitry Andric      constexpr bool contains(charT c) const noexcept;             // C++23
175*700637cbSDimitry Andric      constexpr bool contains(const charT* s) const;               // C++23
176*700637cbSDimitry Andric
177*700637cbSDimitry Andric     private:
178*700637cbSDimitry Andric      const_pointer data_;  // exposition only
179*700637cbSDimitry Andric      size_type     size_;  // exposition only
180*700637cbSDimitry Andric    };
181*700637cbSDimitry Andric
182*700637cbSDimitry Andric  // basic_string_view deduction guides
183*700637cbSDimitry Andric  template<class It, class End>
184*700637cbSDimitry Andric    basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>; // C++20
185*700637cbSDimitry Andric  template<class Range>
186*700637cbSDimitry Andric    basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23
187*700637cbSDimitry Andric
188*700637cbSDimitry Andric  // 7.11, Hash support
189*700637cbSDimitry Andric  template <class T> struct hash;
190*700637cbSDimitry Andric  template <> struct hash<string_view>;
191*700637cbSDimitry Andric  template <> struct hash<u8string_view>; // C++20
192*700637cbSDimitry Andric  template <> struct hash<u16string_view>;
193*700637cbSDimitry Andric  template <> struct hash<u32string_view>;
194*700637cbSDimitry Andric  template <> struct hash<wstring_view>;
195*700637cbSDimitry Andric
196*700637cbSDimitry Andric  constexpr basic_string_view<char>     operator""sv(const char *str,     size_t len) noexcept;
197*700637cbSDimitry Andric  constexpr basic_string_view<wchar_t>  operator""sv(const wchar_t *str,  size_t len) noexcept;
198*700637cbSDimitry Andric  constexpr basic_string_view<char8_t>  operator""sv(const char8_t *str,  size_t len) noexcept; // C++20
199*700637cbSDimitry Andric  constexpr basic_string_view<char16_t> operator""sv(const char16_t *str, size_t len) noexcept;
200*700637cbSDimitry Andric  constexpr basic_string_view<char32_t> operator""sv(const char32_t *str, size_t len) noexcept;
201*700637cbSDimitry Andric
202*700637cbSDimitry Andric}  // namespace std
203*700637cbSDimitry Andric
204*700637cbSDimitry Andric*/
205*700637cbSDimitry Andric
206*700637cbSDimitry Andric// clang-format on
207*700637cbSDimitry Andric
208*700637cbSDimitry Andric#include <__cxx03/__algorithm/min.h>
209*700637cbSDimitry Andric#include <__cxx03/__assert>
210*700637cbSDimitry Andric#include <__cxx03/__config>
211*700637cbSDimitry Andric#include <__cxx03/__functional/hash.h>
212*700637cbSDimitry Andric#include <__cxx03/__functional/unary_function.h>
213*700637cbSDimitry Andric#include <__cxx03/__fwd/ostream.h>
214*700637cbSDimitry Andric#include <__cxx03/__fwd/string_view.h>
215*700637cbSDimitry Andric#include <__cxx03/__iterator/bounded_iter.h>
216*700637cbSDimitry Andric#include <__cxx03/__iterator/iterator_traits.h>
217*700637cbSDimitry Andric#include <__cxx03/__iterator/reverse_iterator.h>
218*700637cbSDimitry Andric#include <__cxx03/__iterator/wrap_iter.h>
219*700637cbSDimitry Andric#include <__cxx03/__memory/pointer_traits.h>
220*700637cbSDimitry Andric#include <__cxx03/__string/char_traits.h>
221*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_array.h>
222*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_convertible.h>
223*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_same.h>
224*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_standard_layout.h>
225*700637cbSDimitry Andric#include <__cxx03/__type_traits/is_trivial.h>
226*700637cbSDimitry Andric#include <__cxx03/__type_traits/remove_cvref.h>
227*700637cbSDimitry Andric#include <__cxx03/__type_traits/remove_reference.h>
228*700637cbSDimitry Andric#include <__cxx03/__type_traits/type_identity.h>
229*700637cbSDimitry Andric#include <__cxx03/cstddef>
230*700637cbSDimitry Andric#include <__cxx03/iosfwd>
231*700637cbSDimitry Andric#include <__cxx03/limits>
232*700637cbSDimitry Andric#include <__cxx03/stdexcept>
233*700637cbSDimitry Andric#include <__cxx03/version>
234*700637cbSDimitry Andric
235*700637cbSDimitry Andric// standard-mandated includes
236*700637cbSDimitry Andric
237*700637cbSDimitry Andric// [iterator.range]
238*700637cbSDimitry Andric#include <__cxx03/__iterator/access.h>
239*700637cbSDimitry Andric
240*700637cbSDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
241*700637cbSDimitry Andric#  pragma GCC system_header
242*700637cbSDimitry Andric#endif
243*700637cbSDimitry Andric
244*700637cbSDimitry Andric_LIBCPP_PUSH_MACROS
245*700637cbSDimitry Andric#include <__cxx03/__undef_macros>
246*700637cbSDimitry Andric
247*700637cbSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
248*700637cbSDimitry Andric
249*700637cbSDimitry Andric// TODO: This is a workaround for some vendors to carry a downstream diff to accept `nullptr` in
250*700637cbSDimitry Andric//       string_view constructors. This can be refactored when this exact form isn't needed anymore.
251*700637cbSDimitry Andrictemplate <class _Traits>
252*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
253*700637cbSDimitry Andric  // This needs to be a single statement for C++11 constexpr
254*700637cbSDimitry Andric  return _LIBCPP_ASSERT_NON_NULL(
255*700637cbSDimitry Andric             __s != nullptr, "null pointer passed to non-null argument of char_traits<...>::length"),
256*700637cbSDimitry Andric         _Traits::length(__s);
257*700637cbSDimitry Andric}
258*700637cbSDimitry Andric
259*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
260*700637cbSDimitry Andricclass basic_string_view {
261*700637cbSDimitry Andricpublic:
262*700637cbSDimitry Andric  // types
263*700637cbSDimitry Andric  using traits_type     = _Traits;
264*700637cbSDimitry Andric  using value_type      = _CharT;
265*700637cbSDimitry Andric  using pointer         = _CharT*;
266*700637cbSDimitry Andric  using const_pointer   = const _CharT*;
267*700637cbSDimitry Andric  using reference       = _CharT&;
268*700637cbSDimitry Andric  using const_reference = const _CharT&;
269*700637cbSDimitry Andric#if defined(_LIBCPP_ABI_BOUNDED_ITERATORS)
270*700637cbSDimitry Andric  using const_iterator = __bounded_iter<const_pointer>;
271*700637cbSDimitry Andric#elif defined(_LIBCPP_ABI_USE_WRAP_ITER_IN_STD_STRING_VIEW)
272*700637cbSDimitry Andric  using const_iterator = __wrap_iter<const_pointer>;
273*700637cbSDimitry Andric#else
274*700637cbSDimitry Andric  using const_iterator = const_pointer;
275*700637cbSDimitry Andric#endif
276*700637cbSDimitry Andric  using iterator               = const_iterator;
277*700637cbSDimitry Andric  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
278*700637cbSDimitry Andric  using reverse_iterator       = const_reverse_iterator;
279*700637cbSDimitry Andric  using size_type              = size_t;
280*700637cbSDimitry Andric  using difference_type        = ptrdiff_t;
281*700637cbSDimitry Andric  static const size_type npos  = -1; // size_type(-1);
282*700637cbSDimitry Andric
283*700637cbSDimitry Andric  static_assert(!is_array<value_type>::value, "Character type of basic_string_view must not be an array");
284*700637cbSDimitry Andric  static_assert(is_standard_layout<value_type>::value, "Character type of basic_string_view must be standard-layout");
285*700637cbSDimitry Andric  static_assert(is_trivial<value_type>::value, "Character type of basic_string_view must be trivial");
286*700637cbSDimitry Andric  static_assert(is_same<_CharT, typename traits_type::char_type>::value,
287*700637cbSDimitry Andric                "traits_type::char_type must be the same type as CharT");
288*700637cbSDimitry Andric
289*700637cbSDimitry Andric  // [string.view.cons], construct/copy
290*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_string_view() _NOEXCEPT : __data_(nullptr), __size_(0) {}
291*700637cbSDimitry Andric
292*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_string_view(const basic_string_view&) _NOEXCEPT = default;
293*700637cbSDimitry Andric
294*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
295*700637cbSDimitry Andric
296*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
297*700637cbSDimitry Andric      : __data_(__s),
298*700637cbSDimitry Andric        __size_(__len) {}
299*700637cbSDimitry Andric
300*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_string_view(const _CharT* __s)
301*700637cbSDimitry Andric      : __data_(__s), __size_(std::__char_traits_length_checked<_Traits>(__s)) {}
302*700637cbSDimitry Andric
303*700637cbSDimitry Andric  // [string.view.iterators], iterators
304*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return cbegin(); }
305*700637cbSDimitry Andric
306*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return cend(); }
307*700637cbSDimitry Andric
308*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT {
309*700637cbSDimitry Andric#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
310*700637cbSDimitry Andric    return std::__make_bounded_iter(data(), data(), data() + size());
311*700637cbSDimitry Andric#else
312*700637cbSDimitry Andric    return const_iterator(__data_);
313*700637cbSDimitry Andric#endif
314*700637cbSDimitry Andric  }
315*700637cbSDimitry Andric
316*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT {
317*700637cbSDimitry Andric#ifdef _LIBCPP_ABI_BOUNDED_ITERATORS
318*700637cbSDimitry Andric    return std::__make_bounded_iter(data() + size(), data(), data() + size());
319*700637cbSDimitry Andric#else
320*700637cbSDimitry Andric    return const_iterator(__data_ + __size_);
321*700637cbSDimitry Andric#endif
322*700637cbSDimitry Andric  }
323*700637cbSDimitry Andric
324*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); }
325*700637cbSDimitry Andric
326*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
327*700637cbSDimitry Andric
328*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); }
329*700637cbSDimitry Andric
330*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
331*700637cbSDimitry Andric
332*700637cbSDimitry Andric  // [string.view.capacity], capacity
333*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __size_; }
334*700637cbSDimitry Andric
335*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type length() const _NOEXCEPT { return __size_; }
336*700637cbSDimitry Andric
337*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
338*700637cbSDimitry Andric    return numeric_limits<size_type>::max() / sizeof(value_type);
339*700637cbSDimitry Andric  }
340*700637cbSDimitry Andric
341*700637cbSDimitry Andric  _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __size_ == 0; }
342*700637cbSDimitry Andric
343*700637cbSDimitry Andric  // [string.view.access], element access
344*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __pos) const _NOEXCEPT {
345*700637cbSDimitry Andric    return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__pos < size(), "string_view[] index out of bounds"), __data_[__pos];
346*700637cbSDimitry Andric  }
347*700637cbSDimitry Andric
348*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference at(size_type __pos) const {
349*700637cbSDimitry Andric    return __pos >= size() ? (__throw_out_of_range("string_view::at"), __data_[0]) : __data_[__pos];
350*700637cbSDimitry Andric  }
351*700637cbSDimitry Andric
352*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference front() const _NOEXCEPT {
353*700637cbSDimitry Andric    return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::front(): string is empty"), __data_[0];
354*700637cbSDimitry Andric  }
355*700637cbSDimitry Andric
356*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference back() const _NOEXCEPT {
357*700637cbSDimitry Andric    return _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "string_view::back(): string is empty"), __data_[__size_ - 1];
358*700637cbSDimitry Andric  }
359*700637cbSDimitry Andric
360*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_pointer data() const _NOEXCEPT { return __data_; }
361*700637cbSDimitry Andric
362*700637cbSDimitry Andric  // [string.view.modifiers], modifiers:
363*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void remove_prefix(size_type __n) _NOEXCEPT {
364*700637cbSDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n <= size(), "remove_prefix() can't remove more than size()");
365*700637cbSDimitry Andric    __data_ += __n;
366*700637cbSDimitry Andric    __size_ -= __n;
367*700637cbSDimitry Andric  }
368*700637cbSDimitry Andric
369*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void remove_suffix(size_type __n) _NOEXCEPT {
370*700637cbSDimitry Andric    _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__n <= size(), "remove_suffix() can't remove more than size()");
371*700637cbSDimitry Andric    __size_ -= __n;
372*700637cbSDimitry Andric  }
373*700637cbSDimitry Andric
374*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(basic_string_view& __other) _NOEXCEPT {
375*700637cbSDimitry Andric    const value_type* __p = __data_;
376*700637cbSDimitry Andric    __data_               = __other.__data_;
377*700637cbSDimitry Andric    __other.__data_       = __p;
378*700637cbSDimitry Andric
379*700637cbSDimitry Andric    size_type __sz  = __size_;
380*700637cbSDimitry Andric    __size_         = __other.__size_;
381*700637cbSDimitry Andric    __other.__size_ = __sz;
382*700637cbSDimitry Andric  }
383*700637cbSDimitry Andric
384*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const {
385*700637cbSDimitry Andric    if (__pos > size())
386*700637cbSDimitry Andric      __throw_out_of_range("string_view::copy");
387*700637cbSDimitry Andric    size_type __rlen = std::min(__n, size() - __pos);
388*700637cbSDimitry Andric    _Traits::copy(__s, data() + __pos, __rlen);
389*700637cbSDimitry Andric    return __rlen;
390*700637cbSDimitry Andric  }
391*700637cbSDimitry Andric
392*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_string_view substr(size_type __pos = 0, size_type __n = npos) const {
393*700637cbSDimitry Andric    return __pos > size() ? (__throw_out_of_range("string_view::substr"), basic_string_view())
394*700637cbSDimitry Andric                          : basic_string_view(data() + __pos, std::min(__n, size() - __pos));
395*700637cbSDimitry Andric  }
396*700637cbSDimitry Andric
397*700637cbSDimitry Andric  int compare(basic_string_view __sv) const _NOEXCEPT {
398*700637cbSDimitry Andric    size_type __rlen = std::min(size(), __sv.size());
399*700637cbSDimitry Andric    int __retval     = _Traits::compare(data(), __sv.data(), __rlen);
400*700637cbSDimitry Andric    if (__retval == 0) // first __rlen chars matched
401*700637cbSDimitry Andric      __retval = size() == __sv.size() ? 0 : (size() < __sv.size() ? -1 : 1);
402*700637cbSDimitry Andric    return __retval;
403*700637cbSDimitry Andric  }
404*700637cbSDimitry Andric
405*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const {
406*700637cbSDimitry Andric    return substr(__pos1, __n1).compare(__sv);
407*700637cbSDimitry Andric  }
408*700637cbSDimitry Andric
409*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI int
410*700637cbSDimitry Andric  compare(size_type __pos1, size_type __n1, basic_string_view __sv, size_type __pos2, size_type __n2) const {
411*700637cbSDimitry Andric    return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
412*700637cbSDimitry Andric  }
413*700637cbSDimitry Andric
414*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI int compare(const _CharT* __s) const _NOEXCEPT { return compare(basic_string_view(__s)); }
415*700637cbSDimitry Andric
416*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI int compare(size_type __pos1, size_type __n1, const _CharT* __s) const {
417*700637cbSDimitry Andric    return substr(__pos1, __n1).compare(basic_string_view(__s));
418*700637cbSDimitry Andric  }
419*700637cbSDimitry Andric
420*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const {
421*700637cbSDimitry Andric    return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
422*700637cbSDimitry Andric  }
423*700637cbSDimitry Andric
424*700637cbSDimitry Andric  // find
425*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
426*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
427*700637cbSDimitry Andric    return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __s.data(), __pos, __s.size());
428*700637cbSDimitry Andric  }
429*700637cbSDimitry Andric
430*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT {
431*700637cbSDimitry Andric    return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
432*700637cbSDimitry Andric  }
433*700637cbSDimitry Andric
434*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
435*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
436*700637cbSDimitry Andric    return std::__str_find<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
437*700637cbSDimitry Andric  }
438*700637cbSDimitry Andric
439*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT {
440*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find(): received nullptr");
441*700637cbSDimitry Andric    return std::__str_find<value_type, size_type, traits_type, npos>(
442*700637cbSDimitry Andric        data(), size(), __s, __pos, traits_type::length(__s));
443*700637cbSDimitry Andric  }
444*700637cbSDimitry Andric
445*700637cbSDimitry Andric  // rfind
446*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
447*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
448*700637cbSDimitry Andric    return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __s.data(), __pos, __s.size());
449*700637cbSDimitry Andric  }
450*700637cbSDimitry Andric
451*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT {
452*700637cbSDimitry Andric    return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
453*700637cbSDimitry Andric  }
454*700637cbSDimitry Andric
455*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
456*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
457*700637cbSDimitry Andric    return std::__str_rfind<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
458*700637cbSDimitry Andric  }
459*700637cbSDimitry Andric
460*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type rfind(const _CharT* __s, size_type __pos = npos) const _NOEXCEPT {
461*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::rfind(): received nullptr");
462*700637cbSDimitry Andric    return std::__str_rfind<value_type, size_type, traits_type, npos>(
463*700637cbSDimitry Andric        data(), size(), __s, __pos, traits_type::length(__s));
464*700637cbSDimitry Andric  }
465*700637cbSDimitry Andric
466*700637cbSDimitry Andric  // find_first_of
467*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
468*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
469*700637cbSDimitry Andric    return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
470*700637cbSDimitry Andric        data(), size(), __s.data(), __pos, __s.size());
471*700637cbSDimitry Andric  }
472*700637cbSDimitry Andric
473*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT {
474*700637cbSDimitry Andric    return find(__c, __pos);
475*700637cbSDimitry Andric  }
476*700637cbSDimitry Andric
477*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
478*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
479*700637cbSDimitry Andric    return std::__str_find_first_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
480*700637cbSDimitry Andric  }
481*700637cbSDimitry Andric
482*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_first_of(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT {
483*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_of(): received nullptr");
484*700637cbSDimitry Andric    return std::__str_find_first_of<value_type, size_type, traits_type, npos>(
485*700637cbSDimitry Andric        data(), size(), __s, __pos, traits_type::length(__s));
486*700637cbSDimitry Andric  }
487*700637cbSDimitry Andric
488*700637cbSDimitry Andric  // find_last_of
489*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_last_of(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
490*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
491*700637cbSDimitry Andric    return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
492*700637cbSDimitry Andric        data(), size(), __s.data(), __pos, __s.size());
493*700637cbSDimitry Andric  }
494*700637cbSDimitry Andric
495*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT {
496*700637cbSDimitry Andric    return rfind(__c, __pos);
497*700637cbSDimitry Andric  }
498*700637cbSDimitry Andric
499*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
500*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
501*700637cbSDimitry Andric    return std::__str_find_last_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
502*700637cbSDimitry Andric  }
503*700637cbSDimitry Andric
504*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_last_of(const _CharT* __s, size_type __pos = npos) const _NOEXCEPT {
505*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_of(): received nullptr");
506*700637cbSDimitry Andric    return std::__str_find_last_of<value_type, size_type, traits_type, npos>(
507*700637cbSDimitry Andric        data(), size(), __s, __pos, traits_type::length(__s));
508*700637cbSDimitry Andric  }
509*700637cbSDimitry Andric
510*700637cbSDimitry Andric  // find_first_not_of
511*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_first_not_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT {
512*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(
513*700637cbSDimitry Andric        __s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
514*700637cbSDimitry Andric    return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
515*700637cbSDimitry Andric        data(), size(), __s.data(), __pos, __s.size());
516*700637cbSDimitry Andric  }
517*700637cbSDimitry Andric
518*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_first_not_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT {
519*700637cbSDimitry Andric    return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
520*700637cbSDimitry Andric  }
521*700637cbSDimitry Andric
522*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
523*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
524*700637cbSDimitry Andric    return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
525*700637cbSDimitry Andric  }
526*700637cbSDimitry Andric
527*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_first_not_of(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT {
528*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
529*700637cbSDimitry Andric    return std::__str_find_first_not_of<value_type, size_type, traits_type, npos>(
530*700637cbSDimitry Andric        data(), size(), __s, __pos, traits_type::length(__s));
531*700637cbSDimitry Andric  }
532*700637cbSDimitry Andric
533*700637cbSDimitry Andric  // find_last_not_of
534*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_last_not_of(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT {
535*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(
536*700637cbSDimitry Andric        __s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
537*700637cbSDimitry Andric    return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
538*700637cbSDimitry Andric        data(), size(), __s.data(), __pos, __s.size());
539*700637cbSDimitry Andric  }
540*700637cbSDimitry Andric
541*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_last_not_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT {
542*700637cbSDimitry Andric    return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(data(), size(), __c, __pos);
543*700637cbSDimitry Andric  }
544*700637cbSDimitry Andric
545*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT {
546*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
547*700637cbSDimitry Andric    return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(data(), size(), __s, __pos, __n);
548*700637cbSDimitry Andric  }
549*700637cbSDimitry Andric
550*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type find_last_not_of(const _CharT* __s, size_type __pos = npos) const _NOEXCEPT {
551*700637cbSDimitry Andric    _LIBCPP_ASSERT_NON_NULL(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
552*700637cbSDimitry Andric    return std::__str_find_last_not_of<value_type, size_type, traits_type, npos>(
553*700637cbSDimitry Andric        data(), size(), __s, __pos, traits_type::length(__s));
554*700637cbSDimitry Andric  }
555*700637cbSDimitry Andric
556*700637cbSDimitry Andricprivate:
557*700637cbSDimitry Andric  const value_type* __data_;
558*700637cbSDimitry Andric  size_type __size_;
559*700637cbSDimitry Andric};
560*700637cbSDimitry Andric_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(basic_string_view);
561*700637cbSDimitry Andric
562*700637cbSDimitry Andric// operator ==
563*700637cbSDimitry Andric
564*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
565*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool
566*700637cbSDimitry Andricoperator==(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
567*700637cbSDimitry Andric  if (__lhs.size() != __rhs.size())
568*700637cbSDimitry Andric    return false;
569*700637cbSDimitry Andric  return __lhs.compare(__rhs) == 0;
570*700637cbSDimitry Andric}
571*700637cbSDimitry Andric
572*700637cbSDimitry Andric// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details.
573*700637cbSDimitry Andric// This applies to the other sufficient overloads below for the other comparison operators.
574*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, int = 1>
575*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator==(basic_string_view<_CharT, _Traits> __lhs,
576*700637cbSDimitry Andric                                      __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
577*700637cbSDimitry Andric  if (__lhs.size() != __rhs.size())
578*700637cbSDimitry Andric    return false;
579*700637cbSDimitry Andric  return __lhs.compare(__rhs) == 0;
580*700637cbSDimitry Andric}
581*700637cbSDimitry Andric
582*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, int = 2>
583*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator==(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
584*700637cbSDimitry Andric                                      basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
585*700637cbSDimitry Andric  if (__lhs.size() != __rhs.size())
586*700637cbSDimitry Andric    return false;
587*700637cbSDimitry Andric  return __lhs.compare(__rhs) == 0;
588*700637cbSDimitry Andric}
589*700637cbSDimitry Andric
590*700637cbSDimitry Andric// operator !=
591*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
592*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool
593*700637cbSDimitry Andricoperator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
594*700637cbSDimitry Andric  if (__lhs.size() != __rhs.size())
595*700637cbSDimitry Andric    return true;
596*700637cbSDimitry Andric  return __lhs.compare(__rhs) != 0;
597*700637cbSDimitry Andric}
598*700637cbSDimitry Andric
599*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, int = 1>
600*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator!=(basic_string_view<_CharT, _Traits> __lhs,
601*700637cbSDimitry Andric                                      __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
602*700637cbSDimitry Andric  if (__lhs.size() != __rhs.size())
603*700637cbSDimitry Andric    return true;
604*700637cbSDimitry Andric  return __lhs.compare(__rhs) != 0;
605*700637cbSDimitry Andric}
606*700637cbSDimitry Andric
607*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, int = 2>
608*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator!=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
609*700637cbSDimitry Andric                                      basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
610*700637cbSDimitry Andric  if (__lhs.size() != __rhs.size())
611*700637cbSDimitry Andric    return true;
612*700637cbSDimitry Andric  return __lhs.compare(__rhs) != 0;
613*700637cbSDimitry Andric}
614*700637cbSDimitry Andric
615*700637cbSDimitry Andric// operator <
616*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
617*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool
618*700637cbSDimitry Andricoperator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
619*700637cbSDimitry Andric  return __lhs.compare(__rhs) < 0;
620*700637cbSDimitry Andric}
621*700637cbSDimitry Andric
622*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, int = 1>
623*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator<(basic_string_view<_CharT, _Traits> __lhs,
624*700637cbSDimitry Andric                                     __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
625*700637cbSDimitry Andric  return __lhs.compare(__rhs) < 0;
626*700637cbSDimitry Andric}
627*700637cbSDimitry Andric
628*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, int = 2>
629*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator<(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
630*700637cbSDimitry Andric                                     basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
631*700637cbSDimitry Andric  return __lhs.compare(__rhs) < 0;
632*700637cbSDimitry Andric}
633*700637cbSDimitry Andric
634*700637cbSDimitry Andric// operator >
635*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
636*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool
637*700637cbSDimitry Andricoperator>(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
638*700637cbSDimitry Andric  return __lhs.compare(__rhs) > 0;
639*700637cbSDimitry Andric}
640*700637cbSDimitry Andric
641*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, int = 1>
642*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator>(basic_string_view<_CharT, _Traits> __lhs,
643*700637cbSDimitry Andric                                     __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
644*700637cbSDimitry Andric  return __lhs.compare(__rhs) > 0;
645*700637cbSDimitry Andric}
646*700637cbSDimitry Andric
647*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, int = 2>
648*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator>(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
649*700637cbSDimitry Andric                                     basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
650*700637cbSDimitry Andric  return __lhs.compare(__rhs) > 0;
651*700637cbSDimitry Andric}
652*700637cbSDimitry Andric
653*700637cbSDimitry Andric// operator <=
654*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
655*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool
656*700637cbSDimitry Andricoperator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
657*700637cbSDimitry Andric  return __lhs.compare(__rhs) <= 0;
658*700637cbSDimitry Andric}
659*700637cbSDimitry Andric
660*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, int = 1>
661*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator<=(basic_string_view<_CharT, _Traits> __lhs,
662*700637cbSDimitry Andric                                      __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
663*700637cbSDimitry Andric  return __lhs.compare(__rhs) <= 0;
664*700637cbSDimitry Andric}
665*700637cbSDimitry Andric
666*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, int = 2>
667*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator<=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
668*700637cbSDimitry Andric                                      basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
669*700637cbSDimitry Andric  return __lhs.compare(__rhs) <= 0;
670*700637cbSDimitry Andric}
671*700637cbSDimitry Andric
672*700637cbSDimitry Andric// operator >=
673*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
674*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool
675*700637cbSDimitry Andricoperator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
676*700637cbSDimitry Andric  return __lhs.compare(__rhs) >= 0;
677*700637cbSDimitry Andric}
678*700637cbSDimitry Andric
679*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, int = 1>
680*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator>=(basic_string_view<_CharT, _Traits> __lhs,
681*700637cbSDimitry Andric                                      __type_identity_t<basic_string_view<_CharT, _Traits> > __rhs) _NOEXCEPT {
682*700637cbSDimitry Andric  return __lhs.compare(__rhs) >= 0;
683*700637cbSDimitry Andric}
684*700637cbSDimitry Andric
685*700637cbSDimitry Andrictemplate <class _CharT, class _Traits, int = 2>
686*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator>=(__type_identity_t<basic_string_view<_CharT, _Traits> > __lhs,
687*700637cbSDimitry Andric                                      basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT {
688*700637cbSDimitry Andric  return __lhs.compare(__rhs) >= 0;
689*700637cbSDimitry Andric}
690*700637cbSDimitry Andric
691*700637cbSDimitry Andrictemplate <class _CharT, class _Traits>
692*700637cbSDimitry Andric_LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _Traits>&
693*700637cbSDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os, basic_string_view<_CharT, _Traits> __str);
694*700637cbSDimitry Andric
695*700637cbSDimitry Andric// [string.view.hash]
696*700637cbSDimitry Andrictemplate <class _CharT>
697*700637cbSDimitry Andricstruct __string_view_hash : public __unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t> {
698*700637cbSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT {
699*700637cbSDimitry Andric    return std::__do_string_hash(__val.data(), __val.data() + __val.size());
700*700637cbSDimitry Andric  }
701*700637cbSDimitry Andric};
702*700637cbSDimitry Andric
703*700637cbSDimitry Andrictemplate <>
704*700637cbSDimitry Andricstruct hash<basic_string_view<char, char_traits<char> > > : __string_view_hash<char> {};
705*700637cbSDimitry Andric
706*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
707*700637cbSDimitry Andrictemplate <>
708*700637cbSDimitry Andricstruct hash<basic_string_view<char8_t, char_traits<char8_t> > > : __string_view_hash<char8_t> {};
709*700637cbSDimitry Andric#endif
710*700637cbSDimitry Andric
711*700637cbSDimitry Andrictemplate <>
712*700637cbSDimitry Andricstruct hash<basic_string_view<char16_t, char_traits<char16_t> > > : __string_view_hash<char16_t> {};
713*700637cbSDimitry Andric
714*700637cbSDimitry Andrictemplate <>
715*700637cbSDimitry Andricstruct hash<basic_string_view<char32_t, char_traits<char32_t> > > : __string_view_hash<char32_t> {};
716*700637cbSDimitry Andric
717*700637cbSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
718*700637cbSDimitry Andrictemplate <>
719*700637cbSDimitry Andricstruct hash<basic_string_view<wchar_t, char_traits<wchar_t> > > : __string_view_hash<wchar_t> {};
720*700637cbSDimitry Andric#endif
721*700637cbSDimitry Andric
722*700637cbSDimitry Andric_LIBCPP_END_NAMESPACE_STD
723*700637cbSDimitry Andric
724*700637cbSDimitry Andric_LIBCPP_POP_MACROS
725*700637cbSDimitry Andric
726*700637cbSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES)
727*700637cbSDimitry Andric#  include <__cxx03/algorithm>
728*700637cbSDimitry Andric#  include <__cxx03/cstdlib>
729*700637cbSDimitry Andric#  include <__cxx03/iterator>
730*700637cbSDimitry Andric#  include <__cxx03/type_traits>
731*700637cbSDimitry Andric#endif
732*700637cbSDimitry Andric
733*700637cbSDimitry Andric#endif // _LIBCPP___CXX03_STRING_VIEW
734