blob: eb5d25437e055aef53322435530753c1f49f4e8a [file] [log] [blame]
Marshall Clowdf63a6d2016-07-21 05:31:24 +00001// -*- C++ -*-
Louis Dionne9bd93882021-11-17 16:25:01 -05002//===----------------------------------------------------------------------===//
Marshall Clowdf63a6d2016-07-21 05:31:24 +00003//
Chandler Carruth7642bb12019-01-19 08:50:56 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Marshall Clowdf63a6d2016-07-21 05:31:24 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_STRING_VIEW
11#define _LIBCPP_STRING_VIEW
12
13/*
14string_view synopsis
15
16namespace std {
17
18 // 7.2, Class template basic_string_view
19 template<class charT, class traits = char_traits<charT>>
20 class basic_string_view;
21
Mark de Weveraf59b2d2020-11-24 18:08:02 +010022 template<class charT, class traits>
Christopher Di Bella92072c22021-05-14 06:20:07 +000023 inline constexpr bool ranges::enable_view<basic_string_view<charT, traits>> = true;
24
25 template<class charT, class traits>
Mark de Weveraf59b2d2020-11-24 18:08:02 +010026 inline constexpr bool ranges::enable_borrowed_range<basic_string_view<charT, traits>> = true; // C++20
27
Marshall Clowdf63a6d2016-07-21 05:31:24 +000028 // 7.9, basic_string_view non-member comparison functions
29 template<class charT, class traits>
30 constexpr bool operator==(basic_string_view<charT, traits> x,
31 basic_string_view<charT, traits> y) noexcept;
32 template<class charT, class traits>
33 constexpr bool operator!=(basic_string_view<charT, traits> x,
34 basic_string_view<charT, traits> y) noexcept;
35 template<class charT, class traits>
36 constexpr bool operator< (basic_string_view<charT, traits> x,
37 basic_string_view<charT, traits> y) noexcept;
38 template<class charT, class traits>
39 constexpr bool operator> (basic_string_view<charT, traits> x,
40 basic_string_view<charT, traits> y) noexcept;
41 template<class charT, class traits>
42 constexpr bool operator<=(basic_string_view<charT, traits> x,
43 basic_string_view<charT, traits> y) noexcept;
44 template<class charT, class traits>
45 constexpr bool operator>=(basic_string_view<charT, traits> x,
46 basic_string_view<charT, traits> y) noexcept;
47 // see below, sufficient additional overloads of comparison functions
48
49 // 7.10, Inserters and extractors
50 template<class charT, class traits>
51 basic_ostream<charT, traits>&
52 operator<<(basic_ostream<charT, traits>& os,
53 basic_string_view<charT, traits> str);
54
55 // basic_string_view typedef names
56 typedef basic_string_view<char> string_view;
Marek Kurdeje3ac4e22021-03-23 17:15:07 +010057 typedef basic_string_view<char8_t> u8string_view; // C++20
Marshall Clowdf63a6d2016-07-21 05:31:24 +000058 typedef basic_string_view<char16_t> u16string_view;
59 typedef basic_string_view<char32_t> u32string_view;
60 typedef basic_string_view<wchar_t> wstring_view;
61
62 template<class charT, class traits = char_traits<charT>>
63 class basic_string_view {
64 public:
65 // types
66 typedef traits traits_type;
67 typedef charT value_type;
68 typedef charT* pointer;
69 typedef const charT* const_pointer;
70 typedef charT& reference;
71 typedef const charT& const_reference;
72 typedef implementation-defined const_iterator;
73 typedef const_iterator iterator;
74 typedef reverse_iterator<const_iterator> const_reverse_iterator;
75 typedef const_reverse_iterator reverse_iterator;
76 typedef size_t size_type;
77 typedef ptrdiff_t difference_type;
78 static constexpr size_type npos = size_type(-1);
79
80 // 7.3, basic_string_view constructors and assignment operators
81 constexpr basic_string_view() noexcept;
82 constexpr basic_string_view(const basic_string_view&) noexcept = default;
83 basic_string_view& operator=(const basic_string_view&) noexcept = default;
84 template<class Allocator>
85 constexpr basic_string_view(const charT* str);
Marek Kurdej90d79712021-07-27 16:16:21 +020086 basic_string_view(nullptr_t) = delete; // C++2b
Marshall Clowdf63a6d2016-07-21 05:31:24 +000087 constexpr basic_string_view(const charT* str, size_type len);
Joe Loser28dcceb2021-10-06 14:17:02 -040088 template <class It, class End>
89 constexpr basic_string_view(It begin, End end); // C++20
Joe Loser1cf8cae2021-11-03 18:45:04 -040090 template <class Range>
91 constexpr basic_string_view(Range&& r); // C++23
Marshall Clowdf63a6d2016-07-21 05:31:24 +000092
93 // 7.4, basic_string_view iterator support
94 constexpr const_iterator begin() const noexcept;
95 constexpr const_iterator end() const noexcept;
96 constexpr const_iterator cbegin() const noexcept;
97 constexpr const_iterator cend() const noexcept;
98 const_reverse_iterator rbegin() const noexcept;
99 const_reverse_iterator rend() const noexcept;
100 const_reverse_iterator crbegin() const noexcept;
101 const_reverse_iterator crend() const noexcept;
102
103 // 7.5, basic_string_view capacity
104 constexpr size_type size() const noexcept;
105 constexpr size_type length() const noexcept;
106 constexpr size_type max_size() const noexcept;
107 constexpr bool empty() const noexcept;
108
109 // 7.6, basic_string_view element access
110 constexpr const_reference operator[](size_type pos) const;
111 constexpr const_reference at(size_type pos) const;
112 constexpr const_reference front() const;
113 constexpr const_reference back() const;
114 constexpr const_pointer data() const noexcept;
115
116 // 7.7, basic_string_view modifiers
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000117 constexpr void remove_prefix(size_type n);
118 constexpr void remove_suffix(size_type n);
119 constexpr void swap(basic_string_view& s) noexcept;
120
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500121 size_type copy(charT* s, size_type n, size_type pos = 0) const; // constexpr in C++20
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000122
123 constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
124 constexpr int compare(basic_string_view s) const noexcept;
125 constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
126 constexpr int compare(size_type pos1, size_type n1,
127 basic_string_view s, size_type pos2, size_type n2) const;
128 constexpr int compare(const charT* s) const;
129 constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
130 constexpr int compare(size_type pos1, size_type n1,
131 const charT* s, size_type n2) const;
132 constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
133 constexpr size_type find(charT c, size_type pos = 0) const noexcept;
zoecarver1997e0a2021-02-05 11:54:47 -0800134 constexpr size_type find(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
135 constexpr size_type find(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000136 constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
137 constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
zoecarver1997e0a2021-02-05 11:54:47 -0800138 constexpr size_type rfind(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
139 constexpr size_type rfind(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000140 constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
141 constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
zoecarver1997e0a2021-02-05 11:54:47 -0800142 constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
143 constexpr size_type find_first_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000144 constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
145 constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
zoecarver1997e0a2021-02-05 11:54:47 -0800146 constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
147 constexpr size_type find_last_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000148 constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
149 constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
zoecarver1997e0a2021-02-05 11:54:47 -0800150 constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
151 constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const noexcept; // noexcept as an extension
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000152 constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
153 constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
zoecarver1997e0a2021-02-05 11:54:47 -0800154 constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const noexcept; // noexcept as an extension
155 constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const noexcept; // noexcept as an extension
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000156
Marek Kurdej24b4c512021-01-07 12:29:04 +0100157 constexpr bool starts_with(basic_string_view s) const noexcept; // C++20
158 constexpr bool starts_with(charT c) const noexcept; // C++20
159 constexpr bool starts_with(const charT* s) const; // C++20
160 constexpr bool ends_with(basic_string_view s) const noexcept; // C++20
161 constexpr bool ends_with(charT c) const noexcept; // C++20
162 constexpr bool ends_with(const charT* s) const; // C++20
Marshall Clow18c293b2017-12-04 20:11:38 +0000163
Wim Leflere023c3542021-01-19 14:33:30 -0500164 constexpr bool contains(basic_string_view s) const noexcept; // C++2b
165 constexpr bool contains(charT c) const noexcept; // C++2b
166 constexpr bool contains(const charT* s) const; // C++2b
167
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000168 private:
169 const_pointer data_; // exposition only
170 size_type size_; // exposition only
171 };
172
Joe Loser28dcceb2021-10-06 14:17:02 -0400173 // basic_string_view deduction guides
174 template<class It, class End>
175 basic_string_view(It, End) -> basic_string_view<iter_value_t<It>>; // C++20
Joe Loser1cf8cae2021-11-03 18:45:04 -0400176 template<class Range>
177 basic_string_view(Range&&) -> basic_string_view<ranges::range_value_t<Range>>; // C++23
Joe Loser28dcceb2021-10-06 14:17:02 -0400178
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000179 // 7.11, Hash support
180 template <class T> struct hash;
181 template <> struct hash<string_view>;
Marek Kurdeje3ac4e22021-03-23 17:15:07 +0100182 template <> struct hash<u8string_view>; // C++20
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000183 template <> struct hash<u16string_view>;
184 template <> struct hash<u32string_view>;
185 template <> struct hash<wstring_view>;
186
Marshall Clowabe6daf2017-10-24 14:06:00 +0000187 constexpr basic_string_view<char> operator "" sv( const char *str, size_t len ) noexcept;
188 constexpr basic_string_view<wchar_t> operator "" sv( const wchar_t *str, size_t len ) noexcept;
Marek Kurdeje3ac4e22021-03-23 17:15:07 +0100189 constexpr basic_string_view<char8_t> operator "" sv( const char8_t *str, size_t len ) noexcept; // C++20
Marshall Clowabe6daf2017-10-24 14:06:00 +0000190 constexpr basic_string_view<char16_t> operator "" sv( const char16_t *str, size_t len ) noexcept;
191 constexpr basic_string_view<char32_t> operator "" sv( const char32_t *str, size_t len ) noexcept;
Marshall Clow27c8a4c2017-01-09 18:07:34 +0000192
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000193} // namespace std
194
195
196*/
197
198#include <__config>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400199#include <__debug>
Joe Loser1cf8cae2021-11-03 18:45:04 -0400200#include <__ranges/concepts.h>
201#include <__ranges/data.h>
Mark de Weveraf59b2d2020-11-24 18:08:02 +0100202#include <__ranges/enable_borrowed_range.h>
Christopher Di Bella92072c22021-05-14 06:20:07 +0000203#include <__ranges/enable_view.h>
Joe Loser1cf8cae2021-11-03 18:45:04 -0400204#include <__ranges/size.h>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000205#include <__string>
Eric Fiselier2d357f72016-12-05 23:53:23 +0000206#include <algorithm>
Arthur O'Dwyer7deec122021-03-24 18:19:12 -0400207#include <compare>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400208#include <iosfwd>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000209#include <iterator>
Eric Fiselier2d357f72016-12-05 23:53:23 +0000210#include <limits>
211#include <stdexcept>
Joe Loser1cf8cae2021-11-03 18:45:04 -0400212#include <type_traits>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000213#include <version>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000214
215#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Arthur O'Dwyer6eeaa002022-02-01 20:16:40 -0500216# pragma GCC system_header
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000217#endif
218
Eric Fiselierf4433a32017-05-31 22:07:49 +0000219_LIBCPP_PUSH_MACROS
220#include <__undef_macros>
221
222
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000223_LIBCPP_BEGIN_NAMESPACE_STD
224
225template<class _CharT, class _Traits = char_traits<_CharT> >
Richard Smith256954d2020-11-11 17:12:18 -0800226 class _LIBCPP_TEMPLATE_VIS basic_string_view;
227
228typedef basic_string_view<char> string_view;
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -0400229#ifndef _LIBCPP_HAS_NO_CHAR8_T
Richard Smith256954d2020-11-11 17:12:18 -0800230typedef basic_string_view<char8_t> u8string_view;
231#endif
232typedef basic_string_view<char16_t> u16string_view;
233typedef basic_string_view<char32_t> u32string_view;
Louis Dionne89258142021-08-23 15:32:36 -0400234#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Richard Smith256954d2020-11-11 17:12:18 -0800235typedef basic_string_view<wchar_t> wstring_view;
Louis Dionne89258142021-08-23 15:32:36 -0400236#endif
Richard Smith256954d2020-11-11 17:12:18 -0800237
238template<class _CharT, class _Traits>
239class
240 _LIBCPP_PREFERRED_NAME(string_view)
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -0400241#ifndef _LIBCPP_HAS_NO_CHAR8_T
Richard Smith256954d2020-11-11 17:12:18 -0800242 _LIBCPP_PREFERRED_NAME(u8string_view)
243#endif
244 _LIBCPP_PREFERRED_NAME(u16string_view)
245 _LIBCPP_PREFERRED_NAME(u32string_view)
Louis Dionne89258142021-08-23 15:32:36 -0400246 _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wstring_view))
Richard Smith256954d2020-11-11 17:12:18 -0800247 basic_string_view {
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000248public:
Marshall Clowb7db4972017-11-15 20:02:27 +0000249 // types
250 typedef _Traits traits_type;
251 typedef _CharT value_type;
Marshall Clow7d2c5182017-12-20 16:31:40 +0000252 typedef _CharT* pointer;
Marshall Clowb7db4972017-11-15 20:02:27 +0000253 typedef const _CharT* const_pointer;
Marshall Clow7d2c5182017-12-20 16:31:40 +0000254 typedef _CharT& reference;
Marshall Clowb7db4972017-11-15 20:02:27 +0000255 typedef const _CharT& const_reference;
256 typedef const_pointer const_iterator; // See [string.view.iterators]
257 typedef const_iterator iterator;
258 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
259 typedef const_reverse_iterator reverse_iterator;
260 typedef size_t size_type;
261 typedef ptrdiff_t difference_type;
262 static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000263
Marshall Clow79f33542018-03-21 00:36:05 +0000264 static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array");
265 static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout");
266 static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial");
Marshall Clowa3a74e02017-03-15 18:41:11 +0000267 static_assert((is_same<_CharT, typename traits_type::char_type>::value),
268 "traits_type::char_type must be the same type as CharT");
269
Marshall Clowb7db4972017-11-15 20:02:27 +0000270 // [string.view.cons], construct/copy
271 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
272 basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {}
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000273
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -0400274 _LIBCPP_INLINE_VISIBILITY
Marshall Clowb7db4972017-11-15 20:02:27 +0000275 basic_string_view(const basic_string_view&) _NOEXCEPT = default;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000276
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -0400277 _LIBCPP_INLINE_VISIBILITY
Marshall Clowb7db4972017-11-15 20:02:27 +0000278 basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000279
Marshall Clowb7db4972017-11-15 20:02:27 +0000280 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
281 basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
282 : __data(__s), __size(__len)
283 {
Marshall Clowca1bcdb2019-06-04 02:07:11 +0000284#if _LIBCPP_STD_VER > 11
285 _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
286#endif
Marshall Clowb7db4972017-11-15 20:02:27 +0000287 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000288
Arthur O'Dwyerfe74c902022-02-01 19:59:37 -0500289#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
Joe Loser28dcceb2021-10-06 14:17:02 -0400290 template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
Joe Loserf9dfe432021-11-24 15:35:15 -0500291 requires (is_same_v<iter_value_t<_It>, _CharT> && !is_convertible_v<_End, size_type>)
Joe Loser28dcceb2021-10-06 14:17:02 -0400292 constexpr _LIBCPP_HIDE_FROM_ABI basic_string_view(_It __begin, _End __end)
293 : __data(_VSTD::to_address(__begin)), __size(__end - __begin)
294 {
295 _LIBCPP_ASSERT((__end - __begin) >= 0, "std::string_view::string_view(iterator, sentinel) received invalid range");
296 }
297#endif
298
Arthur O'Dwyer654b4db2022-01-31 12:04:08 -0500299#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
Joe Loser1cf8cae2021-11-03 18:45:04 -0400300 template <class _Range>
301 requires (
302 !is_same_v<remove_cvref_t<_Range>, basic_string_view> &&
303 ranges::contiguous_range<_Range> &&
304 ranges::sized_range<_Range> &&
305 is_same_v<ranges::range_value_t<_Range>, _CharT> &&
306 !is_convertible_v<_Range, const _CharT*> &&
307 (!requires(remove_cvref_t<_Range>& d) {
308 d.operator _VSTD::basic_string_view<_CharT, _Traits>();
309 }) &&
310 (!requires {
311 typename remove_reference_t<_Range>::traits_type;
312 } || is_same_v<typename remove_reference_t<_Range>::traits_type, _Traits>)
313 )
314 constexpr _LIBCPP_HIDE_FROM_ABI
315 basic_string_view(_Range&& __r) : __data(ranges::data(__r)), __size(ranges::size(__r)) {}
316#endif
317
Marshall Clowb7db4972017-11-15 20:02:27 +0000318 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
319 basic_string_view(const _CharT* __s)
Arthur O'Dwyer07b22492020-11-27 11:02:06 -0500320 : __data(__s), __size(_VSTD::__char_traits_length_checked<_Traits>(__s)) {}
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000321
Marek Kurdej90d79712021-07-27 16:16:21 +0200322#if _LIBCPP_STD_VER > 20
323 basic_string_view(nullptr_t) = delete;
324#endif
325
Marshall Clowb7db4972017-11-15 20:02:27 +0000326 // [string.view.iterators], iterators
327 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
328 const_iterator begin() const _NOEXCEPT { return cbegin(); }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000329
Marshall Clowb7db4972017-11-15 20:02:27 +0000330 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
331 const_iterator end() const _NOEXCEPT { return cend(); }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000332
Marshall Clowb7db4972017-11-15 20:02:27 +0000333 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
334 const_iterator cbegin() const _NOEXCEPT { return __data; }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000335
Marshall Clowb7db4972017-11-15 20:02:27 +0000336 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
337 const_iterator cend() const _NOEXCEPT { return __data + __size; }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000338
Marshall Clowb7db4972017-11-15 20:02:27 +0000339 _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
340 const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000341
Marshall Clowb7db4972017-11-15 20:02:27 +0000342 _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
343 const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000344
Marshall Clowb7db4972017-11-15 20:02:27 +0000345 _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
346 const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000347
Marshall Clowb7db4972017-11-15 20:02:27 +0000348 _LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
349 const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000350
Marshall Clowb7db4972017-11-15 20:02:27 +0000351 // [string.view.capacity], capacity
352 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
353 size_type size() const _NOEXCEPT { return __size; }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000354
Marshall Clowb7db4972017-11-15 20:02:27 +0000355 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
356 size_type length() const _NOEXCEPT { return __size; }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000357
Marshall Clowb7db4972017-11-15 20:02:27 +0000358 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
Louis Dionne8542a4c2021-11-22 16:44:50 -0500359 size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max() / sizeof(value_type); }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000360
Marshall Clowb7db4972017-11-15 20:02:27 +0000361 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
362 bool empty() const _NOEXCEPT { return __size == 0; }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000363
Marshall Clowb7db4972017-11-15 20:02:27 +0000364 // [string.view.access], element access
365 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
Chris Palmer1b114a52020-10-06 13:01:50 -0400366 const_reference operator[](size_type __pos) const _NOEXCEPT {
367 return _LIBCPP_ASSERT(__pos < size(), "string_view[] index out of bounds"), __data[__pos];
368 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000369
Marshall Clowb7db4972017-11-15 20:02:27 +0000370 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
371 const_reference at(size_type __pos) const
372 {
373 return __pos >= size()
374 ? (__throw_out_of_range("string_view::at"), __data[0])
375 : __data[__pos];
376 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000377
Marshall Clowb7db4972017-11-15 20:02:27 +0000378 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
Marshall Clow05cf6692019-03-19 03:30:07 +0000379 const_reference front() const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000380 {
381 return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0];
382 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000383
Marshall Clowb7db4972017-11-15 20:02:27 +0000384 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
Marshall Clow05cf6692019-03-19 03:30:07 +0000385 const_reference back() const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000386 {
387 return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1];
388 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000389
Marshall Clowb7db4972017-11-15 20:02:27 +0000390 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
391 const_pointer data() const _NOEXCEPT { return __data; }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000392
Marshall Clowb7db4972017-11-15 20:02:27 +0000393 // [string.view.modifiers], modifiers:
394 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
395 void remove_prefix(size_type __n) _NOEXCEPT
396 {
397 _LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()");
398 __data += __n;
399 __size -= __n;
400 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000401
Marshall Clowb7db4972017-11-15 20:02:27 +0000402 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
403 void remove_suffix(size_type __n) _NOEXCEPT
404 {
405 _LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()");
406 __size -= __n;
407 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000408
Marshall Clowb7db4972017-11-15 20:02:27 +0000409 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
410 void swap(basic_string_view& __other) _NOEXCEPT
411 {
412 const value_type *__p = __data;
413 __data = __other.__data;
414 __other.__data = __p;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000415
Marshall Clowb7db4972017-11-15 20:02:27 +0000416 size_type __sz = __size;
417 __size = __other.__size;
418 __other.__size = __sz;
419 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000420
Arthur O'Dwyer20638cc2021-02-09 19:12:16 -0500421 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowb7db4972017-11-15 20:02:27 +0000422 size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const
423 {
424 if (__pos > size())
425 __throw_out_of_range("string_view::copy");
426 size_type __rlen = _VSTD::min(__n, size() - __pos);
427 _Traits::copy(__s, data() + __pos, __rlen);
428 return __rlen;
429 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000430
Marshall Clowb7db4972017-11-15 20:02:27 +0000431 _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
432 basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
433 {
434 return __pos > size()
435 ? (__throw_out_of_range("string_view::substr"), basic_string_view())
436 : basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos));
437 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000438
Marshall Clowb7db4972017-11-15 20:02:27 +0000439 _LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT
440 {
441 size_type __rlen = _VSTD::min( size(), __sv.size());
442 int __retval = _Traits::compare(data(), __sv.data(), __rlen);
443 if ( __retval == 0 ) // first __rlen chars matched
444 __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 );
445 return __retval;
446 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000447
Marshall Clowb7db4972017-11-15 20:02:27 +0000448 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
449 int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const
450 {
451 return substr(__pos1, __n1).compare(__sv);
452 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000453
Marshall Clowb7db4972017-11-15 20:02:27 +0000454 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Louis Dionne173f29e2019-05-29 16:01:36 +0000455 int compare( size_type __pos1, size_type __n1,
Marshall Clowb7db4972017-11-15 20:02:27 +0000456 basic_string_view __sv, size_type __pos2, size_type __n2) const
457 {
458 return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
459 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000460
Marshall Clowb7db4972017-11-15 20:02:27 +0000461 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
462 int compare(const _CharT* __s) const _NOEXCEPT
463 {
464 return compare(basic_string_view(__s));
465 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000466
Marshall Clowb7db4972017-11-15 20:02:27 +0000467 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
468 int compare(size_type __pos1, size_type __n1, const _CharT* __s) const
469 {
470 return substr(__pos1, __n1).compare(basic_string_view(__s));
471 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000472
Marshall Clowb7db4972017-11-15 20:02:27 +0000473 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
474 int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
475 {
476 return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
477 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000478
Marshall Clowb7db4972017-11-15 20:02:27 +0000479 // find
480 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
481 size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
482 {
483 _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
484 return __str_find<value_type, size_type, traits_type, npos>
485 (data(), size(), __s.data(), __pos, __s.size());
486 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000487
Marshall Clowb7db4972017-11-15 20:02:27 +0000488 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
489 size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT
490 {
491 return __str_find<value_type, size_type, traits_type, npos>
492 (data(), size(), __c, __pos);
493 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000494
Marshall Clowb7db4972017-11-15 20:02:27 +0000495 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
zoecarver1997e0a2021-02-05 11:54:47 -0800496 size_type find(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000497 {
498 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
499 return __str_find<value_type, size_type, traits_type, npos>
500 (data(), size(), __s, __pos, __n);
501 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000502
Marshall Clowb7db4972017-11-15 20:02:27 +0000503 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
zoecarver1997e0a2021-02-05 11:54:47 -0800504 size_type find(const _CharT* __s, size_type __pos = 0) const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000505 {
506 _LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr");
507 return __str_find<value_type, size_type, traits_type, npos>
508 (data(), size(), __s, __pos, traits_type::length(__s));
509 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000510
Marshall Clowb7db4972017-11-15 20:02:27 +0000511 // rfind
512 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
513 size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT
514 {
515 _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
516 return __str_rfind<value_type, size_type, traits_type, npos>
517 (data(), size(), __s.data(), __pos, __s.size());
518 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000519
Marshall Clowb7db4972017-11-15 20:02:27 +0000520 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
521 size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT
522 {
523 return __str_rfind<value_type, size_type, traits_type, npos>
524 (data(), size(), __c, __pos);
525 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000526
Marshall Clowb7db4972017-11-15 20:02:27 +0000527 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
zoecarver1997e0a2021-02-05 11:54:47 -0800528 size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000529 {
530 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
531 return __str_rfind<value_type, size_type, traits_type, npos>
532 (data(), size(), __s, __pos, __n);
533 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000534
Marshall Clowb7db4972017-11-15 20:02:27 +0000535 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
zoecarver1997e0a2021-02-05 11:54:47 -0800536 size_type rfind(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000537 {
538 _LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr");
539 return __str_rfind<value_type, size_type, traits_type, npos>
540 (data(), size(), __s, __pos, traits_type::length(__s));
541 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000542
Marshall Clowb7db4972017-11-15 20:02:27 +0000543 // find_first_of
544 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
545 size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
546 {
547 _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
548 return __str_find_first_of<value_type, size_type, traits_type, npos>
549 (data(), size(), __s.data(), __pos, __s.size());
550 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000551
Marshall Clowb7db4972017-11-15 20:02:27 +0000552 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
553 size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT
554 { return find(__c, __pos); }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000555
Marshall Clowb7db4972017-11-15 20:02:27 +0000556 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
zoecarver1997e0a2021-02-05 11:54:47 -0800557 size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000558 {
559 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
560 return __str_find_first_of<value_type, size_type, traits_type, npos>
561 (data(), size(), __s, __pos, __n);
562 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000563
Marshall Clowb7db4972017-11-15 20:02:27 +0000564 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
zoecarver1997e0a2021-02-05 11:54:47 -0800565 size_type find_first_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000566 {
567 _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr");
568 return __str_find_first_of<value_type, size_type, traits_type, npos>
569 (data(), size(), __s, __pos, traits_type::length(__s));
570 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000571
Marshall Clowb7db4972017-11-15 20:02:27 +0000572 // find_last_of
573 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
574 size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
575 {
576 _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
577 return __str_find_last_of<value_type, size_type, traits_type, npos>
578 (data(), size(), __s.data(), __pos, __s.size());
579 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000580
Marshall Clowb7db4972017-11-15 20:02:27 +0000581 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
582 size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT
583 { return rfind(__c, __pos); }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000584
Marshall Clowb7db4972017-11-15 20:02:27 +0000585 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
zoecarver1997e0a2021-02-05 11:54:47 -0800586 size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000587 {
588 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
589 return __str_find_last_of<value_type, size_type, traits_type, npos>
590 (data(), size(), __s, __pos, __n);
591 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000592
Marshall Clowb7db4972017-11-15 20:02:27 +0000593 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
zoecarver1997e0a2021-02-05 11:54:47 -0800594 size_type find_last_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000595 {
596 _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr");
597 return __str_find_last_of<value_type, size_type, traits_type, npos>
598 (data(), size(), __s, __pos, traits_type::length(__s));
599 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000600
Marshall Clowb7db4972017-11-15 20:02:27 +0000601 // find_first_not_of
602 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
603 size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT
604 {
605 _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
606 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
607 (data(), size(), __s.data(), __pos, __s.size());
608 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000609
Marshall Clowb7db4972017-11-15 20:02:27 +0000610 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
611 size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT
612 {
613 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
614 (data(), size(), __c, __pos);
615 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000616
Marshall Clowb7db4972017-11-15 20:02:27 +0000617 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
zoecarver1997e0a2021-02-05 11:54:47 -0800618 size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000619 {
620 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
621 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
622 (data(), size(), __s, __pos, __n);
623 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000624
Marshall Clowb7db4972017-11-15 20:02:27 +0000625 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
zoecarver1997e0a2021-02-05 11:54:47 -0800626 size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000627 {
628 _LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
629 return __str_find_first_not_of<value_type, size_type, traits_type, npos>
630 (data(), size(), __s, __pos, traits_type::length(__s));
631 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000632
Marshall Clowb7db4972017-11-15 20:02:27 +0000633 // find_last_not_of
634 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
635 size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
636 {
637 _LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
638 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
639 (data(), size(), __s.data(), __pos, __s.size());
640 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000641
Marshall Clowb7db4972017-11-15 20:02:27 +0000642 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
643 size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT
644 {
645 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
646 (data(), size(), __c, __pos);
647 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000648
Marshall Clowb7db4972017-11-15 20:02:27 +0000649 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
zoecarver1997e0a2021-02-05 11:54:47 -0800650 size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000651 {
652 _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
653 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
654 (data(), size(), __s, __pos, __n);
655 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000656
Marshall Clowb7db4972017-11-15 20:02:27 +0000657 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
zoecarver1997e0a2021-02-05 11:54:47 -0800658 size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const _NOEXCEPT
Marshall Clowb7db4972017-11-15 20:02:27 +0000659 {
660 _LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
661 return __str_find_last_not_of<value_type, size_type, traits_type, npos>
662 (data(), size(), __s, __pos, traits_type::length(__s));
663 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000664
Marshall Clow18c293b2017-12-04 20:11:38 +0000665#if _LIBCPP_STD_VER > 17
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -0400666 constexpr _LIBCPP_INLINE_VISIBILITY
667 bool starts_with(basic_string_view __s) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +0000668 { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; }
669
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -0400670 constexpr _LIBCPP_INLINE_VISIBILITY
671 bool starts_with(value_type __c) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +0000672 { return !empty() && _Traits::eq(front(), __c); }
673
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -0400674 constexpr _LIBCPP_INLINE_VISIBILITY
675 bool starts_with(const value_type* __s) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +0000676 { return starts_with(basic_string_view(__s)); }
677
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -0400678 constexpr _LIBCPP_INLINE_VISIBILITY
679 bool ends_with(basic_string_view __s) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +0000680 { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; }
681
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -0400682 constexpr _LIBCPP_INLINE_VISIBILITY
683 bool ends_with(value_type __c) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +0000684 { return !empty() && _Traits::eq(back(), __c); }
685
Arthur O'Dwyera0cb1e82021-09-28 12:19:35 -0400686 constexpr _LIBCPP_INLINE_VISIBILITY
687 bool ends_with(const value_type* __s) const noexcept
Marshall Clow18c293b2017-12-04 20:11:38 +0000688 { return ends_with(basic_string_view(__s)); }
689#endif
690
Wim Leflere023c3542021-01-19 14:33:30 -0500691#if _LIBCPP_STD_VER > 20
692 constexpr _LIBCPP_INLINE_VISIBILITY
693 bool contains(basic_string_view __sv) const noexcept
694 { return find(__sv) != npos; }
695
696 constexpr _LIBCPP_INLINE_VISIBILITY
697 bool contains(value_type __c) const noexcept
698 { return find(__c) != npos; }
699
700 constexpr _LIBCPP_INLINE_VISIBILITY
701 bool contains(const value_type* __s) const
702 { return find(__s) != npos; }
703#endif
704
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000705private:
Marshall Clowb7db4972017-11-15 20:02:27 +0000706 const value_type* __data;
707 size_type __size;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000708};
709
Arthur O'Dwyerfe74c902022-02-01 19:59:37 -0500710#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
Mark de Weveraf59b2d2020-11-24 18:08:02 +0100711template <class _CharT, class _Traits>
Christopher Di Bella92072c22021-05-14 06:20:07 +0000712inline constexpr bool ranges::enable_view<basic_string_view<_CharT, _Traits>> = true;
713
714template <class _CharT, class _Traits>
Mark de Weveraf59b2d2020-11-24 18:08:02 +0100715inline constexpr bool ranges::enable_borrowed_range<basic_string_view<_CharT, _Traits> > = true;
Arthur O'Dwyerfe74c902022-02-01 19:59:37 -0500716#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS)
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000717
Joe Loser28dcceb2021-10-06 14:17:02 -0400718// [string.view.deduct]
719
Arthur O'Dwyerfe74c902022-02-01 19:59:37 -0500720#if !defined(_LIBCPP_HAS_NO_CONCEPTS)
Joe Loser28dcceb2021-10-06 14:17:02 -0400721template <contiguous_iterator _It, sized_sentinel_for<_It> _End>
722 basic_string_view(_It, _End) -> basic_string_view<iter_value_t<_It>>;
723#endif
724
Joe Loser1cf8cae2021-11-03 18:45:04 -0400725
Arthur O'Dwyer654b4db2022-01-31 12:04:08 -0500726#if _LIBCPP_STD_VER > 20 && !defined(_LIBCPP_HAS_NO_CONCEPTS)
Joe Loser1cf8cae2021-11-03 18:45:04 -0400727template <ranges::contiguous_range _Range>
728 basic_string_view(_Range) -> basic_string_view<ranges::range_value_t<_Range>>;
729#endif
730
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000731// [string.view.comparison]
732// operator ==
733template<class _CharT, class _Traits>
734_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
735bool operator==(basic_string_view<_CharT, _Traits> __lhs,
Marshall Clowb7db4972017-11-15 20:02:27 +0000736 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000737{
Marshall Clowb7db4972017-11-15 20:02:27 +0000738 if ( __lhs.size() != __rhs.size()) return false;
739 return __lhs.compare(__rhs) == 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000740}
741
Joe Loser1cf8cae2021-11-03 18:45:04 -0400742// The dummy default template parameters are used to work around a MSVC issue with mangling, see VSO-409326 for details.
743// This applies to the other sufficient overloads below for the other comparison operators.
744template<class _CharT, class _Traits, int = 1>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000745_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
746bool operator==(basic_string_view<_CharT, _Traits> __lhs,
Marshall Clowb7db4972017-11-15 20:02:27 +0000747 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000748{
Marshall Clowb7db4972017-11-15 20:02:27 +0000749 if ( __lhs.size() != __rhs.size()) return false;
750 return __lhs.compare(__rhs) == 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000751}
752
Joe Loser1cf8cae2021-11-03 18:45:04 -0400753template<class _CharT, class _Traits, int = 2>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000754_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Louis Dionne173f29e2019-05-29 16:01:36 +0000755bool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
Marshall Clowb7db4972017-11-15 20:02:27 +0000756 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000757{
Marshall Clowb7db4972017-11-15 20:02:27 +0000758 if ( __lhs.size() != __rhs.size()) return false;
759 return __lhs.compare(__rhs) == 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000760}
761
762
763// operator !=
764template<class _CharT, class _Traits>
765_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
766bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
767{
Marshall Clowb7db4972017-11-15 20:02:27 +0000768 if ( __lhs.size() != __rhs.size())
769 return true;
770 return __lhs.compare(__rhs) != 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000771}
772
Joe Loser1cf8cae2021-11-03 18:45:04 -0400773template<class _CharT, class _Traits, int = 1>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000774_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
775bool operator!=(basic_string_view<_CharT, _Traits> __lhs,
Marshall Clowb7db4972017-11-15 20:02:27 +0000776 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000777{
Marshall Clowb7db4972017-11-15 20:02:27 +0000778 if ( __lhs.size() != __rhs.size())
779 return true;
780 return __lhs.compare(__rhs) != 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000781}
782
Joe Loser1cf8cae2021-11-03 18:45:04 -0400783template<class _CharT, class _Traits, int = 2>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000784_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Louis Dionne173f29e2019-05-29 16:01:36 +0000785bool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
Marshall Clowb7db4972017-11-15 20:02:27 +0000786 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000787{
Marshall Clowb7db4972017-11-15 20:02:27 +0000788 if ( __lhs.size() != __rhs.size())
789 return true;
790 return __lhs.compare(__rhs) != 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000791}
792
793
794// operator <
795template<class _CharT, class _Traits>
796_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
797bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
798{
Marshall Clowb7db4972017-11-15 20:02:27 +0000799 return __lhs.compare(__rhs) < 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000800}
801
Joe Loser1cf8cae2021-11-03 18:45:04 -0400802template<class _CharT, class _Traits, int = 1>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000803_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
804bool operator<(basic_string_view<_CharT, _Traits> __lhs,
Marshall Clowb7db4972017-11-15 20:02:27 +0000805 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000806{
Marshall Clowb7db4972017-11-15 20:02:27 +0000807 return __lhs.compare(__rhs) < 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000808}
809
Joe Loser1cf8cae2021-11-03 18:45:04 -0400810template<class _CharT, class _Traits, int = 2>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000811_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Louis Dionne173f29e2019-05-29 16:01:36 +0000812bool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
Marshall Clowb7db4972017-11-15 20:02:27 +0000813 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000814{
Marshall Clowb7db4972017-11-15 20:02:27 +0000815 return __lhs.compare(__rhs) < 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000816}
817
818
819// operator >
820template<class _CharT, class _Traits>
821_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
822bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
823{
Marshall Clowb7db4972017-11-15 20:02:27 +0000824 return __lhs.compare(__rhs) > 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000825}
826
Joe Loser1cf8cae2021-11-03 18:45:04 -0400827template<class _CharT, class _Traits, int = 1>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000828_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
829bool operator>(basic_string_view<_CharT, _Traits> __lhs,
Marshall Clowb7db4972017-11-15 20:02:27 +0000830 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000831{
Marshall Clowb7db4972017-11-15 20:02:27 +0000832 return __lhs.compare(__rhs) > 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000833}
834
Joe Loser1cf8cae2021-11-03 18:45:04 -0400835template<class _CharT, class _Traits, int = 2>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000836_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Louis Dionne173f29e2019-05-29 16:01:36 +0000837bool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
Marshall Clowb7db4972017-11-15 20:02:27 +0000838 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000839{
Marshall Clowb7db4972017-11-15 20:02:27 +0000840 return __lhs.compare(__rhs) > 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000841}
842
843
844// operator <=
845template<class _CharT, class _Traits>
846_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
847bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
848{
Marshall Clowb7db4972017-11-15 20:02:27 +0000849 return __lhs.compare(__rhs) <= 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000850}
851
Joe Loser1cf8cae2021-11-03 18:45:04 -0400852template<class _CharT, class _Traits, int = 1>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000853_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
854bool operator<=(basic_string_view<_CharT, _Traits> __lhs,
Marshall Clowb7db4972017-11-15 20:02:27 +0000855 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000856{
Marshall Clowb7db4972017-11-15 20:02:27 +0000857 return __lhs.compare(__rhs) <= 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000858}
859
Joe Loser1cf8cae2021-11-03 18:45:04 -0400860template<class _CharT, class _Traits, int = 2>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000861_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Louis Dionne173f29e2019-05-29 16:01:36 +0000862bool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
Marshall Clowb7db4972017-11-15 20:02:27 +0000863 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000864{
Marshall Clowb7db4972017-11-15 20:02:27 +0000865 return __lhs.compare(__rhs) <= 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000866}
867
868
869// operator >=
870template<class _CharT, class _Traits>
871_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
872bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
873{
Marshall Clowb7db4972017-11-15 20:02:27 +0000874 return __lhs.compare(__rhs) >= 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000875}
876
877
Joe Loser1cf8cae2021-11-03 18:45:04 -0400878template<class _CharT, class _Traits, int = 1>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000879_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
880bool operator>=(basic_string_view<_CharT, _Traits> __lhs,
Marshall Clowb7db4972017-11-15 20:02:27 +0000881 typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000882{
Marshall Clowb7db4972017-11-15 20:02:27 +0000883 return __lhs.compare(__rhs) >= 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000884}
885
Joe Loser1cf8cae2021-11-03 18:45:04 -0400886template<class _CharT, class _Traits, int = 2>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000887_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Louis Dionne173f29e2019-05-29 16:01:36 +0000888bool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
Marshall Clowb7db4972017-11-15 20:02:27 +0000889 basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000890{
Marshall Clowb7db4972017-11-15 20:02:27 +0000891 return __lhs.compare(__rhs) >= 0;
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000892}
893
Eric Fiselier14116922019-09-25 18:56:54 +0000894
895template<class _CharT, class _Traits>
896basic_ostream<_CharT, _Traits>&
897operator<<(basic_ostream<_CharT, _Traits>& __os,
898 basic_string_view<_CharT, _Traits> __str);
899
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000900// [string.view.hash]
Marshall Clowab313df2019-06-27 14:18:32 +0000901template<class _CharT>
902struct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, char_traits<_CharT> > >
903 : public unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t>
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000904{
Louis Dionned83f2e62018-11-28 15:22:30 +0000905 _LIBCPP_INLINE_VISIBILITY
Marshall Clowab313df2019-06-27 14:18:32 +0000906 size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT {
Louis Dionned83f2e62018-11-28 15:22:30 +0000907 return __do_string_hash(__val.data(), __val.data() + __val.size());
908 }
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000909};
910
Marshall Clow27c8a4c2017-01-09 18:07:34 +0000911
Louis Dionne173f29e2019-05-29 16:01:36 +0000912#if _LIBCPP_STD_VER > 11
Marshall Clow27c8a4c2017-01-09 18:07:34 +0000913inline namespace literals
914{
915 inline namespace string_view_literals
916 {
917 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Marshall Clowabe6daf2017-10-24 14:06:00 +0000918 basic_string_view<char> operator "" sv(const char *__str, size_t __len) _NOEXCEPT
Marshall Clow27c8a4c2017-01-09 18:07:34 +0000919 {
920 return basic_string_view<char> (__str, __len);
921 }
922
Louis Dionne89258142021-08-23 15:32:36 -0400923#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
Marshall Clow27c8a4c2017-01-09 18:07:34 +0000924 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Marshall Clowabe6daf2017-10-24 14:06:00 +0000925 basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT
Marshall Clow27c8a4c2017-01-09 18:07:34 +0000926 {
927 return basic_string_view<wchar_t> (__str, __len);
928 }
Louis Dionne89258142021-08-23 15:32:36 -0400929#endif
Marshall Clow27c8a4c2017-01-09 18:07:34 +0000930
Arthur O'Dwyerafa5d5f2021-04-18 21:47:08 -0400931#ifndef _LIBCPP_HAS_NO_CHAR8_T
Marshall Clow8732fed2018-12-11 04:35:44 +0000932 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
933 basic_string_view<char8_t> operator "" sv(const char8_t *__str, size_t __len) _NOEXCEPT
934 {
935 return basic_string_view<char8_t> (__str, __len);
936 }
937#endif
938
Marshall Clow27c8a4c2017-01-09 18:07:34 +0000939 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Marshall Clowabe6daf2017-10-24 14:06:00 +0000940 basic_string_view<char16_t> operator "" sv(const char16_t *__str, size_t __len) _NOEXCEPT
Marshall Clow27c8a4c2017-01-09 18:07:34 +0000941 {
942 return basic_string_view<char16_t> (__str, __len);
943 }
944
945 inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
Marshall Clowabe6daf2017-10-24 14:06:00 +0000946 basic_string_view<char32_t> operator "" sv(const char32_t *__str, size_t __len) _NOEXCEPT
Marshall Clow27c8a4c2017-01-09 18:07:34 +0000947 {
948 return basic_string_view<char32_t> (__str, __len);
949 }
Nikolas Klauserd26407a2021-12-02 14:12:51 +0100950 } // namespace string_view_literals
951} // namespace literals
Marshall Clow27c8a4c2017-01-09 18:07:34 +0000952#endif
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000953_LIBCPP_END_NAMESPACE_STD
954
Eric Fiselierf4433a32017-05-31 22:07:49 +0000955_LIBCPP_POP_MACROS
956
Marshall Clowdf63a6d2016-07-21 05:31:24 +0000957#endif // _LIBCPP_STRING_VIEW