xref: /freebsd/contrib/llvm-project/libcxx/include/string_view (revision 4824e7fd18a1223177218d4aec1b3c6c5c4a444e)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_STRING_VIEW
110b57cec5SDimitry Andric#define _LIBCPP_STRING_VIEW
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andricstring_view synopsis
150b57cec5SDimitry Andric
160b57cec5SDimitry Andricnamespace std {
170b57cec5SDimitry Andric
180b57cec5SDimitry Andric    // 7.2, Class template basic_string_view
190b57cec5SDimitry Andric    template<class charT, class traits = char_traits<charT>>
200b57cec5SDimitry Andric        class basic_string_view;
210b57cec5SDimitry Andric
22fe6060f1SDimitry Andric    template<class charT, class traits>
23fe6060f1SDimitry Andric    inline constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true;
24fe6060f1SDimitry Andric
25fe6060f1SDimitry Andric    template<class charT, class traits>
26fe6060f1SDimitry Andric    inline constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true;  // C++20
27fe6060f1SDimitry Andric
280b57cec5SDimitry Andric    // 7.9, basic_string_view non-member comparison functions
290b57cec5SDimitry Andric    template<class charT, class traits>
300b57cec5SDimitry Andric    constexpr bool operator==(basic_string_view<charT, traits> x,
310b57cec5SDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
320b57cec5SDimitry Andric    template<class charT, class traits>
330b57cec5SDimitry Andric    constexpr bool operator!=(basic_string_view<charT, traits> x,
340b57cec5SDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
350b57cec5SDimitry Andric    template<class charT, class traits>
360b57cec5SDimitry Andric    constexpr bool operator< (basic_string_view<charT, traits> x,
370b57cec5SDimitry Andric                                 basic_string_view<charT, traits> y) noexcept;
380b57cec5SDimitry Andric    template<class charT, class traits>
390b57cec5SDimitry Andric    constexpr bool operator> (basic_string_view<charT, traits> x,
400b57cec5SDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
410b57cec5SDimitry Andric    template<class charT, class traits>
420b57cec5SDimitry Andric    constexpr bool operator<=(basic_string_view<charT, traits> x,
430b57cec5SDimitry Andric                                 basic_string_view<charT, traits> y) noexcept;
440b57cec5SDimitry Andric    template<class charT, class traits>
450b57cec5SDimitry Andric    constexpr bool operator>=(basic_string_view<charT, traits> x,
460b57cec5SDimitry Andric                              basic_string_view<charT, traits> y) noexcept;
470b57cec5SDimitry Andric    // see below, sufficient additional overloads of comparison functions
480b57cec5SDimitry Andric
490b57cec5SDimitry Andric    // 7.10, Inserters and extractors
500b57cec5SDimitry Andric    template<class charT, class traits>
510b57cec5SDimitry Andric      basic_ostream<charT, traits>&
520b57cec5SDimitry Andric        operator<<(basic_ostream<charT, traits>& os,
530b57cec5SDimitry Andric                   basic_string_view<charT, traits> str);
540b57cec5SDimitry Andric
550b57cec5SDimitry Andric    // basic_string_view typedef names
560b57cec5SDimitry Andric    typedef basic_string_view<char> string_view;
57fe6060f1SDimitry Andric    typedef basic_string_view<char8_t> u8string_view; // C++20
580b57cec5SDimitry Andric    typedef basic_string_view<char16_t> u16string_view;
590b57cec5SDimitry Andric    typedef basic_string_view<char32_t> u32string_view;
600b57cec5SDimitry Andric    typedef basic_string_view<wchar_t> wstring_view;
610b57cec5SDimitry Andric
620b57cec5SDimitry Andric    template<class charT, class traits = char_traits<charT>>
630b57cec5SDimitry Andric    class basic_string_view {
640b57cec5SDimitry Andric      public:
650b57cec5SDimitry Andric      // types
660b57cec5SDimitry Andric      typedef traits traits_type;
670b57cec5SDimitry Andric      typedef charT value_type;
680b57cec5SDimitry Andric      typedef charT* pointer;
690b57cec5SDimitry Andric      typedef const charT* const_pointer;
700b57cec5SDimitry Andric      typedef charT& reference;
710b57cec5SDimitry Andric      typedef const charT& const_reference;
720b57cec5SDimitry Andric      typedef implementation-defined const_iterator;
730b57cec5SDimitry Andric      typedef const_iterator iterator;
740b57cec5SDimitry Andric      typedef reverse_iterator<const_iterator> const_reverse_iterator;
750b57cec5SDimitry Andric      typedef const_reverse_iterator reverse_iterator;
760b57cec5SDimitry Andric      typedef size_t size_type;
770b57cec5SDimitry Andric      typedef ptrdiff_t difference_type;
780b57cec5SDimitry Andric      static constexpr size_type npos = size_type(-1);
790b57cec5SDimitry Andric
800b57cec5SDimitry Andric      // 7.3, basic_string_view constructors and assignment operators
810b57cec5SDimitry Andric      constexpr basic_string_view() noexcept;
820b57cec5SDimitry Andric      constexpr basic_string_view(const basic_string_view&) noexcept = default;
830b57cec5SDimitry Andric      basic_string_view& operator=(const basic_string_view&) noexcept = default;
840b57cec5SDimitry Andric      template<class Allocator>
850b57cec5SDimitry Andric      constexpr basic_string_view(const charT* str);
86fe6060f1SDimitry Andric      basic_string_view(nullptr_t) = delete; // C++2b
870b57cec5SDimitry Andric      constexpr basic_string_view(const charT* str, size_type len);
88349cc55cSDimitry Andric      template <class It, class End>
89349cc55cSDimitry Andric      constexpr basic_string_view(It begin, End end); // C++20
90*4824e7fdSDimitry Andric      template <class Range>
91*4824e7fdSDimitry Andric      constexpr basic_string_view(Range&& r); // C++23
920b57cec5SDimitry Andric
930b57cec5SDimitry Andric      // 7.4, basic_string_view iterator support
940b57cec5SDimitry Andric      constexpr const_iterator begin() const noexcept;
950b57cec5SDimitry Andric      constexpr const_iterator end() const noexcept;
960b57cec5SDimitry Andric      constexpr const_iterator cbegin() const noexcept;
970b57cec5SDimitry Andric      constexpr const_iterator cend() const noexcept;
980b57cec5SDimitry Andric      const_reverse_iterator rbegin() const noexcept;
990b57cec5SDimitry Andric      const_reverse_iterator rend() const noexcept;
1000b57cec5SDimitry Andric      const_reverse_iterator crbegin() const noexcept;
1010b57cec5SDimitry Andric      const_reverse_iterator crend() const noexcept;
1020b57cec5SDimitry Andric
1030b57cec5SDimitry Andric      // 7.5, basic_string_view capacity
1040b57cec5SDimitry Andric      constexpr size_type size() const noexcept;
1050b57cec5SDimitry Andric      constexpr size_type length() const noexcept;
1060b57cec5SDimitry Andric      constexpr size_type max_size() const noexcept;
1070b57cec5SDimitry Andric      constexpr bool empty() const noexcept;
1080b57cec5SDimitry Andric
1090b57cec5SDimitry Andric      // 7.6, basic_string_view element access
1100b57cec5SDimitry Andric      constexpr const_reference operator[](size_type pos) const;
1110b57cec5SDimitry Andric      constexpr const_reference at(size_type pos) const;
1120b57cec5SDimitry Andric      constexpr const_reference front() const;
1130b57cec5SDimitry Andric      constexpr const_reference back() const;
1140b57cec5SDimitry Andric      constexpr const_pointer data() const noexcept;
1150b57cec5SDimitry Andric
1160b57cec5SDimitry Andric      // 7.7, basic_string_view modifiers
1170b57cec5SDimitry Andric      constexpr void remove_prefix(size_type n);
1180b57cec5SDimitry Andric      constexpr void remove_suffix(size_type n);
1190b57cec5SDimitry Andric      constexpr void swap(basic_string_view& s) noexcept;
1200b57cec5SDimitry Andric
121fe6060f1SDimitry Andric      size_type copy(charT* s, size_type n, size_type pos = 0) const;  // constexpr in C++20
1220b57cec5SDimitry Andric
1230b57cec5SDimitry Andric      constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
1240b57cec5SDimitry Andric      constexpr int compare(basic_string_view s) const noexcept;
1250b57cec5SDimitry Andric      constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
1260b57cec5SDimitry Andric      constexpr int compare(size_type pos1, size_type n1,
1270b57cec5SDimitry Andric                            basic_string_view s, size_type pos2, size_type n2) const;
1280b57cec5SDimitry Andric      constexpr int compare(const charT* s) const;
1290b57cec5SDimitry Andric      constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
1300b57cec5SDimitry Andric      constexpr int compare(size_type pos1, size_type n1,
1310b57cec5SDimitry Andric                            const charT* s, size_type n2) const;
1320b57cec5SDimitry Andric      constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
1330b57cec5SDimitry Andric      constexpr size_type find(charT c, size_type pos = 0) const noexcept;
134fe6060f1SDimitry Andric      constexpr size_type find(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
135fe6060f1SDimitry Andric      constexpr size_type find(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
1360b57cec5SDimitry Andric      constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
1370b57cec5SDimitry Andric      constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
138fe6060f1SDimitry Andric      constexpr size_type rfind(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
139fe6060f1SDimitry Andric      constexpr size_type rfind(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
1400b57cec5SDimitry Andric      constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
1410b57cec5SDimitry Andric      constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
142fe6060f1SDimitry Andric      constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
143fe6060f1SDimitry Andric      constexpr size_type find_first_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
1440b57cec5SDimitry Andric      constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
1450b57cec5SDimitry Andric      constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
146fe6060f1SDimitry Andric      constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
147fe6060f1SDimitry Andric      constexpr size_type find_last_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
1480b57cec5SDimitry Andric      constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
1490b57cec5SDimitry Andric      constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
150fe6060f1SDimitry Andric      constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
151fe6060f1SDimitry Andric      constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
1520b57cec5SDimitry Andric      constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
1530b57cec5SDimitry Andric      constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
154fe6060f1SDimitry Andric      constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
155fe6060f1SDimitry Andric      constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
1560b57cec5SDimitry Andric
157e8d8bef9SDimitry Andric      constexpr bool starts_with(basic_string_view s) const noexcept; // C++20
158e8d8bef9SDimitry Andric      constexpr bool starts_with(charT c) const noexcept;             // C++20
159e8d8bef9SDimitry Andric      constexpr bool starts_with(const charT* s) const;               // C++20
160e8d8bef9SDimitry Andric      constexpr bool ends_with(basic_string_view s) const noexcept;   // C++20
161e8d8bef9SDimitry Andric      constexpr bool ends_with(charT c) const noexcept;               // C++20
162e8d8bef9SDimitry Andric      constexpr bool ends_with(const charT* s) const;                 // C++20
163e8d8bef9SDimitry Andric
164e8d8bef9SDimitry Andric      constexpr bool contains(basic_string_view s) const noexcept; // C++2b
165e8d8bef9SDimitry Andric      constexpr bool contains(charT c) const noexcept;             // C++2b
166e8d8bef9SDimitry Andric      constexpr bool contains(const charT* s) const;               // C++2b
1670b57cec5SDimitry Andric
1680b57cec5SDimitry Andric     private:
1690b57cec5SDimitry Andric      const_pointer data_;  // exposition only
1700b57cec5SDimitry Andric      size_type     size_;  // exposition only
1710b57cec5SDimitry Andric    };
1720b57cec5SDimitry Andric
173349cc55cSDimitry Andric  // basic_string_view deduction guides
174349cc55cSDimitry Andric  template<class It, class End>
175349cc55cSDimitry Andric    basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>; // C++20
176*4824e7fdSDimitry Andric  template<class Range>
177*4824e7fdSDimitry Andric    basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23
178349cc55cSDimitry Andric
1790b57cec5SDimitry Andric  // 7.11, Hash support
1800b57cec5SDimitry Andric  template <class T> struct hash;
1810b57cec5SDimitry Andric  template <> struct hash<string_view>;
182fe6060f1SDimitry Andric  template <> struct hash<u8string_view>; // C++20
1830b57cec5SDimitry Andric  template <> struct hash<u16string_view>;
1840b57cec5SDimitry Andric  template <> struct hash<u32string_view>;
1850b57cec5SDimitry Andric  template <> struct hash<wstring_view>;
1860b57cec5SDimitry Andric
1870b57cec5SDimitry Andric  constexpr basic_string_view<char>     operator "" sv( const char *str,     size_t len ) noexcept;
1880b57cec5SDimitry Andric  constexpr basic_string_view<wchar_t>  operator "" sv( const wchar_t *str,  size_t len ) noexcept;
189fe6060f1SDimitry Andric  constexpr basic_string_view<char8_t>  operator "" sv( const char8_t *str,  size_t len ) noexcept; // C++20
1900b57cec5SDimitry Andric  constexpr basic_string_view<char16_t> operator "" sv( const char16_t *str, size_t len ) noexcept;
1910b57cec5SDimitry Andric  constexpr basic_string_view<char32_t> operator "" sv( const char32_t *str, size_t len ) noexcept;
1920b57cec5SDimitry Andric
1930b57cec5SDimitry Andric}  // namespace std
1940b57cec5SDimitry Andric
1950b57cec5SDimitry Andric
1960b57cec5SDimitry Andric*/
1970b57cec5SDimitry Andric
1980b57cec5SDimitry Andric#include <__config>
199fe6060f1SDimitry Andric#include <__debug>
200*4824e7fdSDimitry Andric#include <__ranges/concepts.h>
201*4824e7fdSDimitry Andric#include <__ranges/data.h>
202fe6060f1SDimitry Andric#include <__ranges/enable_borrowed_range.h>
203fe6060f1SDimitry Andric#include <__ranges/enable_view.h>
204*4824e7fdSDimitry Andric#include <__ranges/size.h>
2050b57cec5SDimitry Andric#include <__string>
2060b57cec5SDimitry Andric#include <algorithm>
207fe6060f1SDimitry Andric#include <compare>
208fe6060f1SDimitry Andric#include <iosfwd>
2090b57cec5SDimitry Andric#include <iterator>
2100b57cec5SDimitry Andric#include <limits>
2110b57cec5SDimitry Andric#include <stdexcept>
212*4824e7fdSDimitry Andric#include <type_traits>
2130b57cec5SDimitry Andric#include <version>
2140b57cec5SDimitry Andric
2150b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
2160b57cec5SDimitry Andric#pragma GCC system_header
2170b57cec5SDimitry Andric#endif
2180b57cec5SDimitry Andric
2190b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
2200b57cec5SDimitry Andric#include <__undef_macros>
2210b57cec5SDimitry Andric
2220b57cec5SDimitry Andric
2230b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
2240b57cec5SDimitry Andric
2250b57cec5SDimitry Andrictemplate<class _CharT, class _Traits = char_traits<_CharT> >
226e8d8bef9SDimitry Andric    class _LIBCPP_TEMPLATE_VIS basic_string_view;
227e8d8bef9SDimitry Andric
228e8d8bef9SDimitry Andrictypedef basic_string_view<char>     string_view;
229fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
230e8d8bef9SDimitry Andrictypedef basic_string_view<char8_t>  u8string_view;
231e8d8bef9SDimitry Andric#endif
232e8d8bef9SDimitry Andrictypedef basic_string_view<char16_t> u16string_view;
233e8d8bef9SDimitry Andrictypedef basic_string_view<char32_t> u32string_view;
234349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
235e8d8bef9SDimitry Andrictypedef basic_string_view<wchar_t>  wstring_view;
236349cc55cSDimitry Andric#endif
237e8d8bef9SDimitry Andric
238e8d8bef9SDimitry Andrictemplate<class _CharT, class _Traits>
239e8d8bef9SDimitry Andricclass
240e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(string_view)
241fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
242e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(u8string_view)
243e8d8bef9SDimitry Andric#endif
244e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(u16string_view)
245e8d8bef9SDimitry Andric    _LIBCPP_PREFERRED_NAME(u32string_view)
246349cc55cSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstring_view))
247e8d8bef9SDimitry Andric    basic_string_view {
2480b57cec5SDimitry Andricpublic:
2490b57cec5SDimitry Andric    // types
2500b57cec5SDimitry Andric    typedef _Traits                                    traits_type;
2510b57cec5SDimitry Andric    typedef _CharT                                     value_type;
2520b57cec5SDimitry Andric    typedef _CharT*                                    pointer;
2530b57cec5SDimitry Andric    typedef const _CharT*                              const_pointer;
2540b57cec5SDimitry Andric    typedef _CharT&                                    reference;
2550b57cec5SDimitry Andric    typedef const _CharT&                              const_reference;
2560b57cec5SDimitry Andric    typedef const_pointer                              const_iterator; // See [string.view.iterators]
2570b57cec5SDimitry Andric    typedef const_iterator                             iterator;
2580b57cec5SDimitry Andric    typedef _VSTD::reverse_iterator<const_iterator>    const_reverse_iterator;
2590b57cec5SDimitry Andric    typedef const_reverse_iterator                     reverse_iterator;
2600b57cec5SDimitry Andric    typedef size_t                                     size_type;
2610b57cec5SDimitry Andric    typedef ptrdiff_t                                  difference_type;
2620b57cec5SDimitry Andric    static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
2630b57cec5SDimitry Andric
2640b57cec5SDimitry Andric    static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array");
2650b57cec5SDimitry Andric    static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout");
2660b57cec5SDimitry Andric    static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial");
2670b57cec5SDimitry Andric    static_assert((is_same<_CharT, typename traits_type::char_type>::value),
2680b57cec5SDimitry Andric                  "traits_type::char_type must be the same type as CharT");
2690b57cec5SDimitry Andric
2700b57cec5SDimitry Andric    // [string.view.cons], construct/copy
2710b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
2720b57cec5SDimitry Andric    basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {}
2730b57cec5SDimitry Andric
274349cc55cSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2750b57cec5SDimitry Andric    basic_string_view(const basic_string_view&) _NOEXCEPT = default;
2760b57cec5SDimitry Andric
277349cc55cSDimitry Andric    _LIBCPP_INLINE_VISIBILITY
2780b57cec5SDimitry Andric    basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
2790b57cec5SDimitry Andric
2800b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
2810b57cec5SDimitry Andric    basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
2820b57cec5SDimitry Andric        : __data(__s), __size(__len)
2830b57cec5SDimitry Andric    {
2840b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
2850b57cec5SDimitry Andric    _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
2860b57cec5SDimitry Andric#endif
2870b57cec5SDimitry Andric    }
2880b57cec5SDimitry Andric
289349cc55cSDimitry Andric#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
290349cc55cSDimitry Andric    template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
291*4824e7fdSDimitry Andric      requires (is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>)
292349cc55cSDimitry Andric    constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end)
293349cc55cSDimitry Andric       : __data(_VSTD::to_address(__begin)), __size(__end - __begin)
294349cc55cSDimitry Andric    {
295349cc55cSDimitry Andric      _LIBCPP_ASSERT((__end - __begin) >= 0, "std::string_view::string_view(iterator, sentinel) received invalid range");
296349cc55cSDimitry Andric    }
297349cc55cSDimitry Andric#endif
298349cc55cSDimitry Andric
299*4824e7fdSDimitry Andric#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_RANGES)
300*4824e7fdSDimitry Andric    template <class _Range>
301*4824e7fdSDimitry Andric      requires (
302*4824e7fdSDimitry Andric        !is_same_v<remove_cvref_t<_Range>, basic_string_view> &&
303*4824e7fdSDimitry Andric        ranges::contiguous_range<_Range> &&
304*4824e7fdSDimitry Andric        ranges::sized_range<_Range> &&
305*4824e7fdSDimitry Andric        is_same_v<ranges::range_value_t<_Range>, _CharT> &&
306*4824e7fdSDimitry Andric        !is_convertible_v<_Range, const _CharT*> &&
307*4824e7fdSDimitry Andric        (!requires(remove_cvref_t<_Range>& d) {
308*4824e7fdSDimitry Andric          d.operator _VSTD::basic_string_view<_CharT, _Traits>();
309*4824e7fdSDimitry Andric        }) &&
310*4824e7fdSDimitry Andric        (!requires {
311*4824e7fdSDimitry Andric         typename remove_reference_t<_Range>::traits_type;
312*4824e7fdSDimitry Andric        } || is_same_v<typename remove_reference_t<_Range>::traits_type, _Traits>)
313*4824e7fdSDimitry Andric      )
314*4824e7fdSDimitry Andric    constexpr _LIBCPP_HIDE_FROM_ABI
315*4824e7fdSDimitry Andric    basic_string_view(_Range&& __r) : __data(ranges::data(__r)), __size(ranges::size(__r)) {}
316*4824e7fdSDimitry Andric#endif
317*4824e7fdSDimitry Andric
3180b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3190b57cec5SDimitry Andric    basic_string_view(const _CharT* __s)
320e8d8bef9SDimitry Andric        : __data(__s), __size(_VSTD::__char_traits_length_checked<_Traits>(__s)) {}
3210b57cec5SDimitry Andric
322fe6060f1SDimitry Andric#if _LIBCPP_STD_VER > 20
323fe6060f1SDimitry Andric    basic_string_view(nullptr_t) = delete;
324fe6060f1SDimitry Andric#endif
325fe6060f1SDimitry Andric
3260b57cec5SDimitry Andric    // [string.view.iterators], iterators
3270b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3280b57cec5SDimitry Andric    const_iterator begin()  const _NOEXCEPT { return cbegin(); }
3290b57cec5SDimitry Andric
3300b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3310b57cec5SDimitry Andric    const_iterator end()    const _NOEXCEPT { return cend(); }
3320b57cec5SDimitry Andric
3330b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3340b57cec5SDimitry Andric    const_iterator cbegin() const _NOEXCEPT { return __data; }
3350b57cec5SDimitry Andric
3360b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3370b57cec5SDimitry Andric    const_iterator cend()   const _NOEXCEPT { return __data + __size; }
3380b57cec5SDimitry Andric
3390b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
3400b57cec5SDimitry Andric    const_reverse_iterator rbegin()   const _NOEXCEPT { return const_reverse_iterator(cend()); }
3410b57cec5SDimitry Andric
3420b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
3430b57cec5SDimitry Andric    const_reverse_iterator rend()     const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
3440b57cec5SDimitry Andric
3450b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
3460b57cec5SDimitry Andric    const_reverse_iterator crbegin()  const _NOEXCEPT { return const_reverse_iterator(cend()); }
3470b57cec5SDimitry Andric
3480b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
3490b57cec5SDimitry Andric    const_reverse_iterator crend()    const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
3500b57cec5SDimitry Andric
3510b57cec5SDimitry Andric    // [string.view.capacity], capacity
3520b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3530b57cec5SDimitry Andric    size_type size()     const _NOEXCEPT { return __size; }
3540b57cec5SDimitry Andric
3550b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3560b57cec5SDimitry Andric    size_type length()   const _NOEXCEPT { return __size; }
3570b57cec5SDimitry Andric
3580b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3590b57cec5SDimitry Andric    size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max(); }
3600b57cec5SDimitry Andric
3610b57cec5SDimitry Andric    _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
3620b57cec5SDimitry Andric    bool empty()         const _NOEXCEPT { return __size == 0; }
3630b57cec5SDimitry Andric
3640b57cec5SDimitry Andric    // [string.view.access], element access
3650b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
366e8d8bef9SDimitry Andric    const_reference operator[](size_type __pos) const _NOEXCEPT {
367e8d8bef9SDimitry Andric      return _LIBCPP_ASSERT(__pos < size(), "string_view[] index out of bounds"), __data[__pos];
368e8d8bef9SDimitry Andric    }
3690b57cec5SDimitry Andric
3700b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3710b57cec5SDimitry Andric    const_reference at(size_type __pos) const
3720b57cec5SDimitry Andric    {
3730b57cec5SDimitry Andric        return __pos >= size()
3740b57cec5SDimitry Andric            ? (__throw_out_of_range("string_view::at"), __data[0])
3750b57cec5SDimitry Andric            : __data[__pos];
3760b57cec5SDimitry Andric    }
3770b57cec5SDimitry Andric
3780b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3790b57cec5SDimitry Andric    const_reference front() const _NOEXCEPT
3800b57cec5SDimitry Andric    {
3810b57cec5SDimitry Andric        return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0];
3820b57cec5SDimitry Andric    }
3830b57cec5SDimitry Andric
3840b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3850b57cec5SDimitry Andric    const_reference back() const _NOEXCEPT
3860b57cec5SDimitry Andric    {
3870b57cec5SDimitry Andric        return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1];
3880b57cec5SDimitry Andric    }
3890b57cec5SDimitry Andric
3900b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
3910b57cec5SDimitry Andric    const_pointer data() const _NOEXCEPT { return __data; }
3920b57cec5SDimitry Andric
3930b57cec5SDimitry Andric    // [string.view.modifiers], modifiers:
3940b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
3950b57cec5SDimitry Andric    void remove_prefix(size_type __n) _NOEXCEPT
3960b57cec5SDimitry Andric    {
3970b57cec5SDimitry Andric        _LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()");
3980b57cec5SDimitry Andric        __data += __n;
3990b57cec5SDimitry Andric        __size -= __n;
4000b57cec5SDimitry Andric    }
4010b57cec5SDimitry Andric
4020b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
4030b57cec5SDimitry Andric    void remove_suffix(size_type __n) _NOEXCEPT
4040b57cec5SDimitry Andric    {
4050b57cec5SDimitry Andric        _LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()");
4060b57cec5SDimitry Andric        __size -= __n;
4070b57cec5SDimitry Andric    }
4080b57cec5SDimitry Andric
4090b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
4100b57cec5SDimitry Andric    void swap(basic_string_view& __other) _NOEXCEPT
4110b57cec5SDimitry Andric    {
4120b57cec5SDimitry Andric        const value_type *__p = __data;
4130b57cec5SDimitry Andric        __data = __other.__data;
4140b57cec5SDimitry Andric        __other.__data = __p;
4150b57cec5SDimitry Andric
4160b57cec5SDimitry Andric        size_type __sz = __size;
4170b57cec5SDimitry Andric        __size = __other.__size;
4180b57cec5SDimitry Andric        __other.__size = __sz;
4190b57cec5SDimitry Andric    }
4200b57cec5SDimitry Andric
421fe6060f1SDimitry Andric    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
4220b57cec5SDimitry Andric    size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const
4230b57cec5SDimitry Andric    {
4240b57cec5SDimitry Andric        if (__pos > size())
4250b57cec5SDimitry Andric            __throw_out_of_range("string_view::copy");
4260b57cec5SDimitry Andric        size_type __rlen = _VSTD::min(__n, size() - __pos);
4270b57cec5SDimitry Andric        _Traits::copy(__s, data() + __pos, __rlen);
4280b57cec5SDimitry Andric        return __rlen;
4290b57cec5SDimitry Andric    }
4300b57cec5SDimitry Andric
4310b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
4320b57cec5SDimitry Andric    basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
4330b57cec5SDimitry Andric    {
4340b57cec5SDimitry Andric        return __pos > size()
4350b57cec5SDimitry Andric            ? (__throw_out_of_range("string_view::substr"), basic_string_view())
4360b57cec5SDimitry Andric            : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos));
4370b57cec5SDimitry Andric    }
4380b57cec5SDimitry Andric
4390b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT
4400b57cec5SDimitry Andric    {
4410b57cec5SDimitry Andric        size_type __rlen = _VSTD::min( size(), __sv.size());
4420b57cec5SDimitry Andric        int __retval = _Traits::compare(data(), __sv.data(), __rlen);
4430b57cec5SDimitry Andric        if ( __retval == 0 ) // first __rlen chars matched
4440b57cec5SDimitry Andric            __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 );
4450b57cec5SDimitry Andric        return __retval;
4460b57cec5SDimitry Andric    }
4470b57cec5SDimitry Andric
4480b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
4490b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const
4500b57cec5SDimitry Andric    {
4510b57cec5SDimitry Andric        return substr(__pos1, __n1).compare(__sv);
4520b57cec5SDimitry Andric    }
4530b57cec5SDimitry Andric
4540b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
4550b57cec5SDimitry Andric    int compare(                       size_type __pos1, size_type __n1,
4560b57cec5SDimitry Andric                basic_string_view __sv, size_type __pos2, size_type __n2) const
4570b57cec5SDimitry Andric    {
4580b57cec5SDimitry Andric        return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
4590b57cec5SDimitry Andric    }
4600b57cec5SDimitry Andric
4610b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
4620b57cec5SDimitry Andric    int compare(const _CharT* __s) const _NOEXCEPT
4630b57cec5SDimitry Andric    {
4640b57cec5SDimitry Andric        return compare(basic_string_view(__s));
4650b57cec5SDimitry Andric    }
4660b57cec5SDimitry Andric
4670b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
4680b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const _CharT* __s) const
4690b57cec5SDimitry Andric    {
4700b57cec5SDimitry Andric        return substr(__pos1, __n1).compare(basic_string_view(__s));
4710b57cec5SDimitry Andric    }
4720b57cec5SDimitry Andric
4730b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
4740b57cec5SDimitry Andric    int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
4750b57cec5SDimitry Andric    {
4760b57cec5SDimitry Andric        return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
4770b57cec5SDimitry Andric    }
4780b57cec5SDimitry Andric
4790b57cec5SDimitry Andric    // find
4800b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
4810b57cec5SDimitry Andric    size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
4820b57cec5SDimitry Andric    {
4830b57cec5SDimitry Andric        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
4840b57cec5SDimitry Andric        return __str_find<value_type, size_type, traits_type, npos>
4850b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
4860b57cec5SDimitry Andric    }
4870b57cec5SDimitry Andric
4880b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
4890b57cec5SDimitry Andric    size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT
4900b57cec5SDimitry Andric    {
4910b57cec5SDimitry Andric        return __str_find<value_type, size_type, traits_type, npos>
4920b57cec5SDimitry Andric            (data(), size(), __c, __pos);
4930b57cec5SDimitry Andric    }
4940b57cec5SDimitry Andric
4950b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
496fe6060f1SDimitry Andric    size_type find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
4970b57cec5SDimitry Andric    {
4980b57cec5SDimitry Andric        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
4990b57cec5SDimitry Andric        return __str_find<value_type, size_type, traits_type, npos>
5000b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
5010b57cec5SDimitry Andric    }
5020b57cec5SDimitry Andric
5030b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
504fe6060f1SDimitry Andric    size_type find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT
5050b57cec5SDimitry Andric    {
5060b57cec5SDimitry Andric        _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr");
5070b57cec5SDimitry Andric        return __str_find<value_type, size_type, traits_type, npos>
5080b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
5090b57cec5SDimitry Andric    }
5100b57cec5SDimitry Andric
5110b57cec5SDimitry Andric    // rfind
5120b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5130b57cec5SDimitry Andric    size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT
5140b57cec5SDimitry Andric    {
5150b57cec5SDimitry Andric        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
5160b57cec5SDimitry Andric        return __str_rfind<value_type, size_type, traits_type, npos>
5170b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
5180b57cec5SDimitry Andric    }
5190b57cec5SDimitry Andric
5200b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5210b57cec5SDimitry Andric    size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT
5220b57cec5SDimitry Andric    {
5230b57cec5SDimitry Andric        return __str_rfind<value_type, size_type, traits_type, npos>
5240b57cec5SDimitry Andric            (data(), size(), __c, __pos);
5250b57cec5SDimitry Andric    }
5260b57cec5SDimitry Andric
5270b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
528fe6060f1SDimitry Andric    size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
5290b57cec5SDimitry Andric    {
5300b57cec5SDimitry Andric        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
5310b57cec5SDimitry Andric        return __str_rfind<value_type, size_type, traits_type, npos>
5320b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
5330b57cec5SDimitry Andric    }
5340b57cec5SDimitry Andric
5350b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
536fe6060f1SDimitry Andric    size_type rfind(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
5370b57cec5SDimitry Andric    {
5380b57cec5SDimitry Andric        _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr");
5390b57cec5SDimitry Andric        return __str_rfind<value_type, size_type, traits_type, npos>
5400b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
5410b57cec5SDimitry Andric    }
5420b57cec5SDimitry Andric
5430b57cec5SDimitry Andric    // find_first_of
5440b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5450b57cec5SDimitry Andric    size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
5460b57cec5SDimitry Andric    {
5470b57cec5SDimitry Andric        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
5480b57cec5SDimitry Andric        return __str_find_first_of<value_type, size_type, traits_type, npos>
5490b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
5500b57cec5SDimitry Andric    }
5510b57cec5SDimitry Andric
5520b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5530b57cec5SDimitry Andric    size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT
5540b57cec5SDimitry Andric    { return find(__c, __pos); }
5550b57cec5SDimitry Andric
5560b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
557fe6060f1SDimitry Andric    size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
5580b57cec5SDimitry Andric    {
5590b57cec5SDimitry Andric        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
5600b57cec5SDimitry Andric        return __str_find_first_of<value_type, size_type, traits_type, npos>
5610b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
5620b57cec5SDimitry Andric    }
5630b57cec5SDimitry Andric
5640b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
565fe6060f1SDimitry Andric    size_type find_first_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT
5660b57cec5SDimitry Andric    {
5670b57cec5SDimitry Andric        _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr");
5680b57cec5SDimitry Andric        return __str_find_first_of<value_type, size_type, traits_type, npos>
5690b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
5700b57cec5SDimitry Andric    }
5710b57cec5SDimitry Andric
5720b57cec5SDimitry Andric    // find_last_of
5730b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5740b57cec5SDimitry Andric    size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
5750b57cec5SDimitry Andric    {
5760b57cec5SDimitry Andric        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
5770b57cec5SDimitry Andric        return __str_find_last_of<value_type, size_type, traits_type, npos>
5780b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
5790b57cec5SDimitry Andric    }
5800b57cec5SDimitry Andric
5810b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
5820b57cec5SDimitry Andric    size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT
5830b57cec5SDimitry Andric    { return rfind(__c, __pos); }
5840b57cec5SDimitry Andric
5850b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
586fe6060f1SDimitry Andric    size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
5870b57cec5SDimitry Andric    {
5880b57cec5SDimitry Andric        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
5890b57cec5SDimitry Andric        return __str_find_last_of<value_type, size_type, traits_type, npos>
5900b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
5910b57cec5SDimitry Andric    }
5920b57cec5SDimitry Andric
5930b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
594fe6060f1SDimitry Andric    size_type find_last_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
5950b57cec5SDimitry Andric    {
5960b57cec5SDimitry Andric        _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr");
5970b57cec5SDimitry Andric        return __str_find_last_of<value_type, size_type, traits_type, npos>
5980b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
5990b57cec5SDimitry Andric    }
6000b57cec5SDimitry Andric
6010b57cec5SDimitry Andric    // find_first_not_of
6020b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
6030b57cec5SDimitry Andric    size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT
6040b57cec5SDimitry Andric    {
6050b57cec5SDimitry Andric        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
6060b57cec5SDimitry Andric        return __str_find_first_not_of<value_type, size_type, traits_type, npos>
6070b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
6080b57cec5SDimitry Andric    }
6090b57cec5SDimitry Andric
6100b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
6110b57cec5SDimitry Andric    size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT
6120b57cec5SDimitry Andric    {
6130b57cec5SDimitry Andric        return __str_find_first_not_of<value_type, size_type, traits_type, npos>
6140b57cec5SDimitry Andric            (data(), size(), __c, __pos);
6150b57cec5SDimitry Andric    }
6160b57cec5SDimitry Andric
6170b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
618fe6060f1SDimitry Andric    size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
6190b57cec5SDimitry Andric    {
6200b57cec5SDimitry Andric        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
6210b57cec5SDimitry Andric        return __str_find_first_not_of<value_type, size_type, traits_type, npos>
6220b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
6230b57cec5SDimitry Andric    }
6240b57cec5SDimitry Andric
6250b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
626fe6060f1SDimitry Andric    size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT
6270b57cec5SDimitry Andric    {
6280b57cec5SDimitry Andric        _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
6290b57cec5SDimitry Andric        return __str_find_first_not_of<value_type, size_type, traits_type, npos>
6300b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
6310b57cec5SDimitry Andric    }
6320b57cec5SDimitry Andric
6330b57cec5SDimitry Andric    // find_last_not_of
6340b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
6350b57cec5SDimitry Andric    size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
6360b57cec5SDimitry Andric    {
6370b57cec5SDimitry Andric        _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
6380b57cec5SDimitry Andric        return __str_find_last_not_of<value_type, size_type, traits_type, npos>
6390b57cec5SDimitry Andric            (data(), size(), __s.data(), __pos, __s.size());
6400b57cec5SDimitry Andric    }
6410b57cec5SDimitry Andric
6420b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
6430b57cec5SDimitry Andric    size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT
6440b57cec5SDimitry Andric    {
6450b57cec5SDimitry Andric        return __str_find_last_not_of<value_type, size_type, traits_type, npos>
6460b57cec5SDimitry Andric            (data(), size(), __c, __pos);
6470b57cec5SDimitry Andric    }
6480b57cec5SDimitry Andric
6490b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
650fe6060f1SDimitry Andric    size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
6510b57cec5SDimitry Andric    {
6520b57cec5SDimitry Andric        _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
6530b57cec5SDimitry Andric        return __str_find_last_not_of<value_type, size_type, traits_type, npos>
6540b57cec5SDimitry Andric            (data(), size(), __s, __pos, __n);
6550b57cec5SDimitry Andric    }
6560b57cec5SDimitry Andric
6570b57cec5SDimitry Andric    _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
658fe6060f1SDimitry Andric    size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
6590b57cec5SDimitry Andric    {
6600b57cec5SDimitry Andric        _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
6610b57cec5SDimitry Andric        return __str_find_last_not_of<value_type, size_type, traits_type, npos>
6620b57cec5SDimitry Andric            (data(), size(), __s, __pos, traits_type::length(__s));
6630b57cec5SDimitry Andric    }
6640b57cec5SDimitry Andric
6650b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 17
666349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
667349cc55cSDimitry Andric    bool starts_with(basic_string_view __s) const noexcept
6680b57cec5SDimitry Andric    { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; }
6690b57cec5SDimitry Andric
670349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
671349cc55cSDimitry Andric    bool starts_with(value_type __c) const noexcept
6720b57cec5SDimitry Andric    { return !empty() && _Traits::eq(front(), __c); }
6730b57cec5SDimitry Andric
674349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
675349cc55cSDimitry Andric    bool starts_with(const value_type* __s) const noexcept
6760b57cec5SDimitry Andric    { return starts_with(basic_string_view(__s)); }
6770b57cec5SDimitry Andric
678349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
679349cc55cSDimitry Andric    bool ends_with(basic_string_view __s) const noexcept
6800b57cec5SDimitry Andric    { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; }
6810b57cec5SDimitry Andric
682349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
683349cc55cSDimitry Andric    bool ends_with(value_type __c) const noexcept
6840b57cec5SDimitry Andric    { return !empty() && _Traits::eq(back(), __c); }
6850b57cec5SDimitry Andric
686349cc55cSDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
687349cc55cSDimitry Andric    bool ends_with(const value_type* __s) const noexcept
6880b57cec5SDimitry Andric    { return ends_with(basic_string_view(__s)); }
6890b57cec5SDimitry Andric#endif
6900b57cec5SDimitry Andric
691e8d8bef9SDimitry Andric#if _LIBCPP_STD_VER > 20
692e8d8bef9SDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
693e8d8bef9SDimitry Andric    bool contains(basic_string_view __sv) const noexcept
694e8d8bef9SDimitry Andric    { return find(__sv) != npos; }
695e8d8bef9SDimitry Andric
696e8d8bef9SDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
697e8d8bef9SDimitry Andric    bool contains(value_type __c) const noexcept
698e8d8bef9SDimitry Andric    { return find(__c) != npos; }
699e8d8bef9SDimitry Andric
700e8d8bef9SDimitry Andric    constexpr _LIBCPP_INLINE_VISIBILITY
701e8d8bef9SDimitry Andric    bool contains(const value_type* __s) const
702e8d8bef9SDimitry Andric    { return find(__s) != npos; }
703e8d8bef9SDimitry Andric#endif
704e8d8bef9SDimitry Andric
7050b57cec5SDimitry Andricprivate:
7060b57cec5SDimitry Andric    const   value_type* __data;
7070b57cec5SDimitry Andric    size_type           __size;
7080b57cec5SDimitry Andric};
7090b57cec5SDimitry Andric
710fe6060f1SDimitry Andric#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
711fe6060f1SDimitry Andrictemplate <class _CharT, class _Traits>
712fe6060f1SDimitry Andricinline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true;
713fe6060f1SDimitry Andric
714fe6060f1SDimitry Andrictemplate <class _CharT, class _Traits>
715fe6060f1SDimitry Andricinline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true;
716fe6060f1SDimitry Andric#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
7170b57cec5SDimitry Andric
718349cc55cSDimitry Andric// [string.view.deduct]
719349cc55cSDimitry Andric
720349cc55cSDimitry Andric#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_RANGES)
721349cc55cSDimitry Andrictemplate <contiguous_iterator _It, sized_sentinel_for<_It> _End>
722349cc55cSDimitry Andric  basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
723349cc55cSDimitry Andric#endif
724349cc55cSDimitry Andric
725*4824e7fdSDimitry Andric
726*4824e7fdSDimitry Andric#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_RANGES)
727*4824e7fdSDimitry Andrictemplate <ranges::contiguous_range _Range>
728*4824e7fdSDimitry Andric  basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>;
729*4824e7fdSDimitry Andric#endif
730*4824e7fdSDimitry Andric
7310b57cec5SDimitry Andric// [string.view.comparison]
7320b57cec5SDimitry Andric// operator ==
7330b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
7340b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
7350b57cec5SDimitry Andricbool operator==(basic_string_view<_CharT, _Traits> __lhs,
7360b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
7370b57cec5SDimitry Andric{
7380b57cec5SDimitry Andric    if ( __lhs.size() != __rhs.size()) return false;
7390b57cec5SDimitry Andric    return __lhs.compare(__rhs) == 0;
7400b57cec5SDimitry Andric}
7410b57cec5SDimitry Andric
742*4824e7fdSDimitry Andric// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details.
743*4824e7fdSDimitry Andric// This applies to the other sufficient overloads below for the other comparison operators.
744*4824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
7450b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
7460b57cec5SDimitry Andricbool operator==(basic_string_view<_CharT, _Traits> __lhs,
7470b57cec5SDimitry Andric                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
7480b57cec5SDimitry Andric{
7490b57cec5SDimitry Andric    if ( __lhs.size() != __rhs.size()) return false;
7500b57cec5SDimitry Andric    return __lhs.compare(__rhs) == 0;
7510b57cec5SDimitry Andric}
7520b57cec5SDimitry Andric
753*4824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
7540b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
7550b57cec5SDimitry Andricbool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
7560b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
7570b57cec5SDimitry Andric{
7580b57cec5SDimitry Andric    if ( __lhs.size() != __rhs.size()) return false;
7590b57cec5SDimitry Andric    return __lhs.compare(__rhs) == 0;
7600b57cec5SDimitry Andric}
7610b57cec5SDimitry Andric
7620b57cec5SDimitry Andric
7630b57cec5SDimitry Andric// operator !=
7640b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
7650b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
7660b57cec5SDimitry Andricbool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
7670b57cec5SDimitry Andric{
7680b57cec5SDimitry Andric    if ( __lhs.size() != __rhs.size())
7690b57cec5SDimitry Andric        return true;
7700b57cec5SDimitry Andric    return __lhs.compare(__rhs) != 0;
7710b57cec5SDimitry Andric}
7720b57cec5SDimitry Andric
773*4824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
7740b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
7750b57cec5SDimitry Andricbool operator!=(basic_string_view<_CharT, _Traits> __lhs,
7760b57cec5SDimitry Andric                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
7770b57cec5SDimitry Andric{
7780b57cec5SDimitry Andric    if ( __lhs.size() != __rhs.size())
7790b57cec5SDimitry Andric        return true;
7800b57cec5SDimitry Andric    return __lhs.compare(__rhs) != 0;
7810b57cec5SDimitry Andric}
7820b57cec5SDimitry Andric
783*4824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
7840b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
7850b57cec5SDimitry Andricbool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
7860b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
7870b57cec5SDimitry Andric{
7880b57cec5SDimitry Andric    if ( __lhs.size() != __rhs.size())
7890b57cec5SDimitry Andric        return true;
7900b57cec5SDimitry Andric    return __lhs.compare(__rhs) != 0;
7910b57cec5SDimitry Andric}
7920b57cec5SDimitry Andric
7930b57cec5SDimitry Andric
7940b57cec5SDimitry Andric// operator <
7950b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
7960b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
7970b57cec5SDimitry Andricbool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
7980b57cec5SDimitry Andric{
7990b57cec5SDimitry Andric    return __lhs.compare(__rhs) < 0;
8000b57cec5SDimitry Andric}
8010b57cec5SDimitry Andric
802*4824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
8030b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8040b57cec5SDimitry Andricbool operator<(basic_string_view<_CharT, _Traits> __lhs,
8050b57cec5SDimitry Andric                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
8060b57cec5SDimitry Andric{
8070b57cec5SDimitry Andric    return __lhs.compare(__rhs) < 0;
8080b57cec5SDimitry Andric}
8090b57cec5SDimitry Andric
810*4824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
8110b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8120b57cec5SDimitry Andricbool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
8130b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8140b57cec5SDimitry Andric{
8150b57cec5SDimitry Andric    return __lhs.compare(__rhs) < 0;
8160b57cec5SDimitry Andric}
8170b57cec5SDimitry Andric
8180b57cec5SDimitry Andric
8190b57cec5SDimitry Andric// operator >
8200b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
8210b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8220b57cec5SDimitry Andricbool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8230b57cec5SDimitry Andric{
8240b57cec5SDimitry Andric    return __lhs.compare(__rhs) > 0;
8250b57cec5SDimitry Andric}
8260b57cec5SDimitry Andric
827*4824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
8280b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8290b57cec5SDimitry Andricbool operator>(basic_string_view<_CharT, _Traits> __lhs,
8300b57cec5SDimitry Andric                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
8310b57cec5SDimitry Andric{
8320b57cec5SDimitry Andric    return __lhs.compare(__rhs) > 0;
8330b57cec5SDimitry Andric}
8340b57cec5SDimitry Andric
835*4824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
8360b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8370b57cec5SDimitry Andricbool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
8380b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8390b57cec5SDimitry Andric{
8400b57cec5SDimitry Andric    return __lhs.compare(__rhs) > 0;
8410b57cec5SDimitry Andric}
8420b57cec5SDimitry Andric
8430b57cec5SDimitry Andric
8440b57cec5SDimitry Andric// operator <=
8450b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
8460b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8470b57cec5SDimitry Andricbool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8480b57cec5SDimitry Andric{
8490b57cec5SDimitry Andric    return __lhs.compare(__rhs) <= 0;
8500b57cec5SDimitry Andric}
8510b57cec5SDimitry Andric
852*4824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
8530b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8540b57cec5SDimitry Andricbool operator<=(basic_string_view<_CharT, _Traits> __lhs,
8550b57cec5SDimitry Andric                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
8560b57cec5SDimitry Andric{
8570b57cec5SDimitry Andric    return __lhs.compare(__rhs) <= 0;
8580b57cec5SDimitry Andric}
8590b57cec5SDimitry Andric
860*4824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
8610b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8620b57cec5SDimitry Andricbool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
8630b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8640b57cec5SDimitry Andric{
8650b57cec5SDimitry Andric    return __lhs.compare(__rhs) <= 0;
8660b57cec5SDimitry Andric}
8670b57cec5SDimitry Andric
8680b57cec5SDimitry Andric
8690b57cec5SDimitry Andric// operator >=
8700b57cec5SDimitry Andrictemplate<class _CharT, class _Traits>
8710b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8720b57cec5SDimitry Andricbool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8730b57cec5SDimitry Andric{
8740b57cec5SDimitry Andric    return __lhs.compare(__rhs) >= 0;
8750b57cec5SDimitry Andric}
8760b57cec5SDimitry Andric
8770b57cec5SDimitry Andric
878*4824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 1>
8790b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8800b57cec5SDimitry Andricbool operator>=(basic_string_view<_CharT, _Traits> __lhs,
8810b57cec5SDimitry Andric                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
8820b57cec5SDimitry Andric{
8830b57cec5SDimitry Andric    return __lhs.compare(__rhs) >= 0;
8840b57cec5SDimitry Andric}
8850b57cec5SDimitry Andric
886*4824e7fdSDimitry Andrictemplate<class _CharT, class _Traits, int = 2>
8870b57cec5SDimitry Andric_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
8880b57cec5SDimitry Andricbool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
8890b57cec5SDimitry Andric                basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
8900b57cec5SDimitry Andric{
8910b57cec5SDimitry Andric    return __lhs.compare(__rhs) >= 0;
8920b57cec5SDimitry Andric}
8930b57cec5SDimitry Andric
894e40139ffSDimitry Andric
895e40139ffSDimitry Andrictemplate<class _CharT, class _Traits>
896e40139ffSDimitry Andricbasic_ostream<_CharT, _Traits>&
897e40139ffSDimitry Andricoperator<<(basic_ostream<_CharT, _Traits>& __os,
898e40139ffSDimitry Andric           basic_string_view<_CharT, _Traits> __str);
899e40139ffSDimitry Andric
9000b57cec5SDimitry Andric// [string.view.hash]
9010b57cec5SDimitry Andrictemplate<class _CharT>
9020b57cec5SDimitry Andricstruct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, char_traits<_CharT> > >
9030b57cec5SDimitry Andric    : public unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t>
9040b57cec5SDimitry Andric{
9050b57cec5SDimitry Andric    _LIBCPP_INLINE_VISIBILITY
9060b57cec5SDimitry Andric    size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT {
9070b57cec5SDimitry Andric        return __do_string_hash(__val.data(), __val.data() + __val.size());
9080b57cec5SDimitry Andric    }
9090b57cec5SDimitry Andric};
9100b57cec5SDimitry Andric
9110b57cec5SDimitry Andric
9120b57cec5SDimitry Andric#if _LIBCPP_STD_VER > 11
9130b57cec5SDimitry Andricinline namespace literals
9140b57cec5SDimitry Andric{
9150b57cec5SDimitry Andric  inline namespace string_view_literals
9160b57cec5SDimitry Andric  {
9170b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
9180b57cec5SDimitry Andric    basic_string_view<char> operator "" sv(const char *__str, size_t __len) _NOEXCEPT
9190b57cec5SDimitry Andric    {
9200b57cec5SDimitry Andric        return basic_string_view<char> (__str, __len);
9210b57cec5SDimitry Andric    }
9220b57cec5SDimitry Andric
923349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
9240b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
9250b57cec5SDimitry Andric    basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT
9260b57cec5SDimitry Andric    {
9270b57cec5SDimitry Andric        return basic_string_view<wchar_t> (__str, __len);
9280b57cec5SDimitry Andric    }
929349cc55cSDimitry Andric#endif
9300b57cec5SDimitry Andric
931fe6060f1SDimitry Andric#ifndef _LIBCPP_HAS_NO_CHAR8_T
9320b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
9330b57cec5SDimitry Andric    basic_string_view<char8_t> operator "" sv(const char8_t *__str, size_t __len) _NOEXCEPT
9340b57cec5SDimitry Andric    {
9350b57cec5SDimitry Andric        return basic_string_view<char8_t> (__str, __len);
9360b57cec5SDimitry Andric    }
9370b57cec5SDimitry Andric#endif
9380b57cec5SDimitry Andric
9390b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
9400b57cec5SDimitry Andric    basic_string_view<char16_t> operator "" sv(const char16_t *__str, size_t __len) _NOEXCEPT
9410b57cec5SDimitry Andric    {
9420b57cec5SDimitry Andric        return basic_string_view<char16_t> (__str, __len);
9430b57cec5SDimitry Andric    }
9440b57cec5SDimitry Andric
9450b57cec5SDimitry Andric    inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
9460b57cec5SDimitry Andric    basic_string_view<char32_t> operator "" sv(const char32_t *__str, size_t __len) _NOEXCEPT
9470b57cec5SDimitry Andric    {
9480b57cec5SDimitry Andric        return basic_string_view<char32_t> (__str, __len);
9490b57cec5SDimitry Andric    }
9500b57cec5SDimitry Andric  }
9510b57cec5SDimitry Andric}
9520b57cec5SDimitry Andric#endif
9530b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
9540b57cec5SDimitry Andric
9550b57cec5SDimitry Andric_LIBCPP_POP_MACROS
9560b57cec5SDimitry Andric
9570b57cec5SDimitry Andric#endif // _LIBCPP_STRING_VIEW
958