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/* 14385cc25aSLouis Dionne 15053d81ceSMarshall Clow string_view synopsis 16053d81ceSMarshall Clow 17053d81ceSMarshall Clownamespace std { 18053d81ceSMarshall Clow 19053d81ceSMarshall Clow // 7.2, Class template basic_string_view 20053d81ceSMarshall Clow template<class charT, class traits = char_traits<charT>> 21053d81ceSMarshall Clow class basic_string_view; 22053d81ceSMarshall Clow 2301ace074SMark de Wever template<class charT, class traits> 24462f8f06SChristopher Di Bella inline constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true; 25462f8f06SChristopher Di Bella 26462f8f06SChristopher Di Bella template<class charT, class traits> 2701ace074SMark de Wever inline constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true; // C++20 2801ace074SMark de Wever 29053d81ceSMarshall Clow // 7.9, basic_string_view non-member comparison functions 30053d81ceSMarshall Clow template<class charT, class traits> 31053d81ceSMarshall Clow constexpr bool operator==(basic_string_view<charT, traits> x, 32053d81ceSMarshall Clow basic_string_view<charT, traits> y) noexcept; 33053d81ceSMarshall Clow template<class charT, class traits> 34053d81ceSMarshall Clow constexpr bool operator!=(basic_string_view<charT, traits> x, 35053d81ceSMarshall Clow basic_string_view<charT, traits> y) noexcept; 36053d81ceSMarshall Clow template<class charT, class traits> 37053d81ceSMarshall Clow constexpr bool operator< (basic_string_view<charT, traits> x, 38053d81ceSMarshall Clow basic_string_view<charT, traits> y) noexcept; 39053d81ceSMarshall Clow template<class charT, class traits> 40053d81ceSMarshall Clow constexpr bool operator> (basic_string_view<charT, traits> x, 41053d81ceSMarshall Clow basic_string_view<charT, traits> y) noexcept; 42053d81ceSMarshall Clow template<class charT, class traits> 43053d81ceSMarshall Clow constexpr bool operator<=(basic_string_view<charT, traits> x, 44053d81ceSMarshall Clow basic_string_view<charT, traits> y) noexcept; 45053d81ceSMarshall Clow template<class charT, class traits> 46053d81ceSMarshall Clow constexpr bool operator>=(basic_string_view<charT, traits> x, 47053d81ceSMarshall Clow basic_string_view<charT, traits> y) noexcept; 48053d81ceSMarshall Clow // see below, sufficient additional overloads of comparison functions 49053d81ceSMarshall Clow 50053d81ceSMarshall Clow // 7.10, Inserters and extractors 51053d81ceSMarshall Clow template<class charT, class traits> 52053d81ceSMarshall Clow basic_ostream<charT, traits>& 53053d81ceSMarshall Clow operator<<(basic_ostream<charT, traits>& os, 54053d81ceSMarshall Clow basic_string_view<charT, traits> str); 55053d81ceSMarshall Clow 56053d81ceSMarshall Clow // basic_string_view typedef names 57053d81ceSMarshall Clow typedef basic_string_view<char> string_view; 5828f82becSMarek Kurdej typedef basic_string_view<char8_t> u8string_view; // C++20 59053d81ceSMarshall Clow typedef basic_string_view<char16_t> u16string_view; 60053d81ceSMarshall Clow typedef basic_string_view<char32_t> u32string_view; 61053d81ceSMarshall Clow typedef basic_string_view<wchar_t> wstring_view; 62053d81ceSMarshall Clow 63053d81ceSMarshall Clow template<class charT, class traits = char_traits<charT>> 64053d81ceSMarshall Clow class basic_string_view { 65053d81ceSMarshall Clow public: 66053d81ceSMarshall Clow // types 67053d81ceSMarshall Clow typedef traits traits_type; 68053d81ceSMarshall Clow typedef charT value_type; 69053d81ceSMarshall Clow typedef charT* pointer; 70053d81ceSMarshall Clow typedef const charT* const_pointer; 71053d81ceSMarshall Clow typedef charT& reference; 72053d81ceSMarshall Clow typedef const charT& const_reference; 73053d81ceSMarshall Clow typedef implementation-defined const_iterator; 74053d81ceSMarshall Clow typedef const_iterator iterator; 75053d81ceSMarshall Clow typedef reverse_iterator<const_iterator> const_reverse_iterator; 76053d81ceSMarshall Clow typedef const_reverse_iterator reverse_iterator; 77053d81ceSMarshall Clow typedef size_t size_type; 78053d81ceSMarshall Clow typedef ptrdiff_t difference_type; 79053d81ceSMarshall Clow static constexpr size_type npos = size_type(-1); 80053d81ceSMarshall Clow 81053d81ceSMarshall Clow // 7.3, basic_string_view constructors and assignment operators 82053d81ceSMarshall Clow constexpr basic_string_view() noexcept; 83053d81ceSMarshall Clow constexpr basic_string_view(const basic_string_view&) noexcept = default; 84053d81ceSMarshall Clow basic_string_view& operator=(const basic_string_view&) noexcept = default; 85053d81ceSMarshall Clow template<class Allocator> 86053d81ceSMarshall Clow constexpr basic_string_view(const charT* str); 87775caa58SMarek Kurdej basic_string_view(nullptr_t) = delete; // C++2b 88053d81ceSMarshall Clow constexpr basic_string_view(const charT* str, size_type len); 894be7f489SJoe Loser template <class It, class End> 904be7f489SJoe Loser constexpr basic_string_view(It begin, End end); // C++20 91c16b13ebSJoe Loser template <class Range> 92c16b13ebSJoe Loser constexpr basic_string_view(Range&& r); // C++23 93053d81ceSMarshall Clow 94053d81ceSMarshall Clow // 7.4, basic_string_view iterator support 95053d81ceSMarshall Clow constexpr const_iterator begin() const noexcept; 96053d81ceSMarshall Clow constexpr const_iterator end() const noexcept; 97053d81ceSMarshall Clow constexpr const_iterator cbegin() const noexcept; 98053d81ceSMarshall Clow constexpr const_iterator cend() const noexcept; 99053d81ceSMarshall Clow const_reverse_iterator rbegin() const noexcept; 100053d81ceSMarshall Clow const_reverse_iterator rend() const noexcept; 101053d81ceSMarshall Clow const_reverse_iterator crbegin() const noexcept; 102053d81ceSMarshall Clow const_reverse_iterator crend() const noexcept; 103053d81ceSMarshall Clow 104053d81ceSMarshall Clow // 7.5, basic_string_view capacity 105053d81ceSMarshall Clow constexpr size_type size() const noexcept; 106053d81ceSMarshall Clow constexpr size_type length() const noexcept; 107053d81ceSMarshall Clow constexpr size_type max_size() const noexcept; 108053d81ceSMarshall Clow constexpr bool empty() const noexcept; 109053d81ceSMarshall Clow 110053d81ceSMarshall Clow // 7.6, basic_string_view element access 111053d81ceSMarshall Clow constexpr const_reference operator[](size_type pos) const; 112053d81ceSMarshall Clow constexpr const_reference at(size_type pos) const; 113053d81ceSMarshall Clow constexpr const_reference front() const; 114053d81ceSMarshall Clow constexpr const_reference back() const; 115053d81ceSMarshall Clow constexpr const_pointer data() const noexcept; 116053d81ceSMarshall Clow 117053d81ceSMarshall Clow // 7.7, basic_string_view modifiers 118053d81ceSMarshall Clow constexpr void remove_prefix(size_type n); 119053d81ceSMarshall Clow constexpr void remove_suffix(size_type n); 120053d81ceSMarshall Clow constexpr void swap(basic_string_view& s) noexcept; 121053d81ceSMarshall Clow 12206e2b737SArthur O'Dwyer size_type copy(charT* s, size_type n, size_type pos = 0) const; // constexpr in C++20 123053d81ceSMarshall Clow 124053d81ceSMarshall Clow constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const; 125053d81ceSMarshall Clow constexpr int compare(basic_string_view s) const noexcept; 126053d81ceSMarshall Clow constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const; 127053d81ceSMarshall Clow constexpr int compare(size_type pos1, size_type n1, 128053d81ceSMarshall Clow basic_string_view s, size_type pos2, size_type n2) const; 129053d81ceSMarshall Clow constexpr int compare(const charT* s) const; 130053d81ceSMarshall Clow constexpr int compare(size_type pos1, size_type n1, const charT* s) const; 131053d81ceSMarshall Clow constexpr int compare(size_type pos1, size_type n1, 132053d81ceSMarshall Clow const charT* s, size_type n2) const; 133053d81ceSMarshall Clow constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept; 134053d81ceSMarshall Clow constexpr size_type find(charT c, size_type pos = 0) const noexcept; 135dea74b28Szoecarver constexpr size_type find(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 136dea74b28Szoecarver constexpr size_type find(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension 137053d81ceSMarshall Clow constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept; 138053d81ceSMarshall Clow constexpr size_type rfind(charT c, size_type pos = npos) const noexcept; 139dea74b28Szoecarver constexpr size_type rfind(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 140dea74b28Szoecarver constexpr size_type rfind(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension 141053d81ceSMarshall Clow constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept; 142053d81ceSMarshall Clow constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept; 143dea74b28Szoecarver constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 144dea74b28Szoecarver constexpr size_type find_first_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension 145053d81ceSMarshall Clow constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept; 146053d81ceSMarshall Clow constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept; 147dea74b28Szoecarver constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 148dea74b28Szoecarver constexpr size_type find_last_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension 149053d81ceSMarshall Clow constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept; 150053d81ceSMarshall Clow constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept; 151dea74b28Szoecarver constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 152dea74b28Szoecarver constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension 153053d81ceSMarshall Clow constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept; 154053d81ceSMarshall Clow constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept; 155dea74b28Szoecarver constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension 156dea74b28Szoecarver constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension 157053d81ceSMarshall Clow 158044b892cSMarek Kurdej constexpr bool starts_with(basic_string_view s) const noexcept; // C++20 159044b892cSMarek Kurdej constexpr bool starts_with(charT c) const noexcept; // C++20 160044b892cSMarek Kurdej constexpr bool starts_with(const charT* s) const; // C++20 161044b892cSMarek Kurdej constexpr bool ends_with(basic_string_view s) const noexcept; // C++20 162044b892cSMarek Kurdej constexpr bool ends_with(charT c) const noexcept; // C++20 163044b892cSMarek Kurdej constexpr bool ends_with(const charT* s) const; // C++20 164800259c9SMarshall Clow 1656ac9cb2aSWim Leflere constexpr bool contains(basic_string_view s) const noexcept; // C++2b 1666ac9cb2aSWim Leflere constexpr bool contains(charT c) const noexcept; // C++2b 1676ac9cb2aSWim Leflere constexpr bool contains(const charT* s) const; // C++2b 1686ac9cb2aSWim Leflere 169053d81ceSMarshall Clow private: 170053d81ceSMarshall Clow const_pointer data_; // exposition only 171053d81ceSMarshall Clow size_type size_; // exposition only 172053d81ceSMarshall Clow }; 173053d81ceSMarshall Clow 1744be7f489SJoe Loser // basic_string_view deduction guides 1754be7f489SJoe Loser template<class It, class End> 1764be7f489SJoe Loser basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>; // C++20 177c16b13ebSJoe Loser template<class Range> 178c16b13ebSJoe Loser basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23 1794be7f489SJoe Loser 180053d81ceSMarshall Clow // 7.11, Hash support 181053d81ceSMarshall Clow template <class T> struct hash; 182053d81ceSMarshall Clow template <> struct hash<string_view>; 18328f82becSMarek Kurdej template <> struct hash<u8string_view>; // C++20 184053d81ceSMarshall Clow template <> struct hash<u16string_view>; 185053d81ceSMarshall Clow template <> struct hash<u32string_view>; 186053d81ceSMarshall Clow template <> struct hash<wstring_view>; 187053d81ceSMarshall Clow 18859b48302SMarshall Clow constexpr basic_string_view<char> operator "" sv( const char *str, size_t len ) noexcept; 18959b48302SMarshall Clow constexpr basic_string_view<wchar_t> operator "" sv( const wchar_t *str, size_t len ) noexcept; 19028f82becSMarek Kurdej constexpr basic_string_view<char8_t> operator "" sv( const char8_t *str, size_t len ) noexcept; // C++20 19159b48302SMarshall Clow constexpr basic_string_view<char16_t> operator "" sv( const char16_t *str, size_t len ) noexcept; 19259b48302SMarshall Clow constexpr basic_string_view<char32_t> operator "" sv( const char32_t *str, size_t len ) noexcept; 1938fd58a6bSMarshall Clow 194053d81ceSMarshall Clow} // namespace std 195053d81ceSMarshall Clow 196053d81ceSMarshall Clow 197053d81ceSMarshall Clow*/ 198053d81ceSMarshall Clow 1992e2f3158SNikolas Klauser#include <__algorithm/min.h> 200385cc25aSLouis Dionne#include <__assert> // all public C++ headers provide the assertion handler 201053d81ceSMarshall Clow#include <__config> 202976f3705SNikolas Klauser#include <__functional/hash.h> 20334f73804SNikolas Klauser#include <__functional/unary_function.h> 2049924d8d6SKonstantin Varlamov#include <__fwd/string_view.h> 2053cd4531bSNikolas Klauser#include <__iterator/concepts.h> 2063cd4531bSNikolas Klauser#include <__iterator/readable_traits.h> 2073cd4531bSNikolas Klauser#include <__iterator/reverse_iterator.h> 2083cd4531bSNikolas Klauser#include <__memory/pointer_traits.h> 209c16b13ebSJoe Loser#include <__ranges/concepts.h> 210c16b13ebSJoe Loser#include <__ranges/data.h> 21101ace074SMark de Wever#include <__ranges/enable_borrowed_range.h> 212462f8f06SChristopher Di Bella#include <__ranges/enable_view.h> 213c16b13ebSJoe Loser#include <__ranges/size.h> 214976f3705SNikolas Klauser#include <__string/char_traits.h> 215bfbd73f8SArthur O'Dwyer#include <iosfwd> 216ca648c97SEric Fiselier#include <limits> 217ca648c97SEric Fiselier#include <stdexcept> 218c16b13ebSJoe Loser#include <type_traits> 219f56972e2SMarshall Clow#include <version> 220053d81ceSMarshall Clow 221de4a57cbSLouis Dionne#ifndef _LIBCPP_REMOVE_TRANSITIVE_INCLUDES 222de4a57cbSLouis Dionne# include <algorithm> 223de4a57cbSLouis Dionne# include <functional> 224de4a57cbSLouis Dionne# include <iterator> 225de4a57cbSLouis Dionne#endif 226de4a57cbSLouis Dionne 227db1978b6SNikolas Klauser// standard-mandated includes 228db1978b6SNikolas Klauser 229db1978b6SNikolas Klauser// [iterator.range] 230db1978b6SNikolas Klauser#include <__iterator/access.h> 231db1978b6SNikolas Klauser#include <__iterator/data.h> 232db1978b6SNikolas Klauser#include <__iterator/empty.h> 233db1978b6SNikolas Klauser#include <__iterator/reverse_access.h> 234db1978b6SNikolas Klauser#include <__iterator/size.h> 235db1978b6SNikolas Klauser 236db1978b6SNikolas Klauser// [string.view.synop] 237db1978b6SNikolas Klauser#include <compare> 238db1978b6SNikolas Klauser 239053d81ceSMarshall Clow#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 240053d81ceSMarshall Clow# pragma GCC system_header 241053d81ceSMarshall Clow#endif 242053d81ceSMarshall Clow 243a016efb1SEric Fiselier_LIBCPP_PUSH_MACROS 244a016efb1SEric Fiselier#include <__undef_macros> 245a016efb1SEric Fiselier 246a016efb1SEric Fiselier 247053d81ceSMarshall Clow_LIBCPP_BEGIN_NAMESPACE_STD 248053d81ceSMarshall Clow 249611469c5SLouis Dionne// TODO: This is a workaround for some vendors to carry a downstream diff to accept `nullptr` in 250611469c5SLouis Dionne// string_view constructors. This can be refactored when this exact form isn't needed anymore. 251611469c5SLouis Dionnetemplate <class _Traits> 252611469c5SLouis Dionne_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR 253611469c5SLouis Dionneinline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT { 254611469c5SLouis Dionne // This needs to be a single statement for C++11 constexpr 255611469c5SLouis Dionne return _LIBCPP_ASSERT(__s != nullptr, "null pointer passed to non-null argument of char_traits<...>::length"), _Traits::length(__s); 256611469c5SLouis Dionne} 257611469c5SLouis Dionne 2582a2c228cSRichard Smithtemplate<class _CharT, class _Traits> 2592a2c228cSRichard Smithclass 2602a2c228cSRichard Smith _LIBCPP_PREFERRED_NAME(string_view) 2615c40c994SArthur O'Dwyer#ifndef _LIBCPP_HAS_NO_CHAR8_T 2622a2c228cSRichard Smith _LIBCPP_PREFERRED_NAME(u8string_view) 2632a2c228cSRichard Smith#endif 2642a2c228cSRichard Smith _LIBCPP_PREFERRED_NAME(u16string_view) 2652a2c228cSRichard Smith _LIBCPP_PREFERRED_NAME(u32string_view) 266f4c1258dSLouis Dionne _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstring_view)) 2672a2c228cSRichard Smith basic_string_view { 268053d81ceSMarshall Clowpublic: 269053d81ceSMarshall Clow // types 270053d81ceSMarshall Clow typedef _Traits traits_type; 271053d81ceSMarshall Clow typedef _CharT value_type; 2727d661bb2SMarshall Clow typedef _CharT* pointer; 273053d81ceSMarshall Clow typedef const _CharT* const_pointer; 2747d661bb2SMarshall Clow typedef _CharT& reference; 275053d81ceSMarshall Clow typedef const _CharT& const_reference; 276053d81ceSMarshall Clow typedef const_pointer const_iterator; // See [string.view.iterators] 277053d81ceSMarshall Clow typedef const_iterator iterator; 278053d81ceSMarshall Clow typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 279053d81ceSMarshall Clow typedef const_reverse_iterator reverse_iterator; 280053d81ceSMarshall Clow typedef size_t size_type; 281053d81ceSMarshall Clow typedef ptrdiff_t difference_type; 282053d81ceSMarshall Clow static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1); 283053d81ceSMarshall Clow 2844a6f3c47SMarshall Clow static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array"); 2854a6f3c47SMarshall Clow static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout"); 2864a6f3c47SMarshall Clow static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial"); 2874069c2bcSMarshall Clow static_assert((is_same<_CharT, typename traits_type::char_type>::value), 2884069c2bcSMarshall Clow "traits_type::char_type must be the same type as CharT"); 2894069c2bcSMarshall Clow 290053d81ceSMarshall Clow // [string.view.cons], construct/copy 291053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 292053d81ceSMarshall Clow basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {} 293053d81ceSMarshall Clow 294ae0e037fSArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY 295053d81ceSMarshall Clow basic_string_view(const basic_string_view&) _NOEXCEPT = default; 296053d81ceSMarshall Clow 297ae0e037fSArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY 298053d81ceSMarshall Clow basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default; 299053d81ceSMarshall Clow 300053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 301ac2b3e3aSMarshall Clow basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT 302053d81ceSMarshall Clow : __data(__s), __size(__len) 303053d81ceSMarshall Clow { 304f67524d4SMarshall Clow#if _LIBCPP_STD_VER > 11 305f67524d4SMarshall Clow _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr"); 306f67524d4SMarshall Clow#endif 307053d81ceSMarshall Clow } 308053d81ceSMarshall Clow 309d2baefaeSJoe Loser#if _LIBCPP_STD_VER > 17 3104be7f489SJoe Loser template <contiguous_iterator _It, sized_sentinel_for<_It> _End> 31168e7e76aSJoe Loser requires (is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>) 3124be7f489SJoe Loser constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end) 3134be7f489SJoe Loser : __data(_VSTD::to_address(__begin)), __size(__end - __begin) 3144be7f489SJoe Loser { 3154be7f489SJoe Loser _LIBCPP_ASSERT((__end - __begin) >= 0, "std::string_view::string_view(iterator, sentinel) received invalid range"); 3164be7f489SJoe Loser } 317d2baefaeSJoe Loser#endif // _LIBCPP_STD_VER > 17 3184be7f489SJoe Loser 319d2baefaeSJoe Loser#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 320c16b13ebSJoe Loser template <class _Range> 321c16b13ebSJoe Loser requires ( 322c16b13ebSJoe Loser !is_same_v<remove_cvref_t<_Range>, basic_string_view> && 323c16b13ebSJoe Loser ranges::contiguous_range<_Range> && 324c16b13ebSJoe Loser ranges::sized_range<_Range> && 325c16b13ebSJoe Loser is_same_v<ranges::range_value_t<_Range>, _CharT> && 326c16b13ebSJoe Loser !is_convertible_v<_Range, const _CharT*> && 327*b48c5010SNikolas Klauser (!requires(remove_cvref_t<_Range>& __d) { 328*b48c5010SNikolas Klauser __d.operator _VSTD::basic_string_view<_CharT, _Traits>(); 329c16b13ebSJoe Loser }) && 330c16b13ebSJoe Loser (!requires { 331c16b13ebSJoe Loser typename remove_reference_t<_Range>::traits_type; 332c16b13ebSJoe Loser } || is_same_v<typename remove_reference_t<_Range>::traits_type, _Traits>) 333c16b13ebSJoe Loser ) 334c16b13ebSJoe Loser constexpr _LIBCPP_HIDE_FROM_ABI 335c16b13ebSJoe Loser basic_string_view(_Range&& __r) : __data(ranges::data(__r)), __size(ranges::size(__r)) {} 336d2baefaeSJoe Loser#endif // _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 337c16b13ebSJoe Loser 338053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 339053d81ceSMarshall Clow basic_string_view(const _CharT* __s) 340d586f92cSArthur O'Dwyer : __data(__s), __size(_VSTD::__char_traits_length_checked<_Traits>(__s)) {} 341053d81ceSMarshall Clow 342775caa58SMarek Kurdej#if _LIBCPP_STD_VER > 20 343775caa58SMarek Kurdej basic_string_view(nullptr_t) = delete; 344775caa58SMarek Kurdej#endif 345775caa58SMarek Kurdej 346053d81ceSMarshall Clow // [string.view.iterators], iterators 347053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 348053d81ceSMarshall Clow const_iterator begin() const _NOEXCEPT { return cbegin(); } 349053d81ceSMarshall Clow 350053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 351053d81ceSMarshall Clow const_iterator end() const _NOEXCEPT { return cend(); } 352053d81ceSMarshall Clow 353053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 354053d81ceSMarshall Clow const_iterator cbegin() const _NOEXCEPT { return __data; } 355053d81ceSMarshall Clow 356053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 357053d81ceSMarshall Clow const_iterator cend() const _NOEXCEPT { return __data + __size; } 358053d81ceSMarshall Clow 359cddeb751SMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY 360053d81ceSMarshall Clow const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } 361053d81ceSMarshall Clow 362cddeb751SMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY 363053d81ceSMarshall Clow const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } 364053d81ceSMarshall Clow 365cddeb751SMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY 366053d81ceSMarshall Clow const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); } 367053d81ceSMarshall Clow 368cddeb751SMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY 369053d81ceSMarshall Clow const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); } 370053d81ceSMarshall Clow 371053d81ceSMarshall Clow // [string.view.capacity], capacity 372053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 373053d81ceSMarshall Clow size_type size() const _NOEXCEPT { return __size; } 374053d81ceSMarshall Clow 375053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 376053d81ceSMarshall Clow size_type length() const _NOEXCEPT { return __size; } 377053d81ceSMarshall Clow 378053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 3792db67e97SLouis Dionne size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max() / sizeof(value_type); } 380053d81ceSMarshall Clow 38125a7ba45SMarshall Clow _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 38225a7ba45SMarshall Clow bool empty() const _NOEXCEPT { return __size == 0; } 383053d81ceSMarshall Clow 384053d81ceSMarshall Clow // [string.view.access], element access 385053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 3869eff07a7SChris Palmer const_reference operator[](size_type __pos) const _NOEXCEPT { 3879eff07a7SChris Palmer return _LIBCPP_ASSERT(__pos < size(), "string_view[] index out of bounds"), __data[__pos]; 3889eff07a7SChris Palmer } 389053d81ceSMarshall Clow 390053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 391053d81ceSMarshall Clow const_reference at(size_type __pos) const 392053d81ceSMarshall Clow { 393053d81ceSMarshall Clow return __pos >= size() 3940fc8cec7SMarshall Clow ? (__throw_out_of_range("string_view::at"), __data[0]) 395053d81ceSMarshall Clow : __data[__pos]; 396053d81ceSMarshall Clow } 397053d81ceSMarshall Clow 398053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 3999ea0e473SMarshall Clow const_reference front() const _NOEXCEPT 400053d81ceSMarshall Clow { 401053d81ceSMarshall Clow return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0]; 402053d81ceSMarshall Clow } 403053d81ceSMarshall Clow 404053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 4059ea0e473SMarshall Clow const_reference back() const _NOEXCEPT 406053d81ceSMarshall Clow { 407053d81ceSMarshall Clow return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1]; 408053d81ceSMarshall Clow } 409053d81ceSMarshall Clow 410053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 411053d81ceSMarshall Clow const_pointer data() const _NOEXCEPT { return __data; } 412053d81ceSMarshall Clow 413053d81ceSMarshall Clow // [string.view.modifiers], modifiers: 414053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 415053d81ceSMarshall Clow void remove_prefix(size_type __n) _NOEXCEPT 416053d81ceSMarshall Clow { 417053d81ceSMarshall Clow _LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()"); 418053d81ceSMarshall Clow __data += __n; 419053d81ceSMarshall Clow __size -= __n; 420053d81ceSMarshall Clow } 421053d81ceSMarshall Clow 422053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 423053d81ceSMarshall Clow void remove_suffix(size_type __n) _NOEXCEPT 424053d81ceSMarshall Clow { 425053d81ceSMarshall Clow _LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()"); 426053d81ceSMarshall Clow __size -= __n; 427053d81ceSMarshall Clow } 428053d81ceSMarshall Clow 429053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 430053d81ceSMarshall Clow void swap(basic_string_view& __other) _NOEXCEPT 431053d81ceSMarshall Clow { 432053d81ceSMarshall Clow const value_type *__p = __data; 433053d81ceSMarshall Clow __data = __other.__data; 434053d81ceSMarshall Clow __other.__data = __p; 435053d81ceSMarshall Clow 436053d81ceSMarshall Clow size_type __sz = __size; 437053d81ceSMarshall Clow __size = __other.__size; 438053d81ceSMarshall Clow __other.__size = __sz; 439053d81ceSMarshall Clow } 440053d81ceSMarshall Clow 44106e2b737SArthur O'Dwyer _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 442053d81ceSMarshall Clow size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const 443053d81ceSMarshall Clow { 444053d81ceSMarshall Clow if (__pos > size()) 4450fc8cec7SMarshall Clow __throw_out_of_range("string_view::copy"); 446053d81ceSMarshall Clow size_type __rlen = _VSTD::min(__n, size() - __pos); 4471c7fe126SMarshall Clow _Traits::copy(__s, data() + __pos, __rlen); 448053d81ceSMarshall Clow return __rlen; 449053d81ceSMarshall Clow } 450053d81ceSMarshall Clow 451053d81ceSMarshall Clow _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY 452053d81ceSMarshall Clow basic_string_view substr(size_type __pos = 0, size_type __n = npos) const 453053d81ceSMarshall Clow { 454053d81ceSMarshall Clow return __pos > size() 4550fc8cec7SMarshall Clow ? (__throw_out_of_range("string_view::substr"), basic_string_view()) 456053d81ceSMarshall Clow : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos)); 457053d81ceSMarshall Clow } 458053d81ceSMarshall Clow 459053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT 460053d81ceSMarshall Clow { 461053d81ceSMarshall Clow size_type __rlen = _VSTD::min( size(), __sv.size()); 462053d81ceSMarshall Clow int __retval = _Traits::compare(data(), __sv.data(), __rlen); 463053d81ceSMarshall Clow if ( __retval == 0 ) // first __rlen chars matched 464053d81ceSMarshall Clow __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 ); 465053d81ceSMarshall Clow return __retval; 466053d81ceSMarshall Clow } 467053d81ceSMarshall Clow 468053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 469053d81ceSMarshall Clow int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const 470053d81ceSMarshall Clow { 471053d81ceSMarshall Clow return substr(__pos1, __n1).compare(__sv); 472053d81ceSMarshall Clow } 473053d81ceSMarshall Clow 474053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 475053d81ceSMarshall Clow int compare( size_type __pos1, size_type __n1, 4769ffacf3dSEric Fiselier basic_string_view __sv, size_type __pos2, size_type __n2) const 477053d81ceSMarshall Clow { 4789ffacf3dSEric Fiselier return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); 479053d81ceSMarshall Clow } 480053d81ceSMarshall Clow 481053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 482aa849bc2SMarshall Clow int compare(const _CharT* __s) const _NOEXCEPT 483053d81ceSMarshall Clow { 484053d81ceSMarshall Clow return compare(basic_string_view(__s)); 485053d81ceSMarshall Clow } 486053d81ceSMarshall Clow 487053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 488053d81ceSMarshall Clow int compare(size_type __pos1, size_type __n1, const _CharT* __s) const 489053d81ceSMarshall Clow { 490053d81ceSMarshall Clow return substr(__pos1, __n1).compare(basic_string_view(__s)); 491053d81ceSMarshall Clow } 492053d81ceSMarshall Clow 493053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 494053d81ceSMarshall Clow int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const 495053d81ceSMarshall Clow { 496053d81ceSMarshall Clow return substr(__pos1, __n1).compare(basic_string_view(__s, __n2)); 497053d81ceSMarshall Clow } 498053d81ceSMarshall Clow 499053d81ceSMarshall Clow // find 500053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 501053d81ceSMarshall Clow size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT 502053d81ceSMarshall Clow { 503053d81ceSMarshall Clow _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); 504053d81ceSMarshall Clow return __str_find<value_type, size_type, traits_type, npos> 505053d81ceSMarshall Clow (data(), size(), __s.data(), __pos, __s.size()); 506053d81ceSMarshall Clow } 507053d81ceSMarshall Clow 508053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 509053d81ceSMarshall Clow size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT 510053d81ceSMarshall Clow { 511053d81ceSMarshall Clow return __str_find<value_type, size_type, traits_type, npos> 512053d81ceSMarshall Clow (data(), size(), __c, __pos); 513053d81ceSMarshall Clow } 514053d81ceSMarshall Clow 515053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 516dea74b28Szoecarver size_type find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 517053d81ceSMarshall Clow { 518053d81ceSMarshall Clow _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr"); 519053d81ceSMarshall Clow return __str_find<value_type, size_type, traits_type, npos> 520053d81ceSMarshall Clow (data(), size(), __s, __pos, __n); 521053d81ceSMarshall Clow } 522053d81ceSMarshall Clow 523053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 524dea74b28Szoecarver size_type find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT 525053d81ceSMarshall Clow { 526053d81ceSMarshall Clow _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr"); 527053d81ceSMarshall Clow return __str_find<value_type, size_type, traits_type, npos> 528053d81ceSMarshall Clow (data(), size(), __s, __pos, traits_type::length(__s)); 529053d81ceSMarshall Clow } 530053d81ceSMarshall Clow 531053d81ceSMarshall Clow // rfind 532053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 533053d81ceSMarshall Clow size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT 534053d81ceSMarshall Clow { 535053d81ceSMarshall Clow _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); 536053d81ceSMarshall Clow return __str_rfind<value_type, size_type, traits_type, npos> 537053d81ceSMarshall Clow (data(), size(), __s.data(), __pos, __s.size()); 538053d81ceSMarshall Clow } 539053d81ceSMarshall Clow 540053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 541053d81ceSMarshall Clow size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT 542053d81ceSMarshall Clow { 543053d81ceSMarshall Clow return __str_rfind<value_type, size_type, traits_type, npos> 544053d81ceSMarshall Clow (data(), size(), __c, __pos); 545053d81ceSMarshall Clow } 546053d81ceSMarshall Clow 547053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 548dea74b28Szoecarver size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 549053d81ceSMarshall Clow { 550053d81ceSMarshall Clow _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr"); 551053d81ceSMarshall Clow return __str_rfind<value_type, size_type, traits_type, npos> 552053d81ceSMarshall Clow (data(), size(), __s, __pos, __n); 553053d81ceSMarshall Clow } 554053d81ceSMarshall Clow 555053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 556dea74b28Szoecarver size_type rfind(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT 557053d81ceSMarshall Clow { 558053d81ceSMarshall Clow _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr"); 559053d81ceSMarshall Clow return __str_rfind<value_type, size_type, traits_type, npos> 560053d81ceSMarshall Clow (data(), size(), __s, __pos, traits_type::length(__s)); 561053d81ceSMarshall Clow } 562053d81ceSMarshall Clow 563053d81ceSMarshall Clow // find_first_of 564053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 565053d81ceSMarshall Clow size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT 566053d81ceSMarshall Clow { 567053d81ceSMarshall Clow _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr"); 568053d81ceSMarshall Clow return __str_find_first_of<value_type, size_type, traits_type, npos> 569053d81ceSMarshall Clow (data(), size(), __s.data(), __pos, __s.size()); 570053d81ceSMarshall Clow } 571053d81ceSMarshall Clow 572053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 573053d81ceSMarshall Clow size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT 574053d81ceSMarshall Clow { return find(__c, __pos); } 575053d81ceSMarshall Clow 576053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 577dea74b28Szoecarver size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 578053d81ceSMarshall Clow { 579053d81ceSMarshall Clow _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr"); 580053d81ceSMarshall Clow return __str_find_first_of<value_type, size_type, traits_type, npos> 581053d81ceSMarshall Clow (data(), size(), __s, __pos, __n); 582053d81ceSMarshall Clow } 583053d81ceSMarshall Clow 584053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 585dea74b28Szoecarver size_type find_first_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT 586053d81ceSMarshall Clow { 587053d81ceSMarshall Clow _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr"); 588053d81ceSMarshall Clow return __str_find_first_of<value_type, size_type, traits_type, npos> 589053d81ceSMarshall Clow (data(), size(), __s, __pos, traits_type::length(__s)); 590053d81ceSMarshall Clow } 591053d81ceSMarshall Clow 592053d81ceSMarshall Clow // find_last_of 593053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 594053d81ceSMarshall Clow size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT 595053d81ceSMarshall Clow { 596053d81ceSMarshall Clow _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr"); 597053d81ceSMarshall Clow return __str_find_last_of<value_type, size_type, traits_type, npos> 598053d81ceSMarshall Clow (data(), size(), __s.data(), __pos, __s.size()); 599053d81ceSMarshall Clow } 600053d81ceSMarshall Clow 601053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 602053d81ceSMarshall Clow size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT 603053d81ceSMarshall Clow { return rfind(__c, __pos); } 604053d81ceSMarshall Clow 605053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 606dea74b28Szoecarver size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 607053d81ceSMarshall Clow { 608053d81ceSMarshall Clow _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr"); 609053d81ceSMarshall Clow return __str_find_last_of<value_type, size_type, traits_type, npos> 610053d81ceSMarshall Clow (data(), size(), __s, __pos, __n); 611053d81ceSMarshall Clow } 612053d81ceSMarshall Clow 613053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 614dea74b28Szoecarver size_type find_last_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT 615053d81ceSMarshall Clow { 616053d81ceSMarshall Clow _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr"); 617053d81ceSMarshall Clow return __str_find_last_of<value_type, size_type, traits_type, npos> 618053d81ceSMarshall Clow (data(), size(), __s, __pos, traits_type::length(__s)); 619053d81ceSMarshall Clow } 620053d81ceSMarshall Clow 621053d81ceSMarshall Clow // find_first_not_of 622053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 623053d81ceSMarshall Clow size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT 624053d81ceSMarshall Clow { 625053d81ceSMarshall Clow _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr"); 626053d81ceSMarshall Clow return __str_find_first_not_of<value_type, size_type, traits_type, npos> 627053d81ceSMarshall Clow (data(), size(), __s.data(), __pos, __s.size()); 628053d81ceSMarshall Clow } 629053d81ceSMarshall Clow 630053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 631053d81ceSMarshall Clow size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT 632053d81ceSMarshall Clow { 633053d81ceSMarshall Clow return __str_find_first_not_of<value_type, size_type, traits_type, npos> 634053d81ceSMarshall Clow (data(), size(), __c, __pos); 635053d81ceSMarshall Clow } 636053d81ceSMarshall Clow 637053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 638dea74b28Szoecarver size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 639053d81ceSMarshall Clow { 640053d81ceSMarshall Clow _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr"); 641053d81ceSMarshall Clow return __str_find_first_not_of<value_type, size_type, traits_type, npos> 642053d81ceSMarshall Clow (data(), size(), __s, __pos, __n); 643053d81ceSMarshall Clow } 644053d81ceSMarshall Clow 645053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 646dea74b28Szoecarver size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT 647053d81ceSMarshall Clow { 648053d81ceSMarshall Clow _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr"); 649053d81ceSMarshall Clow return __str_find_first_not_of<value_type, size_type, traits_type, npos> 650053d81ceSMarshall Clow (data(), size(), __s, __pos, traits_type::length(__s)); 651053d81ceSMarshall Clow } 652053d81ceSMarshall Clow 653053d81ceSMarshall Clow // find_last_not_of 654053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 655053d81ceSMarshall Clow size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT 656053d81ceSMarshall Clow { 657053d81ceSMarshall Clow _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr"); 658053d81ceSMarshall Clow return __str_find_last_not_of<value_type, size_type, traits_type, npos> 659053d81ceSMarshall Clow (data(), size(), __s.data(), __pos, __s.size()); 660053d81ceSMarshall Clow } 661053d81ceSMarshall Clow 662053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 663053d81ceSMarshall Clow size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT 664053d81ceSMarshall Clow { 665053d81ceSMarshall Clow return __str_find_last_not_of<value_type, size_type, traits_type, npos> 666053d81ceSMarshall Clow (data(), size(), __c, __pos); 667053d81ceSMarshall Clow } 668053d81ceSMarshall Clow 669053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 670dea74b28Szoecarver size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT 671053d81ceSMarshall Clow { 672053d81ceSMarshall Clow _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr"); 673053d81ceSMarshall Clow return __str_find_last_not_of<value_type, size_type, traits_type, npos> 674053d81ceSMarshall Clow (data(), size(), __s, __pos, __n); 675053d81ceSMarshall Clow } 676053d81ceSMarshall Clow 677053d81ceSMarshall Clow _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 678dea74b28Szoecarver size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT 679053d81ceSMarshall Clow { 680053d81ceSMarshall Clow _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr"); 681053d81ceSMarshall Clow return __str_find_last_not_of<value_type, size_type, traits_type, npos> 682053d81ceSMarshall Clow (data(), size(), __s, __pos, traits_type::length(__s)); 683053d81ceSMarshall Clow } 684053d81ceSMarshall Clow 685800259c9SMarshall Clow#if _LIBCPP_STD_VER > 17 686ae0e037fSArthur O'Dwyer constexpr _LIBCPP_INLINE_VISIBILITY 687ae0e037fSArthur O'Dwyer bool starts_with(basic_string_view __s) const noexcept 688800259c9SMarshall Clow { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; } 689800259c9SMarshall Clow 690ae0e037fSArthur O'Dwyer constexpr _LIBCPP_INLINE_VISIBILITY 691ae0e037fSArthur O'Dwyer bool starts_with(value_type __c) const noexcept 692800259c9SMarshall Clow { return !empty() && _Traits::eq(front(), __c); } 693800259c9SMarshall Clow 694ae0e037fSArthur O'Dwyer constexpr _LIBCPP_INLINE_VISIBILITY 695ae0e037fSArthur O'Dwyer bool starts_with(const value_type* __s) const noexcept 696800259c9SMarshall Clow { return starts_with(basic_string_view(__s)); } 697800259c9SMarshall Clow 698ae0e037fSArthur O'Dwyer constexpr _LIBCPP_INLINE_VISIBILITY 699ae0e037fSArthur O'Dwyer bool ends_with(basic_string_view __s) const noexcept 700800259c9SMarshall Clow { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; } 701800259c9SMarshall Clow 702ae0e037fSArthur O'Dwyer constexpr _LIBCPP_INLINE_VISIBILITY 703ae0e037fSArthur O'Dwyer bool ends_with(value_type __c) const noexcept 704800259c9SMarshall Clow { return !empty() && _Traits::eq(back(), __c); } 705800259c9SMarshall Clow 706ae0e037fSArthur O'Dwyer constexpr _LIBCPP_INLINE_VISIBILITY 707ae0e037fSArthur O'Dwyer bool ends_with(const value_type* __s) const noexcept 708800259c9SMarshall Clow { return ends_with(basic_string_view(__s)); } 709800259c9SMarshall Clow#endif 710800259c9SMarshall Clow 7116ac9cb2aSWim Leflere#if _LIBCPP_STD_VER > 20 7126ac9cb2aSWim Leflere constexpr _LIBCPP_INLINE_VISIBILITY 7136ac9cb2aSWim Leflere bool contains(basic_string_view __sv) const noexcept 7146ac9cb2aSWim Leflere { return find(__sv) != npos; } 7156ac9cb2aSWim Leflere 7166ac9cb2aSWim Leflere constexpr _LIBCPP_INLINE_VISIBILITY 7176ac9cb2aSWim Leflere bool contains(value_type __c) const noexcept 7186ac9cb2aSWim Leflere { return find(__c) != npos; } 7196ac9cb2aSWim Leflere 7206ac9cb2aSWim Leflere constexpr _LIBCPP_INLINE_VISIBILITY 7216ac9cb2aSWim Leflere bool contains(const value_type* __s) const 7226ac9cb2aSWim Leflere { return find(__s) != npos; } 7236ac9cb2aSWim Leflere#endif 7246ac9cb2aSWim Leflere 725053d81ceSMarshall Clowprivate: 726053d81ceSMarshall Clow const value_type* __data; 727053d81ceSMarshall Clow size_type __size; 728053d81ceSMarshall Clow}; 729053d81ceSMarshall Clow 730d2baefaeSJoe Loser#if _LIBCPP_STD_VER > 17 73101ace074SMark de Wevertemplate <class _CharT, class _Traits> 732462f8f06SChristopher Di Bellainline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true; 733462f8f06SChristopher Di Bella 734462f8f06SChristopher Di Bellatemplate <class _CharT, class _Traits> 73501ace074SMark de Weverinline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true; 736d2baefaeSJoe Loser#endif // _LIBCPP_STD_VER > 17 737053d81ceSMarshall Clow 7384be7f489SJoe Loser// [string.view.deduct] 7394be7f489SJoe Loser 740d2baefaeSJoe Loser#if _LIBCPP_STD_VER > 17 7414be7f489SJoe Losertemplate <contiguous_iterator _It, sized_sentinel_for<_It> _End> 7424be7f489SJoe Loser basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>; 743d2baefaeSJoe Loser#endif // _LIBCPP_STD_VER > 17 7444be7f489SJoe Loser 745c16b13ebSJoe Loser 746d2baefaeSJoe Loser#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 747c16b13ebSJoe Losertemplate <ranges::contiguous_range _Range> 748c16b13ebSJoe Loser basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>; 749d2baefaeSJoe Loser#endif // _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) 750c16b13ebSJoe Loser 751053d81ceSMarshall Clow// [string.view.comparison] 752053d81ceSMarshall Clow// operator == 753053d81ceSMarshall Clowtemplate<class _CharT, class _Traits> 754053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 755053d81ceSMarshall Clowbool operator==(basic_string_view<_CharT, _Traits> __lhs, 756053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __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 Loser// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details. 763c16b13ebSJoe Loser// This applies to the other sufficient overloads below for the other comparison operators. 764c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 1> 765053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 766053d81ceSMarshall Clowbool operator==(basic_string_view<_CharT, _Traits> __lhs, 767053d81ceSMarshall Clow typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT 768053d81ceSMarshall Clow{ 769053d81ceSMarshall Clow if ( __lhs.size() != __rhs.size()) return false; 770053d81ceSMarshall Clow return __lhs.compare(__rhs) == 0; 771053d81ceSMarshall Clow} 772053d81ceSMarshall Clow 773c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 2> 774053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 775053d81ceSMarshall Clowbool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 776053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 777053d81ceSMarshall Clow{ 778053d81ceSMarshall Clow if ( __lhs.size() != __rhs.size()) return false; 779053d81ceSMarshall Clow return __lhs.compare(__rhs) == 0; 780053d81ceSMarshall Clow} 781053d81ceSMarshall Clow 782053d81ceSMarshall Clow 783053d81ceSMarshall Clow// operator != 784053d81ceSMarshall Clowtemplate<class _CharT, class _Traits> 785053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 786053d81ceSMarshall Clowbool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 787053d81ceSMarshall Clow{ 788053d81ceSMarshall Clow if ( __lhs.size() != __rhs.size()) 789053d81ceSMarshall Clow return true; 790053d81ceSMarshall Clow return __lhs.compare(__rhs) != 0; 791053d81ceSMarshall Clow} 792053d81ceSMarshall Clow 793c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 1> 794053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 795053d81ceSMarshall Clowbool operator!=(basic_string_view<_CharT, _Traits> __lhs, 796053d81ceSMarshall Clow typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT 797053d81ceSMarshall Clow{ 798053d81ceSMarshall Clow if ( __lhs.size() != __rhs.size()) 799053d81ceSMarshall Clow return true; 800053d81ceSMarshall Clow return __lhs.compare(__rhs) != 0; 801053d81ceSMarshall Clow} 802053d81ceSMarshall Clow 803c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 2> 804053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 805053d81ceSMarshall Clowbool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 806053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 807053d81ceSMarshall Clow{ 808053d81ceSMarshall Clow if ( __lhs.size() != __rhs.size()) 809053d81ceSMarshall Clow return true; 810053d81ceSMarshall Clow return __lhs.compare(__rhs) != 0; 811053d81ceSMarshall Clow} 812053d81ceSMarshall Clow 813053d81ceSMarshall Clow 814053d81ceSMarshall Clow// operator < 815053d81ceSMarshall Clowtemplate<class _CharT, class _Traits> 816053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 817053d81ceSMarshall Clowbool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 818053d81ceSMarshall Clow{ 819053d81ceSMarshall Clow return __lhs.compare(__rhs) < 0; 820053d81ceSMarshall Clow} 821053d81ceSMarshall Clow 822c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 1> 823053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 824053d81ceSMarshall Clowbool operator<(basic_string_view<_CharT, _Traits> __lhs, 825053d81ceSMarshall Clow typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT 826053d81ceSMarshall Clow{ 827053d81ceSMarshall Clow return __lhs.compare(__rhs) < 0; 828053d81ceSMarshall Clow} 829053d81ceSMarshall Clow 830c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 2> 831053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 832053d81ceSMarshall Clowbool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 833053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 834053d81ceSMarshall Clow{ 835053d81ceSMarshall Clow return __lhs.compare(__rhs) < 0; 836053d81ceSMarshall Clow} 837053d81ceSMarshall Clow 838053d81ceSMarshall Clow 839053d81ceSMarshall Clow// operator > 840053d81ceSMarshall Clowtemplate<class _CharT, class _Traits> 841053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 842053d81ceSMarshall Clowbool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 843053d81ceSMarshall Clow{ 844053d81ceSMarshall Clow return __lhs.compare(__rhs) > 0; 845053d81ceSMarshall Clow} 846053d81ceSMarshall Clow 847c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 1> 848053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 849053d81ceSMarshall Clowbool operator>(basic_string_view<_CharT, _Traits> __lhs, 850053d81ceSMarshall Clow typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT 851053d81ceSMarshall Clow{ 852053d81ceSMarshall Clow return __lhs.compare(__rhs) > 0; 853053d81ceSMarshall Clow} 854053d81ceSMarshall Clow 855c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 2> 856053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 857053d81ceSMarshall Clowbool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 858053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 859053d81ceSMarshall Clow{ 860053d81ceSMarshall Clow return __lhs.compare(__rhs) > 0; 861053d81ceSMarshall Clow} 862053d81ceSMarshall Clow 863053d81ceSMarshall Clow 864053d81ceSMarshall Clow// operator <= 865053d81ceSMarshall Clowtemplate<class _CharT, class _Traits> 866053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 867053d81ceSMarshall Clowbool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 868053d81ceSMarshall Clow{ 869053d81ceSMarshall Clow return __lhs.compare(__rhs) <= 0; 870053d81ceSMarshall Clow} 871053d81ceSMarshall Clow 872c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 1> 873053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 874053d81ceSMarshall Clowbool operator<=(basic_string_view<_CharT, _Traits> __lhs, 875053d81ceSMarshall Clow typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT 876053d81ceSMarshall Clow{ 877053d81ceSMarshall Clow return __lhs.compare(__rhs) <= 0; 878053d81ceSMarshall Clow} 879053d81ceSMarshall Clow 880c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 2> 881053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 882053d81ceSMarshall Clowbool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 883053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 884053d81ceSMarshall Clow{ 885053d81ceSMarshall Clow return __lhs.compare(__rhs) <= 0; 886053d81ceSMarshall Clow} 887053d81ceSMarshall Clow 888053d81ceSMarshall Clow 889053d81ceSMarshall Clow// operator >= 890053d81ceSMarshall Clowtemplate<class _CharT, class _Traits> 891053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 892053d81ceSMarshall Clowbool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 893053d81ceSMarshall Clow{ 894053d81ceSMarshall Clow return __lhs.compare(__rhs) >= 0; 895053d81ceSMarshall Clow} 896053d81ceSMarshall Clow 897053d81ceSMarshall Clow 898c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 1> 899053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 900053d81ceSMarshall Clowbool operator>=(basic_string_view<_CharT, _Traits> __lhs, 901053d81ceSMarshall Clow typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT 902053d81ceSMarshall Clow{ 903053d81ceSMarshall Clow return __lhs.compare(__rhs) >= 0; 904053d81ceSMarshall Clow} 905053d81ceSMarshall Clow 906c16b13ebSJoe Losertemplate<class _CharT, class _Traits, int = 2> 907053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 908053d81ceSMarshall Clowbool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs, 909053d81ceSMarshall Clow basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT 910053d81ceSMarshall Clow{ 911053d81ceSMarshall Clow return __lhs.compare(__rhs) >= 0; 912053d81ceSMarshall Clow} 913053d81ceSMarshall Clow 914af4a29afSEric Fiselier 915af4a29afSEric Fiseliertemplate<class _CharT, class _Traits> 916af4a29afSEric Fiselierbasic_ostream<_CharT, _Traits>& 917af4a29afSEric Fiselieroperator<<(basic_ostream<_CharT, _Traits>& __os, 918af4a29afSEric Fiselier basic_string_view<_CharT, _Traits> __str); 919af4a29afSEric Fiselier 920053d81ceSMarshall Clow// [string.view.hash] 92193184302SMarshall Clowtemplate<class _CharT> 92293184302SMarshall Clowstruct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, char_traits<_CharT> > > 923681cde7dSNikolas Klauser : public __unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t> 924053d81ceSMarshall Clow{ 925a86710f1SLouis Dionne _LIBCPP_INLINE_VISIBILITY 92693184302SMarshall Clow size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT { 927053d81ceSMarshall Clow return __do_string_hash(__val.data(), __val.data() + __val.size()); 928053d81ceSMarshall Clow } 929a86710f1SLouis Dionne}; 930053d81ceSMarshall Clow 9318fd58a6bSMarshall Clow#if _LIBCPP_STD_VER > 11 9328fd58a6bSMarshall Clowinline namespace literals 9338fd58a6bSMarshall Clow{ 9348fd58a6bSMarshall Clow inline namespace string_view_literals 9358fd58a6bSMarshall Clow { 9368fd58a6bSMarshall Clow inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 93759b48302SMarshall Clow basic_string_view<char> operator "" sv(const char *__str, size_t __len) _NOEXCEPT 9388fd58a6bSMarshall Clow { 9398fd58a6bSMarshall Clow return basic_string_view<char> (__str, __len); 9408fd58a6bSMarshall Clow } 9418fd58a6bSMarshall Clow 942f4c1258dSLouis Dionne#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS 9438fd58a6bSMarshall Clow inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 94459b48302SMarshall Clow basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT 9458fd58a6bSMarshall Clow { 9468fd58a6bSMarshall Clow return basic_string_view<wchar_t> (__str, __len); 9478fd58a6bSMarshall Clow } 948f4c1258dSLouis Dionne#endif 9498fd58a6bSMarshall Clow 9505c40c994SArthur O'Dwyer#ifndef _LIBCPP_HAS_NO_CHAR8_T 9517dad0bd6SMarshall Clow inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 9527dad0bd6SMarshall Clow basic_string_view<char8_t> operator "" sv(const char8_t *__str, size_t __len) _NOEXCEPT 9537dad0bd6SMarshall Clow { 9547dad0bd6SMarshall Clow return basic_string_view<char8_t> (__str, __len); 9557dad0bd6SMarshall Clow } 9567dad0bd6SMarshall Clow#endif 9577dad0bd6SMarshall Clow 9588fd58a6bSMarshall Clow inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 95959b48302SMarshall Clow basic_string_view<char16_t> operator "" sv(const char16_t *__str, size_t __len) _NOEXCEPT 9608fd58a6bSMarshall Clow { 9618fd58a6bSMarshall Clow return basic_string_view<char16_t> (__str, __len); 9628fd58a6bSMarshall Clow } 9638fd58a6bSMarshall Clow 9648fd58a6bSMarshall Clow inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR 96559b48302SMarshall Clow basic_string_view<char32_t> operator "" sv(const char32_t *__str, size_t __len) _NOEXCEPT 9668fd58a6bSMarshall Clow { 9678fd58a6bSMarshall Clow return basic_string_view<char32_t> (__str, __len); 9688fd58a6bSMarshall Clow } 969d2b0df35SNikolas Klauser } // namespace string_view_literals 970d2b0df35SNikolas Klauser} // namespace literals 9718fd58a6bSMarshall Clow#endif 972053d81ceSMarshall Clow_LIBCPP_END_NAMESPACE_STD 973053d81ceSMarshall Clow 974a016efb1SEric Fiselier_LIBCPP_POP_MACROS 975a016efb1SEric Fiselier 976053d81ceSMarshall Clow#endif // _LIBCPP_STRING_VIEW 977