1053d81ceSMarshall Clow// -*- C++ -*- 2eb8650a7SLouis Dionne//===----------------------------------------------------------------------===// 3053d81ceSMarshall Clow// 42946cd70SChandler Carruth// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 52946cd70SChandler Carruth// See https://llvm.org/LICENSE.txt for license information. 62946cd70SChandler Carruth// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7053d81ceSMarshall Clow// 8053d81ceSMarshall Clow//===----------------------------------------------------------------------===// 9053d81ceSMarshall Clow 10053d81ceSMarshall Clow#ifndef _LIBCPP_STRING_VIEW 11053d81ceSMarshall Clow#define _LIBCPP_STRING_VIEW 12053d81ceSMarshall Clow 13053d81ceSMarshall Clow/* 14053d81ceSMarshall Clowstring_view synopsis 15053d81ceSMarshall Clow 16053d81ceSMarshall Clownamespace std { 17053d81ceSMarshall Clow 18053d81ceSMarshall Clow // 7.2, Class template basic_string_view 19053d81ceSMarshall Clow template<class charT, class traits = char_traits<charT>> 20053d81ceSMarshall Clow class basic_string_view; 21053d81ceSMarshall Clow 2201ace074SMark de Wever template<class charT, class traits> 23462f8f06SChristopher Di Bella inline constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true; 24462f8f06SChristopher Di Bella 25462f8f06SChristopher Di Bella template<class charT, class traits> 2601ace074SMark de Wever inline constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true; // C++20 2701ace074SMark de Wever 28053d81ceSMarshall Clow // 7.9, basic_string_view non-member comparison functions 29053d81ceSMarshall Clow template<class charT, class traits> 30053d81ceSMarshall Clow constexpr bool operator==(basic_string_view<charT, traits> x, 31053d81ceSMarshall Clow basic_string_view<charT, traits> y) noexcept; 32053d81ceSMarshall Clow template<class charT, class traits> 33053d81ceSMarshall Clow constexpr bool operator!=(basic_string_view<charT, traits> x, 34053d81ceSMarshall Clow basic_string_view<charT, traits> y) noexcept; 35053d81ceSMarshall Clow template<class charT, class traits> 36053d81ceSMarshall Clow constexpr bool operator< (basic_string_view<charT, traits> x, 37053d81ceSMarshall Clow basic_string_view<charT, traits> y) noexcept; 38053d81ceSMarshall Clow template<class charT, class traits> 39053d81ceSMarshall Clow constexpr bool operator> (basic_string_view<charT, traits> x, 40053d81ceSMarshall Clow basic_string_view<charT, traits> y) noexcept; 41053d81ceSMarshall Clow template<class charT, class traits> 42053d81ceSMarshall Clow constexpr bool operator<=(basic_string_view<charT, traits> x, 43053d81ceSMarshall Clow basic_string_view<charT, traits> y) noexcept; 44053d81ceSMarshall Clow template<class charT, class traits> 45053d81ceSMarshall Clow constexpr bool operator>=(basic_string_view<charT, traits> x, 46053d81ceSMarshall Clow basic_string_view<charT, traits> y) noexcept; 47053d81ceSMarshall Clow // see below, sufficient additional overloads of comparison functions 48053d81ceSMarshall Clow 49053d81ceSMarshall Clow // 7.10, Inserters and extractors 50053d81ceSMarshall Clow template<class charT, class traits> 51053d81ceSMarshall Clow basic_ostream<charT, traits>& 52053d81ceSMarshall Clow operator<<(basic_ostream<charT, traits>& os, 53053d81ceSMarshall Clow basic_string_view<charT, traits> str); 54053d81ceSMarshall Clow 55053d81ceSMarshall Clow // basic_string_view typedef names 56053d81ceSMarshall Clow typedef basic_string_view<char> string_view; 5728f82becSMarek Kurdej typedef basic_string_view<char8_t> u8string_view; // C++20 58053d81ceSMarshall Clow typedef basic_string_view<char16_t> u16string_view; 59053d81ceSMarshall Clow typedef basic_string_view<char32_t> u32string_view; 60053d81ceSMarshall Clow typedef basic_string_view<wchar_t> wstring_view; 61053d81ceSMarshall Clow 62053d81ceSMarshall Clow template<class charT, class traits = char_traits<charT>> 63053d81ceSMarshall Clow class basic_string_view { 64053d81ceSMarshall Clow public: 65053d81ceSMarshall Clow // types 66053d81ceSMarshall Clow typedef traits traits_type; 67053d81ceSMarshall Clow typedef charT value_type; 68053d81ceSMarshall Clow typedef charT* pointer; 69053d81ceSMarshall Clow typedef const charT* const_pointer; 70053d81ceSMarshall Clow typedef charT& reference; 71053d81ceSMarshall Clow typedef const charT& const_reference; 72053d81ceSMarshall Clow typedef implementation-defined const_iterator; 73053d81ceSMarshall Clow typedef const_iterator iterator; 74053d81ceSMarshall Clow typedef reverse_iterator<const_iterator> const_reverse_iterator; 75053d81ceSMarshall Clow typedef const_reverse_iterator reverse_iterator; 76053d81ceSMarshall Clow typedef size_t size_type; 77053d81ceSMarshall Clow typedef ptrdiff_t difference_type; 78053d81ceSMarshall Clow static constexpr size_type npos = size_type(-1); 79053d81ceSMarshall Clow 80053d81ceSMarshall Clow // 7.3, basic_string_view constructors and assignment operators 81053d81ceSMarshall Clow constexpr basic_string_view() noexcept; 82053d81ceSMarshall Clow constexpr basic_string_view(const basic_string_view&) noexcept = default; 83053d81ceSMarshall Clow basic_string_view& operator=(const basic_string_view&) noexcept = default; 84053d81ceSMarshall Clow template<class Allocator> 85053d81ceSMarshall Clow constexpr basic_string_view(const charT* str); 86775caa58SMarek Kurdej basic_string_view(nullptr_t) = delete; // C++2b 87053d81ceSMarshall Clow constexpr basic_string_view(const charT* str, size_type len); 884be7f489SJoe Loser template <class It, class End> 894be7f489SJoe Loser constexpr basic_string_view(It begin, End end); // C++20 90c16b13ebSJoe Loser template <class Range> 91c16b13ebSJoe Loser constexpr basic_string_view(Range&& r); // C++23 92053d81ceSMarshall Clow 93053d81ceSMarshall Clow // 7.4, basic_string_view iterator support 94053d81ceSMarshall Clow constexpr const_iterator begin() const noexcept; 95053d81ceSMarshall Clow constexpr const_iterator end() const noexcept; 96053d81ceSMarshall Clow constexpr const_iterator cbegin() const noexcept; 97053d81ceSMarshall Clow constexpr const_iterator cend() const noexcept; 98053d81ceSMarshall Clow const_reverse_iterator rbegin() const noexcept; 99053d81ceSMarshall Clow const_reverse_iterator rend() const noexcept; 100053d81ceSMarshall Clow const_reverse_iterator crbegin() const noexcept; 101053d81ceSMarshall Clow const_reverse_iterator crend() const noexcept; 102053d81ceSMarshall Clow 103053d81ceSMarshall Clow // 7.5, basic_string_view capacity 104053d81ceSMarshall Clow constexpr size_type size() const noexcept; 105053d81ceSMarshall Clow constexpr size_type length() const noexcept; 106053d81ceSMarshall Clow constexpr size_type max_size() const noexcept; 107053d81ceSMarshall Clow constexpr bool empty() const noexcept; 108053d81ceSMarshall Clow 109053d81ceSMarshall Clow // 7.6, basic_string_view element access 110053d81ceSMarshall Clow constexpr const_reference operator[](size_type pos) const; 111053d81ceSMarshall Clow constexpr const_reference at(size_type pos) const; 112053d81ceSMarshall Clow constexpr const_reference front() const; 113053d81ceSMarshall Clow constexpr const_reference back() const; 114053d81ceSMarshall Clow constexpr const_pointer data() const noexcept; 115053d81ceSMarshall Clow 116053d81ceSMarshall Clow // 7.7, basic_string_view modifiers 117053d81ceSMarshall Clow constexpr void remove_prefix(size_type n); 118053d81ceSMarshall Clow constexpr void remove_suffix(size_type n); 119053d81ceSMarshall Clow constexpr void swap(basic_string_view& s) noexcept; 120053d81ceSMarshall Clow 12106e2b737SArthur O'Dwyer size_type copy(charT* s, size_type n, size_type pos = 0) const; // constexpr in C++20 122053d81ceSMarshall Clow 123053d81ceSMarshall Clow constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const; 124053d81ceSMarshall Clow constexpr int compare(basic_string_view s) const noexcept; 125053d81ceSMarshall Clow constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const; 126053d81ceSMarshall Clow constexpr int compare(size_type pos1, size_type n1, 127053d81ceSMarshall Clow basic_string_view s, size_type pos2, size_type n2) const; 128053d81ceSMarshall Clow constexpr int compare(const charT* s) const; 129053d81ceSMarshall Clow constexpr int compare(size_type pos1, size_type n1, const charT* s) const; 130053d81ceSMarshall Clow constexpr int compare(size_type pos1, size_type n1, 131053d81ceSMarshall Clow const charT* s, size_type n2) const; 132053d81ceSMarshall Clow constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept; 133053d81ceSMarshall Clow constexpr size_type find(charT c, size_type pos = 0) const noexcept; 134dea74b28Szoecarver constexpr size_type find(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 135dea74b28Szoecarver constexpr size_type find(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension 136053d81ceSMarshall Clow constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept; 137053d81ceSMarshall Clow constexpr size_type rfind(charT c, size_type pos = npos) const noexcept; 138dea74b28Szoecarver constexpr size_type rfind(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 139dea74b28Szoecarver constexpr size_type rfind(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension 140053d81ceSMarshall Clow constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept; 141053d81ceSMarshall Clow constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept; 142dea74b28Szoecarver constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 143dea74b28Szoecarver constexpr size_type find_first_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension 144053d81ceSMarshall Clow constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept; 145053d81ceSMarshall Clow constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept; 146dea74b28Szoecarver constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 147dea74b28Szoecarver constexpr size_type find_last_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension 148053d81ceSMarshall Clow constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept; 149053d81ceSMarshall Clow constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept; 150dea74b28Szoecarver constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 151dea74b28Szoecarver constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension 152053d81ceSMarshall Clow constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept; 153053d81ceSMarshall Clow constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept; 154dea74b28Szoecarver constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 155dea74b28Szoecarver constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension 156053d81ceSMarshall Clow 157044b892cSMarek Kurdej constexpr bool starts_with(basic_string_view s) const noexcept; // C++20 158044b892cSMarek Kurdej constexpr bool starts_with(charT c) const noexcept; // C++20 159044b892cSMarek Kurdej constexpr bool starts_with(const charT* s) const; // C++20 160044b892cSMarek Kurdej constexpr bool ends_with(basic_string_view s) const noexcept; // C++20 161044b892cSMarek Kurdej constexpr bool ends_with(charT c) const noexcept; // C++20 162044b892cSMarek Kurdej constexpr bool ends_with(const charT* s) const; // C++20 163800259c9SMarshall Clow 1646ac9cb2aSWim Leflere constexpr bool contains(basic_string_view s) const noexcept; // C++2b 1656ac9cb2aSWim Leflere constexpr bool contains(charT c) const noexcept; // C++2b 1666ac9cb2aSWim Leflere constexpr bool contains(const charT* s) const; // C++2b 1676ac9cb2aSWim Leflere 168053d81ceSMarshall Clow private: 169053d81ceSMarshall Clow const_pointer data_; // exposition only 170053d81ceSMarshall Clow size_type size_; // exposition only 171053d81ceSMarshall Clow }; 172053d81ceSMarshall Clow 1734be7f489SJoe Loser // basic_string_view deduction guides 1744be7f489SJoe Loser template<class It, class End> 1754be7f489SJoe Loser basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>; // C++20 176c16b13ebSJoe Loser template<class Range> 177c16b13ebSJoe Loser basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23 1784be7f489SJoe Loser 179053d81ceSMarshall Clow // 7.11, Hash support 180053d81ceSMarshall Clow template <class T> struct hash; 181053d81ceSMarshall Clow template <> struct hash<string_view>; 18228f82becSMarek Kurdej template <> struct hash<u8string_view>; // C++20 183053d81ceSMarshall Clow template <> struct hash<u16string_view>; 184053d81ceSMarshall Clow template <> struct hash<u32string_view>; 185053d81ceSMarshall Clow template <> struct hash<wstring_view>; 186053d81ceSMarshall Clow 18759b48302SMarshall Clow constexpr basic_string_view<char> operator "" sv( const char *str, size_t len ) noexcept; 18859b48302SMarshall Clow constexpr basic_string_view<wchar_t> operator "" sv( const wchar_t *str, size_t len ) noexcept; 18928f82becSMarek Kurdej constexpr basic_string_view<char8_t> operator "" sv( const char8_t *str, size_t len ) noexcept; // C++20 19059b48302SMarshall Clow constexpr basic_string_view<char16_t> operator "" sv( const char16_t *str, size_t len ) noexcept; 19159b48302SMarshall Clow constexpr basic_string_view<char32_t> operator "" sv( const char32_t *str, size_t len ) noexcept; 1928fd58a6bSMarshall Clow 193053d81ceSMarshall Clow} // namespace std 194053d81ceSMarshall Clow 195053d81ceSMarshall Clow 196053d81ceSMarshall Clow*/ 197053d81ceSMarshall Clow 1982e2f3158SNikolas Klauser#include <__algorithm/min.h> 199f87aa19bSLouis Dionne#include <__assert> 200053d81ceSMarshall Clow#include <__config> 201c16b13ebSJoe Loser#include <__ranges/concepts.h> 202c16b13ebSJoe Loser#include <__ranges/data.h> 20301ace074SMark de Wever#include <__ranges/enable_borrowed_range.h> 204462f8f06SChristopher Di Bella#include <__ranges/enable_view.h> 205c16b13ebSJoe Loser#include <__ranges/size.h> 206053d81ceSMarshall Clow#include <__string> 2072d0f1fa4SArthur O'Dwyer#include <compare> 208bfbd73f8SArthur O'Dwyer#include <iosfwd> 209053d81ceSMarshall Clow#include <iterator> 210ca648c97SEric Fiselier#include <limits> 211ca648c97SEric Fiselier#include <stdexcept> 212c16b13ebSJoe Loser#include <type_traits> 213f56972e2SMarshall Clow#include <version> 214053d81ceSMarshall Clow 215053d81ceSMarshall Clow#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 216053d81ceSMarshall Clow# pragma GCC system_header 217053d81ceSMarshall Clow#endif 218053d81ceSMarshall Clow 219a016efb1SEric Fiselier_LIBCPP_PUSH_MACROS 220a016efb1SEric Fiselier#include <__undef_macros> 221a016efb1SEric Fiselier 222a016efb1SEric Fiselier 223053d81ceSMarshall Clow_LIBCPP_BEGIN_NAMESPACE_STD 224053d81ceSMarshall Clow 225053d81ceSMarshall Clowtemplate<class _CharT, class _Traits = char_traits<_CharT> > 2262a2c228cSRichard Smith class _LIBCPP_TEMPLATE_VIS basic_string_view; 2272a2c228cSRichard Smith 2282a2c228cSRichard Smithtypedef basic_string_view<char> string_view; 2295c40c994SArthur O'Dwyer#ifndef _LIBCPP_HAS_NO_CHAR8_T 2302a2c228cSRichard Smithtypedef basic_string_view<char8_t> u8string_view; 2312a2c228cSRichard Smith#endif 2322a2c228cSRichard Smithtypedef basic_string_view<char16_t> u16string_view; 2332a2c228cSRichard Smithtypedef basic_string_view<char32_t> u32string_view; 234f4c1258dSLouis Dionne#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 2352a2c228cSRichard Smithtypedef basic_string_view<wchar_t> wstring_view; 236f4c1258dSLouis Dionne#endif 2372a2c228cSRichard Smith 238611469c5SLouis Dionne// TODO: This is a workaround for some vendors to carry a downstream diff to accept `nullptr` in 239611469c5SLouis Dionne// string_view constructors. This can be refactored when this exact form isn't needed anymore. 240611469c5SLouis Dionnetemplate <class _Traits> 241611469c5SLouis Dionne_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR 242611469c5SLouis Dionneinline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT { 243611469c5SLouis Dionne // This needs to be a single statement for C++11 constexpr 244611469c5SLouis Dionne return _LIBCPP_ASSERT(__s != nullptr, "null pointer passed to non-null argument of char_traits<...>::length"), _Traits::length(__s); 245611469c5SLouis Dionne} 246611469c5SLouis Dionne 2472a2c228cSRichard Smithtemplate<class _CharT, class _Traits> 2482a2c228cSRichard Smithclass 2492a2c228cSRichard Smith _LIBCPP_PREFERRED_NAME(string_view) 2505c40c994SArthur O'Dwyer#ifndef _LIBCPP_HAS_NO_CHAR8_T 2512a2c228cSRichard Smith _LIBCPP_PREFERRED_NAME(u8string_view) 2522a2c228cSRichard Smith#endif 2532a2c228cSRichard Smith _LIBCPP_PREFERRED_NAME(u16string_view) 2542a2c228cSRichard Smith _LIBCPP_PREFERRED_NAME(u32string_view) 255f4c1258dSLouis Dionne _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstring_view)) 2562a2c228cSRichard Smith basic_string_view { 257053d81ceSMarshall Clowpublic: 258053d81ceSMarshall Clow // types 259053d81ceSMarshall Clow typedef _Traits traits_type; 260053d81ceSMarshall Clow typedef _CharT value_type; 2617d661bb2SMarshall Clow typedef _CharT* pointer; 262053d81ceSMarshall Clow typedef const _CharT* const_pointer; 2637d661bb2SMarshall Clow typedef _CharT& reference; 264053d81ceSMarshall Clow typedef const _CharT& const_reference; 265053d81ceSMarshall Clow typedef const_pointer const_iterator; // See [string.view.iterators] 266053d81ceSMarshall Clow typedef const_iterator iterator; 267053d81ceSMarshall Clow typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 268053d81ceSMarshall Clow typedef const_reverse_iterator reverse_iterator; 269053d81ceSMarshall Clow typedef size_t size_type; 270053d81ceSMarshall Clow typedef ptrdiff_t difference_type; 271053d81ceSMarshall Clow static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1); 272053d81ceSMarshall Clow 2734a6f3c47SMarshall Clow static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array"); 2744a6f3c47SMarshall Clow static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout"); 2754a6f3c47SMarshall Clow static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial"); 2764069c2bcSMarshall Clow static_assert((is_same<_CharT, typename traits_type::char_type>::value), 2774069c2bcSMarshall Clow "traits_type::char_type must be the same type as CharT"); 2784069c2bcSMarshall Clow 279053d81ceSMarshall Clow // [string.view.cons], construct/copy 280053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 281053d81ceSMarshall Clow basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {} 282053d81ceSMarshall Clow 283ae0e037fSArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY 284053d81ceSMarshall Clow basic_string_view(const basic_string_view&) _NOEXCEPT = default; 285053d81ceSMarshall Clow 286ae0e037fSArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY 287053d81ceSMarshall Clow basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default; 288053d81ceSMarshall Clow 289053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 290ac2b3e3aSMarshall Clow basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT 291053d81ceSMarshall Clow : __data(__s), __size(__len) 292053d81ceSMarshall Clow { 293f67524d4SMarshall Clow#if _LIBCPP_STD_VER > 11 294f67524d4SMarshall Clow _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr"); 295f67524d4SMarshall Clow#endif 296053d81ceSMarshall Clow } 297053d81ceSMarshall Clow 298*d2baefaeSJoe Loser#if _LIBCPP_STD_VER > 17 2994be7f489SJoe Loser template <contiguous_iterator _It, sized_sentinel_for<_It> _End> 30068e7e76aSJoe Loser requires (is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>) 3014be7f489SJoe Loser constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end) 3024be7f489SJoe Loser : __data(_VSTD::to_address(__begin)), __size(__end - __begin) 3034be7f489SJoe Loser { 3044be7f489SJoe Loser _LIBCPP_ASSERT((__end - __begin) >= 0, "std::string_view::string_view(iterator, sentinel) received invalid range"); 3054be7f489SJoe Loser } 306*d2baefaeSJoe Loser#endif // _LIBCPP_STD_VER > 17 3074be7f489SJoe Loser 308*d2baefaeSJoe Loser#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 309c16b13ebSJoe Loser template <class _Range> 310c16b13ebSJoe Loser requires ( 311c16b13ebSJoe Loser !is_same_v<remove_cvref_t<_Range>, basic_string_view> && 312c16b13ebSJoe Loser ranges::contiguous_range<_Range> && 313c16b13ebSJoe Loser ranges::sized_range<_Range> && 314c16b13ebSJoe Loser is_same_v<ranges::range_value_t<_Range>, _CharT> && 315c16b13ebSJoe Loser !is_convertible_v<_Range, const _CharT*> && 316c16b13ebSJoe Loser (!requires(remove_cvref_t<_Range>& d) { 317c16b13ebSJoe Loser d.operator _VSTD::basic_string_view<_CharT, _Traits>(); 318c16b13ebSJoe Loser }) && 319c16b13ebSJoe Loser (!requires { 320c16b13ebSJoe Loser typename remove_reference_t<_Range>::traits_type; 321c16b13ebSJoe Loser } || is_same_v<typename remove_reference_t<_Range>::traits_type, _Traits>) 322c16b13ebSJoe Loser ) 323c16b13ebSJoe Loser constexpr _LIBCPP_HIDE_FROM_ABI 324c16b13ebSJoe Loser basic_string_view(_Range&& __r) : __data(ranges::data(__r)), __size(ranges::size(__r)) {} 325*d2baefaeSJoe Loser#endif // _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 326c16b13ebSJoe Loser 327053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 328053d81ceSMarshall Clow basic_string_view(const _CharT* __s) 329d586f92cSArthur O'Dwyer : __data(__s), __size(_VSTD::__char_traits_length_checked<_Traits>(__s)) {} 330053d81ceSMarshall Clow 331775caa58SMarek Kurdej#if _LIBCPP_STD_VER > 20 332775caa58SMarek Kurdej basic_string_view(nullptr_t) = delete; 333775caa58SMarek Kurdej#endif 334775caa58SMarek Kurdej 335053d81ceSMarshall Clow // [string.view.iterators], iterators 336053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 337053d81ceSMarshall Clow const_iterator begin() const _NOEXCEPT { return cbegin(); } 338053d81ceSMarshall Clow 339053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 340053d81ceSMarshall Clow const_iterator end() const _NOEXCEPT { return cend(); } 341053d81ceSMarshall Clow 342053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 343053d81ceSMarshall Clow const_iterator cbegin() const _NOEXCEPT { return __data; } 344053d81ceSMarshall Clow 345053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 346053d81ceSMarshall Clow const_iterator cend() const _NOEXCEPT { return __data + __size; } 347053d81ceSMarshall Clow 348cddeb751SMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY 349053d81ceSMarshall Clow const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } 350053d81ceSMarshall Clow 351cddeb751SMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY 352053d81ceSMarshall Clow const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } 353053d81ceSMarshall Clow 354cddeb751SMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY 355053d81ceSMarshall Clow const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } 356053d81ceSMarshall Clow 357cddeb751SMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY 358053d81ceSMarshall Clow const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } 359053d81ceSMarshall Clow 360053d81ceSMarshall Clow // [string.view.capacity], capacity 361053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 362053d81ceSMarshall Clow size_type size() const _NOEXCEPT { return __size; } 363053d81ceSMarshall Clow 364053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 365053d81ceSMarshall Clow size_type length() const _NOEXCEPT { return __size; } 366053d81ceSMarshall Clow 367053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 3682db67e97SLouis Dionne size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max() / sizeof(value_type); } 369053d81ceSMarshall Clow 37025a7ba45SMarshall Clow _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 37125a7ba45SMarshall Clow bool empty() const _NOEXCEPT { return __size == 0; } 372053d81ceSMarshall Clow 373053d81ceSMarshall Clow // [string.view.access], element access 374053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 3759eff07a7SChris Palmer const_reference operator[](size_type __pos) const _NOEXCEPT { 3769eff07a7SChris Palmer return _LIBCPP_ASSERT(__pos < size(), "string_view[] index out of bounds"), __data[__pos]; 3779eff07a7SChris Palmer } 378053d81ceSMarshall Clow 379053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 380053d81ceSMarshall Clow const_reference at(size_type __pos) const 381053d81ceSMarshall Clow { 382053d81ceSMarshall Clow return __pos >= size() 3830fc8cec7SMarshall Clow ? (__throw_out_of_range("string_view::at"), __data[0]) 384053d81ceSMarshall Clow : __data[__pos]; 385053d81ceSMarshall Clow } 386053d81ceSMarshall Clow 387053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 3889ea0e473SMarshall Clow const_reference front() const _NOEXCEPT 389053d81ceSMarshall Clow { 390053d81ceSMarshall Clow return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0]; 391053d81ceSMarshall Clow } 392053d81ceSMarshall Clow 393053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 3949ea0e473SMarshall Clow const_reference back() const _NOEXCEPT 395053d81ceSMarshall Clow { 396053d81ceSMarshall Clow return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1]; 397053d81ceSMarshall Clow } 398053d81ceSMarshall Clow 399053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 400053d81ceSMarshall Clow const_pointer data() const _NOEXCEPT { return __data; } 401053d81ceSMarshall Clow 402053d81ceSMarshall Clow // [string.view.modifiers], modifiers: 403053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 404053d81ceSMarshall Clow void remove_prefix(size_type __n) _NOEXCEPT 405053d81ceSMarshall Clow { 406053d81ceSMarshall Clow _LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()"); 407053d81ceSMarshall Clow __data += __n; 408053d81ceSMarshall Clow __size -= __n; 409053d81ceSMarshall Clow } 410053d81ceSMarshall Clow 411053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 412053d81ceSMarshall Clow void remove_suffix(size_type __n) _NOEXCEPT 413053d81ceSMarshall Clow { 414053d81ceSMarshall Clow _LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()"); 415053d81ceSMarshall Clow __size -= __n; 416053d81ceSMarshall Clow } 417053d81ceSMarshall Clow 418053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 419053d81ceSMarshall Clow void swap(basic_string_view& __other) _NOEXCEPT 420053d81ceSMarshall Clow { 421053d81ceSMarshall Clow const value_type *__p = __data; 422053d81ceSMarshall Clow __data = __other.__data; 423053d81ceSMarshall Clow __other.__data = __p; 424053d81ceSMarshall Clow 425053d81ceSMarshall Clow size_type __sz = __size; 426053d81ceSMarshall Clow __size = __other.__size; 427053d81ceSMarshall Clow __other.__size = __sz; 428053d81ceSMarshall Clow } 429053d81ceSMarshall Clow 43006e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 431053d81ceSMarshall Clow size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const 432053d81ceSMarshall Clow { 433053d81ceSMarshall Clow if (__pos > size()) 4340fc8cec7SMarshall Clow __throw_out_of_range("string_view::copy"); 435053d81ceSMarshall Clow size_type __rlen = _VSTD::min(__n, size() - __pos); 4361c7fe126SMarshall Clow _Traits::copy(__s, data() + __pos, __rlen); 437053d81ceSMarshall Clow return __rlen; 438053d81ceSMarshall Clow } 439053d81ceSMarshall Clow 440053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 441053d81ceSMarshall Clow basic_string_view substr(size_type __pos = 0, size_type __n = npos) const 442053d81ceSMarshall Clow { 443053d81ceSMarshall Clow return __pos > size() 4440fc8cec7SMarshall Clow ? (__throw_out_of_range("string_view::substr"), basic_string_view()) 445053d81ceSMarshall Clow : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos)); 446053d81ceSMarshall Clow } 447053d81ceSMarshall Clow 448053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT 449053d81ceSMarshall Clow { 450053d81ceSMarshall Clow size_type __rlen = _VSTD::min( size(), __sv.size()); 451053d81ceSMarshall Clow int __retval = _Traits::compare(data(), __sv.data(), __rlen); 452053d81ceSMarshall Clow if ( __retval == 0 ) // first __rlen chars matched 453053d81ceSMarshall Clow __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 ); 454053d81ceSMarshall Clow return __retval; 455053d81ceSMarshall Clow } 456053d81ceSMarshall Clow 457053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 458053d81ceSMarshall Clow int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const 459053d81ceSMarshall Clow { 460053d81ceSMarshall Clow return substr(__pos1, __n1).compare(__sv); 461053d81ceSMarshall Clow } 462053d81ceSMarshall Clow 463053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 464053d81ceSMarshall Clow int compare( size_type __pos1, size_type __n1, 4659ffacf3dSEric Fiselier basic_string_view __sv, size_type __pos2, size_type __n2) const 466053d81ceSMarshall Clow { 4679ffacf3dSEric Fiselier return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); 468053d81ceSMarshall Clow } 469053d81ceSMarshall Clow 470053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 471aa849bc2SMarshall Clow int compare(const _CharT* __s) const _NOEXCEPT 472053d81ceSMarshall Clow { 473053d81ceSMarshall Clow return compare(basic_string_view(__s)); 474053d81ceSMarshall Clow } 475053d81ceSMarshall Clow 476053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 477053d81ceSMarshall Clow int compare(size_type __pos1, size_type __n1, const _CharT* __s) const 478053d81ceSMarshall Clow { 479053d81ceSMarshall Clow return substr(__pos1, __n1).compare(basic_string_view(__s)); 480053d81ceSMarshall Clow } 481053d81ceSMarshall Clow 482053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 483053d81ceSMarshall Clow int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const 484053d81ceSMarshall Clow { 485053d81ceSMarshall Clow return substr(__pos1, __n1).compare(basic_string_view(__s, __n2)); 486053d81ceSMarshall Clow } 487053d81ceSMarshall Clow 488053d81ceSMarshall Clow // find 489053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 490053d81ceSMarshall Clow size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT 491053d81ceSMarshall Clow { 492053d81ceSMarshall Clow _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); 493053d81ceSMarshall Clow return __str_find<value_type, size_type, traits_type, npos> 494053d81ceSMarshall Clow (data(), size(), __s.data(), __pos, __s.size()); 495053d81ceSMarshall Clow } 496053d81ceSMarshall Clow 497053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 498053d81ceSMarshall Clow size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT 499053d81ceSMarshall Clow { 500053d81ceSMarshall Clow return __str_find<value_type, size_type, traits_type, npos> 501053d81ceSMarshall Clow (data(), size(), __c, __pos); 502053d81ceSMarshall Clow } 503053d81ceSMarshall Clow 504053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 505dea74b28Szoecarver size_type find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 506053d81ceSMarshall Clow { 507053d81ceSMarshall Clow _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr"); 508053d81ceSMarshall Clow return __str_find<value_type, size_type, traits_type, npos> 509053d81ceSMarshall Clow (data(), size(), __s, __pos, __n); 510053d81ceSMarshall Clow } 511053d81ceSMarshall Clow 512053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 513dea74b28Szoecarver size_type find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT 514053d81ceSMarshall Clow { 515053d81ceSMarshall Clow _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr"); 516053d81ceSMarshall Clow return __str_find<value_type, size_type, traits_type, npos> 517053d81ceSMarshall Clow (data(), size(), __s, __pos, traits_type::length(__s)); 518053d81ceSMarshall Clow } 519053d81ceSMarshall Clow 520053d81ceSMarshall Clow // rfind 521053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 522053d81ceSMarshall Clow size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT 523053d81ceSMarshall Clow { 524053d81ceSMarshall Clow _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); 525053d81ceSMarshall Clow return __str_rfind<value_type, size_type, traits_type, npos> 526053d81ceSMarshall Clow (data(), size(), __s.data(), __pos, __s.size()); 527053d81ceSMarshall Clow } 528053d81ceSMarshall Clow 529053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 530053d81ceSMarshall Clow size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT 531053d81ceSMarshall Clow { 532053d81ceSMarshall Clow return __str_rfind<value_type, size_type, traits_type, npos> 533053d81ceSMarshall Clow (data(), size(), __c, __pos); 534053d81ceSMarshall Clow } 535053d81ceSMarshall Clow 536053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 537dea74b28Szoecarver size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 538053d81ceSMarshall Clow { 539053d81ceSMarshall Clow _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr"); 540053d81ceSMarshall Clow return __str_rfind<value_type, size_type, traits_type, npos> 541053d81ceSMarshall Clow (data(), size(), __s, __pos, __n); 542053d81ceSMarshall Clow } 543053d81ceSMarshall Clow 544053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 545dea74b28Szoecarver size_type rfind(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT 546053d81ceSMarshall Clow { 547053d81ceSMarshall Clow _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr"); 548053d81ceSMarshall Clow return __str_rfind<value_type, size_type, traits_type, npos> 549053d81ceSMarshall Clow (data(), size(), __s, __pos, traits_type::length(__s)); 550053d81ceSMarshall Clow } 551053d81ceSMarshall Clow 552053d81ceSMarshall Clow // find_first_of 553053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 554053d81ceSMarshall Clow size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT 555053d81ceSMarshall Clow { 556053d81ceSMarshall Clow _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr"); 557053d81ceSMarshall Clow return __str_find_first_of<value_type, size_type, traits_type, npos> 558053d81ceSMarshall Clow (data(), size(), __s.data(), __pos, __s.size()); 559053d81ceSMarshall Clow } 560053d81ceSMarshall Clow 561053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 562053d81ceSMarshall Clow size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT 563053d81ceSMarshall Clow { return find(__c, __pos); } 564053d81ceSMarshall Clow 565053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 566dea74b28Szoecarver size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 567053d81ceSMarshall Clow { 568053d81ceSMarshall Clow _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr"); 569053d81ceSMarshall Clow return __str_find_first_of<value_type, size_type, traits_type, npos> 570053d81ceSMarshall Clow (data(), size(), __s, __pos, __n); 571053d81ceSMarshall Clow } 572053d81ceSMarshall Clow 573053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 574dea74b28Szoecarver size_type find_first_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT 575053d81ceSMarshall Clow { 576053d81ceSMarshall Clow _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr"); 577053d81ceSMarshall Clow return __str_find_first_of<value_type, size_type, traits_type, npos> 578053d81ceSMarshall Clow (data(), size(), __s, __pos, traits_type::length(__s)); 579053d81ceSMarshall Clow } 580053d81ceSMarshall Clow 581053d81ceSMarshall Clow // find_last_of 582053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 583053d81ceSMarshall Clow size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT 584053d81ceSMarshall Clow { 585053d81ceSMarshall Clow _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr"); 586053d81ceSMarshall Clow return __str_find_last_of<value_type, size_type, traits_type, npos> 587053d81ceSMarshall Clow (data(), size(), __s.data(), __pos, __s.size()); 588053d81ceSMarshall Clow } 589053d81ceSMarshall Clow 590053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 591053d81ceSMarshall Clow size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT 592053d81ceSMarshall Clow { return rfind(__c, __pos); } 593053d81ceSMarshall Clow 594053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 595dea74b28Szoecarver size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 596053d81ceSMarshall Clow { 597053d81ceSMarshall Clow _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr"); 598053d81ceSMarshall Clow return __str_find_last_of<value_type, size_type, traits_type, npos> 599053d81ceSMarshall Clow (data(), size(), __s, __pos, __n); 600053d81ceSMarshall Clow } 601053d81ceSMarshall Clow 602053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 603dea74b28Szoecarver size_type find_last_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT 604053d81ceSMarshall Clow { 605053d81ceSMarshall Clow _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr"); 606053d81ceSMarshall Clow return __str_find_last_of<value_type, size_type, traits_type, npos> 607053d81ceSMarshall Clow (data(), size(), __s, __pos, traits_type::length(__s)); 608053d81ceSMarshall Clow } 609053d81ceSMarshall Clow 610053d81ceSMarshall Clow // find_first_not_of 611053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 612053d81ceSMarshall Clow size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT 613053d81ceSMarshall Clow { 614053d81ceSMarshall Clow _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr"); 615053d81ceSMarshall Clow return __str_find_first_not_of<value_type, size_type, traits_type, npos> 616053d81ceSMarshall Clow (data(), size(), __s.data(), __pos, __s.size()); 617053d81ceSMarshall Clow } 618053d81ceSMarshall Clow 619053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 620053d81ceSMarshall Clow size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT 621053d81ceSMarshall Clow { 622053d81ceSMarshall Clow return __str_find_first_not_of<value_type, size_type, traits_type, npos> 623053d81ceSMarshall Clow (data(), size(), __c, __pos); 624053d81ceSMarshall Clow } 625053d81ceSMarshall Clow 626053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 627dea74b28Szoecarver size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 628053d81ceSMarshall Clow { 629053d81ceSMarshall Clow _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr"); 630053d81ceSMarshall Clow return __str_find_first_not_of<value_type, size_type, traits_type, npos> 631053d81ceSMarshall Clow (data(), size(), __s, __pos, __n); 632053d81ceSMarshall Clow } 633053d81ceSMarshall Clow 634053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 635dea74b28Szoecarver size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT 636053d81ceSMarshall Clow { 637053d81ceSMarshall Clow _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr"); 638053d81ceSMarshall Clow return __str_find_first_not_of<value_type, size_type, traits_type, npos> 639053d81ceSMarshall Clow (data(), size(), __s, __pos, traits_type::length(__s)); 640053d81ceSMarshall Clow } 641053d81ceSMarshall Clow 642053d81ceSMarshall Clow // find_last_not_of 643053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 644053d81ceSMarshall Clow size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT 645053d81ceSMarshall Clow { 646053d81ceSMarshall Clow _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr"); 647053d81ceSMarshall Clow return __str_find_last_not_of<value_type, size_type, traits_type, npos> 648053d81ceSMarshall Clow (data(), size(), __s.data(), __pos, __s.size()); 649053d81ceSMarshall Clow } 650053d81ceSMarshall Clow 651053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 652053d81ceSMarshall Clow size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT 653053d81ceSMarshall Clow { 654053d81ceSMarshall Clow return __str_find_last_not_of<value_type, size_type, traits_type, npos> 655053d81ceSMarshall Clow (data(), size(), __c, __pos); 656053d81ceSMarshall Clow } 657053d81ceSMarshall Clow 658053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 659dea74b28Szoecarver size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 660053d81ceSMarshall Clow { 661053d81ceSMarshall Clow _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr"); 662053d81ceSMarshall Clow return __str_find_last_not_of<value_type, size_type, traits_type, npos> 663053d81ceSMarshall Clow (data(), size(), __s, __pos, __n); 664053d81ceSMarshall Clow } 665053d81ceSMarshall Clow 666053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 667dea74b28Szoecarver size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT 668053d81ceSMarshall Clow { 669053d81ceSMarshall Clow _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr"); 670053d81ceSMarshall Clow return __str_find_last_not_of<value_type, size_type, traits_type, npos> 671053d81ceSMarshall Clow (data(), size(), __s, __pos, traits_type::length(__s)); 672053d81ceSMarshall Clow } 673053d81ceSMarshall Clow 674800259c9SMarshall Clow#if _LIBCPP_STD_VER > 17 675ae0e037fSArthur O'Dwyer constexpr _LIBCPP_INLINE_VISIBILITY 676ae0e037fSArthur O'Dwyer bool starts_with(basic_string_view __s) const noexcept 677800259c9SMarshall Clow { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; } 678800259c9SMarshall Clow 679ae0e037fSArthur O'Dwyer constexpr _LIBCPP_INLINE_VISIBILITY 680ae0e037fSArthur O'Dwyer bool starts_with(value_type __c) const noexcept 681800259c9SMarshall Clow { return !empty() && _Traits::eq(front(), __c); } 682800259c9SMarshall Clow 683ae0e037fSArthur O'Dwyer constexpr _LIBCPP_INLINE_VISIBILITY 684ae0e037fSArthur O'Dwyer bool starts_with(const value_type* __s) const noexcept 685800259c9SMarshall Clow { return starts_with(basic_string_view(__s)); } 686800259c9SMarshall Clow 687ae0e037fSArthur O'Dwyer constexpr _LIBCPP_INLINE_VISIBILITY 688ae0e037fSArthur O'Dwyer bool ends_with(basic_string_view __s) const noexcept 689800259c9SMarshall Clow { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; } 690800259c9SMarshall Clow 691ae0e037fSArthur O'Dwyer constexpr _LIBCPP_INLINE_VISIBILITY 692ae0e037fSArthur O'Dwyer bool ends_with(value_type __c) const noexcept 693800259c9SMarshall Clow { return !empty() && _Traits::eq(back(), __c); } 694800259c9SMarshall Clow 695ae0e037fSArthur O'Dwyer constexpr _LIBCPP_INLINE_VISIBILITY 696ae0e037fSArthur O'Dwyer bool ends_with(const value_type* __s) const noexcept 697800259c9SMarshall Clow { return ends_with(basic_string_view(__s)); } 698800259c9SMarshall Clow#endif 699800259c9SMarshall Clow 7006ac9cb2aSWim Leflere#if _LIBCPP_STD_VER > 20 7016ac9cb2aSWim Leflere constexpr _LIBCPP_INLINE_VISIBILITY 7026ac9cb2aSWim Leflere bool contains(basic_string_view __sv) const noexcept 7036ac9cb2aSWim Leflere { return find(__sv) != npos; } 7046ac9cb2aSWim Leflere 7056ac9cb2aSWim Leflere constexpr _LIBCPP_INLINE_VISIBILITY 7066ac9cb2aSWim Leflere bool contains(value_type __c) const noexcept 7076ac9cb2aSWim Leflere { return find(__c) != npos; } 7086ac9cb2aSWim Leflere 7096ac9cb2aSWim Leflere constexpr _LIBCPP_INLINE_VISIBILITY 7106ac9cb2aSWim Leflere bool contains(const value_type* __s) const 7116ac9cb2aSWim Leflere { return find(__s) != npos; } 7126ac9cb2aSWim Leflere#endif 7136ac9cb2aSWim Leflere 714053d81ceSMarshall Clowprivate: 715053d81ceSMarshall Clow const value_type* __data; 716053d81ceSMarshall Clow size_type __size; 717053d81ceSMarshall Clow}; 718053d81ceSMarshall Clow 719*d2baefaeSJoe Loser#if _LIBCPP_STD_VER > 17 72001ace074SMark de Wevertemplate <class _CharT, class _Traits> 721462f8f06SChristopher Di Bellainline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true; 722462f8f06SChristopher Di Bella 723462f8f06SChristopher Di Bellatemplate <class _CharT, class _Traits> 72401ace074SMark de Weverinline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true; 725*d2baefaeSJoe Loser#endif // _LIBCPP_STD_VER > 17 726053d81ceSMarshall Clow 7274be7f489SJoe Loser// [string.view.deduct] 7284be7f489SJoe Loser 729*d2baefaeSJoe Loser#if _LIBCPP_STD_VER > 17 7304be7f489SJoe Losertemplate <contiguous_iterator _It, sized_sentinel_for<_It> _End> 7314be7f489SJoe Loser basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>; 732*d2baefaeSJoe Loser#endif // _LIBCPP_STD_VER > 17 7334be7f489SJoe Loser 734c16b13ebSJoe Loser 735*d2baefaeSJoe Loser#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 736c16b13ebSJoe Losertemplate <ranges::contiguous_range _Range> 737c16b13ebSJoe Loser basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>; 738*d2baefaeSJoe Loser#endif // _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 739c16b13ebSJoe Loser 740053d81ceSMarshall Clow// [string.view.comparison] 741053d81ceSMarshall Clow// operator == 742053d81ceSMarshall Clowtemplate<class _CharT, class _Traits> 743053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 744053d81ceSMarshall Clowbool operator==(basic_string_view<_CharT, _Traits> __lhs, 745053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 746053d81ceSMarshall Clow{ 747053d81ceSMarshall Clow if ( __lhs.size() != __rhs.size()) return false; 748053d81ceSMarshall Clow return __lhs.compare(__rhs) == 0; 749053d81ceSMarshall Clow} 750053d81ceSMarshall Clow 751c16b13ebSJoe Loser// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details. 752c16b13ebSJoe Loser// This applies to the other sufficient overloads below for the other comparison operators. 753c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 1> 754053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 755053d81ceSMarshall Clowbool operator==(basic_string_view<_CharT, _Traits> __lhs, 756053d81ceSMarshall Clow typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT 757053d81ceSMarshall Clow{ 758053d81ceSMarshall Clow if ( __lhs.size() != __rhs.size()) return false; 759053d81ceSMarshall Clow return __lhs.compare(__rhs) == 0; 760053d81ceSMarshall Clow} 761053d81ceSMarshall Clow 762c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 2> 763053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 764053d81ceSMarshall Clowbool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 765053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 766053d81ceSMarshall Clow{ 767053d81ceSMarshall Clow if ( __lhs.size() != __rhs.size()) return false; 768053d81ceSMarshall Clow return __lhs.compare(__rhs) == 0; 769053d81ceSMarshall Clow} 770053d81ceSMarshall Clow 771053d81ceSMarshall Clow 772053d81ceSMarshall Clow// operator != 773053d81ceSMarshall Clowtemplate<class _CharT, class _Traits> 774053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 775053d81ceSMarshall Clowbool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 776053d81ceSMarshall Clow{ 777053d81ceSMarshall Clow if ( __lhs.size() != __rhs.size()) 778053d81ceSMarshall Clow return true; 779053d81ceSMarshall Clow return __lhs.compare(__rhs) != 0; 780053d81ceSMarshall Clow} 781053d81ceSMarshall Clow 782c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 1> 783053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 784053d81ceSMarshall Clowbool operator!=(basic_string_view<_CharT, _Traits> __lhs, 785053d81ceSMarshall Clow typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT 786053d81ceSMarshall Clow{ 787053d81ceSMarshall Clow if ( __lhs.size() != __rhs.size()) 788053d81ceSMarshall Clow return true; 789053d81ceSMarshall Clow return __lhs.compare(__rhs) != 0; 790053d81ceSMarshall Clow} 791053d81ceSMarshall Clow 792c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 2> 793053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 794053d81ceSMarshall Clowbool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 795053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 796053d81ceSMarshall Clow{ 797053d81ceSMarshall Clow if ( __lhs.size() != __rhs.size()) 798053d81ceSMarshall Clow return true; 799053d81ceSMarshall Clow return __lhs.compare(__rhs) != 0; 800053d81ceSMarshall Clow} 801053d81ceSMarshall Clow 802053d81ceSMarshall Clow 803053d81ceSMarshall Clow// operator < 804053d81ceSMarshall Clowtemplate<class _CharT, class _Traits> 805053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 806053d81ceSMarshall Clowbool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 807053d81ceSMarshall Clow{ 808053d81ceSMarshall Clow return __lhs.compare(__rhs) < 0; 809053d81ceSMarshall Clow} 810053d81ceSMarshall Clow 811c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 1> 812053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 813053d81ceSMarshall Clowbool operator<(basic_string_view<_CharT, _Traits> __lhs, 814053d81ceSMarshall Clow typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT 815053d81ceSMarshall Clow{ 816053d81ceSMarshall Clow return __lhs.compare(__rhs) < 0; 817053d81ceSMarshall Clow} 818053d81ceSMarshall Clow 819c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 2> 820053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 821053d81ceSMarshall Clowbool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 822053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 823053d81ceSMarshall Clow{ 824053d81ceSMarshall Clow return __lhs.compare(__rhs) < 0; 825053d81ceSMarshall Clow} 826053d81ceSMarshall Clow 827053d81ceSMarshall Clow 828053d81ceSMarshall Clow// operator > 829053d81ceSMarshall Clowtemplate<class _CharT, class _Traits> 830053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 831053d81ceSMarshall Clowbool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 832053d81ceSMarshall Clow{ 833053d81ceSMarshall Clow return __lhs.compare(__rhs) > 0; 834053d81ceSMarshall Clow} 835053d81ceSMarshall Clow 836c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 1> 837053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 838053d81ceSMarshall Clowbool operator>(basic_string_view<_CharT, _Traits> __lhs, 839053d81ceSMarshall Clow typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT 840053d81ceSMarshall Clow{ 841053d81ceSMarshall Clow return __lhs.compare(__rhs) > 0; 842053d81ceSMarshall Clow} 843053d81ceSMarshall Clow 844c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 2> 845053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 846053d81ceSMarshall Clowbool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 847053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 848053d81ceSMarshall Clow{ 849053d81ceSMarshall Clow return __lhs.compare(__rhs) > 0; 850053d81ceSMarshall Clow} 851053d81ceSMarshall Clow 852053d81ceSMarshall Clow 853053d81ceSMarshall Clow// operator <= 854053d81ceSMarshall Clowtemplate<class _CharT, class _Traits> 855053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 856053d81ceSMarshall Clowbool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 857053d81ceSMarshall Clow{ 858053d81ceSMarshall Clow return __lhs.compare(__rhs) <= 0; 859053d81ceSMarshall Clow} 860053d81ceSMarshall Clow 861c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 1> 862053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 863053d81ceSMarshall Clowbool operator<=(basic_string_view<_CharT, _Traits> __lhs, 864053d81ceSMarshall Clow typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT 865053d81ceSMarshall Clow{ 866053d81ceSMarshall Clow return __lhs.compare(__rhs) <= 0; 867053d81ceSMarshall Clow} 868053d81ceSMarshall Clow 869c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 2> 870053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 871053d81ceSMarshall Clowbool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 872053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 873053d81ceSMarshall Clow{ 874053d81ceSMarshall Clow return __lhs.compare(__rhs) <= 0; 875053d81ceSMarshall Clow} 876053d81ceSMarshall Clow 877053d81ceSMarshall Clow 878053d81ceSMarshall Clow// operator >= 879053d81ceSMarshall Clowtemplate<class _CharT, class _Traits> 880053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 881053d81ceSMarshall Clowbool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 882053d81ceSMarshall Clow{ 883053d81ceSMarshall Clow return __lhs.compare(__rhs) >= 0; 884053d81ceSMarshall Clow} 885053d81ceSMarshall Clow 886053d81ceSMarshall Clow 887c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 1> 888053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 889053d81ceSMarshall Clowbool operator>=(basic_string_view<_CharT, _Traits> __lhs, 890053d81ceSMarshall Clow typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT 891053d81ceSMarshall Clow{ 892053d81ceSMarshall Clow return __lhs.compare(__rhs) >= 0; 893053d81ceSMarshall Clow} 894053d81ceSMarshall Clow 895c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 2> 896053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 897053d81ceSMarshall Clowbool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 898053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 899053d81ceSMarshall Clow{ 900053d81ceSMarshall Clow return __lhs.compare(__rhs) >= 0; 901053d81ceSMarshall Clow} 902053d81ceSMarshall Clow 903af4a29afSEric Fiselier 904af4a29afSEric Fiseliertemplate<class _CharT, class _Traits> 905af4a29afSEric Fiselierbasic_ostream<_CharT, _Traits>& 906af4a29afSEric Fiselieroperator<<(basic_ostream<_CharT, _Traits>& __os, 907af4a29afSEric Fiselier basic_string_view<_CharT, _Traits> __str); 908af4a29afSEric Fiselier 909053d81ceSMarshall Clow// [string.view.hash] 91093184302SMarshall Clowtemplate<class _CharT> 91193184302SMarshall Clowstruct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, char_traits<_CharT> > > 91293184302SMarshall Clow : public unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t> 913053d81ceSMarshall Clow{ 914a86710f1SLouis Dionne _LIBCPP_INLINE_VISIBILITY 91593184302SMarshall Clow size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT { 916053d81ceSMarshall Clow return __do_string_hash(__val.data(), __val.data() + __val.size()); 917053d81ceSMarshall Clow } 918a86710f1SLouis Dionne}; 919053d81ceSMarshall Clow 9208fd58a6bSMarshall Clow 9218fd58a6bSMarshall Clow#if _LIBCPP_STD_VER > 11 9228fd58a6bSMarshall Clowinline namespace literals 9238fd58a6bSMarshall Clow{ 9248fd58a6bSMarshall Clow inline namespace string_view_literals 9258fd58a6bSMarshall Clow { 9268fd58a6bSMarshall Clow inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 92759b48302SMarshall Clow basic_string_view<char> operator "" sv(const char *__str, size_t __len) _NOEXCEPT 9288fd58a6bSMarshall Clow { 9298fd58a6bSMarshall Clow return basic_string_view<char> (__str, __len); 9308fd58a6bSMarshall Clow } 9318fd58a6bSMarshall Clow 932f4c1258dSLouis Dionne#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 9338fd58a6bSMarshall Clow inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 93459b48302SMarshall Clow basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT 9358fd58a6bSMarshall Clow { 9368fd58a6bSMarshall Clow return basic_string_view<wchar_t> (__str, __len); 9378fd58a6bSMarshall Clow } 938f4c1258dSLouis Dionne#endif 9398fd58a6bSMarshall Clow 9405c40c994SArthur O'Dwyer#ifndef _LIBCPP_HAS_NO_CHAR8_T 9417dad0bd6SMarshall Clow inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 9427dad0bd6SMarshall Clow basic_string_view<char8_t> operator "" sv(const char8_t *__str, size_t __len) _NOEXCEPT 9437dad0bd6SMarshall Clow { 9447dad0bd6SMarshall Clow return basic_string_view<char8_t> (__str, __len); 9457dad0bd6SMarshall Clow } 9467dad0bd6SMarshall Clow#endif 9477dad0bd6SMarshall Clow 9488fd58a6bSMarshall Clow inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 94959b48302SMarshall Clow basic_string_view<char16_t> operator "" sv(const char16_t *__str, size_t __len) _NOEXCEPT 9508fd58a6bSMarshall Clow { 9518fd58a6bSMarshall Clow return basic_string_view<char16_t> (__str, __len); 9528fd58a6bSMarshall Clow } 9538fd58a6bSMarshall Clow 9548fd58a6bSMarshall Clow inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 95559b48302SMarshall Clow basic_string_view<char32_t> operator "" sv(const char32_t *__str, size_t __len) _NOEXCEPT 9568fd58a6bSMarshall Clow { 9578fd58a6bSMarshall Clow return basic_string_view<char32_t> (__str, __len); 9588fd58a6bSMarshall Clow } 959d2b0df35SNikolas Klauser } // namespace string_view_literals 960d2b0df35SNikolas Klauser} // namespace literals 9618fd58a6bSMarshall Clow#endif 962053d81ceSMarshall Clow_LIBCPP_END_NAMESPACE_STD 963053d81ceSMarshall Clow 964a016efb1SEric Fiselier_LIBCPP_POP_MACROS 965a016efb1SEric Fiselier 966053d81ceSMarshall Clow#endif // _LIBCPP_STRING_VIEW 967