1*053d81ceSMarshall Clow// -*- C++ -*-
2*053d81ceSMarshall Clow//===------------------------ string_view ---------------------------------===//
3*053d81ceSMarshall Clow//
4*053d81ceSMarshall Clow//                     The LLVM Compiler Infrastructure
5*053d81ceSMarshall Clow//
6*053d81ceSMarshall Clow// This file is distributed under the University of Illinois Open Source
7*053d81ceSMarshall Clow// License. See LICENSE.TXT for details.
8*053d81ceSMarshall Clow//
9*053d81ceSMarshall Clow//===----------------------------------------------------------------------===//
10*053d81ceSMarshall Clow
11*053d81ceSMarshall Clow#ifndef _LIBCPP_STRING_VIEW
12*053d81ceSMarshall Clow#define _LIBCPP_STRING_VIEW
13*053d81ceSMarshall Clow
14*053d81ceSMarshall Clow/*
15*053d81ceSMarshall Clowstring_view synopsis
16*053d81ceSMarshall Clow
17*053d81ceSMarshall Clownamespace std {
18*053d81ceSMarshall Clow
19*053d81ceSMarshall Clow    // 7.2, Class template basic_string_view
20*053d81ceSMarshall Clow    template<class charT, class traits = char_traits<charT>>
21*053d81ceSMarshall Clow        class basic_string_view;
22*053d81ceSMarshall Clow
23*053d81ceSMarshall Clow    // 7.9, basic_string_view non-member comparison functions
24*053d81ceSMarshall Clow    template<class charT, class traits>
25*053d81ceSMarshall Clow    constexpr bool operator==(basic_string_view<charT, traits> x,
26*053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
27*053d81ceSMarshall Clow    template<class charT, class traits>
28*053d81ceSMarshall Clow    constexpr bool operator!=(basic_string_view<charT, traits> x,
29*053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
30*053d81ceSMarshall Clow    template<class charT, class traits>
31*053d81ceSMarshall Clow    constexpr bool operator< (basic_string_view<charT, traits> x,
32*053d81ceSMarshall Clow                                 basic_string_view<charT, traits> y) noexcept;
33*053d81ceSMarshall Clow    template<class charT, class traits>
34*053d81ceSMarshall Clow    constexpr bool operator> (basic_string_view<charT, traits> x,
35*053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
36*053d81ceSMarshall Clow    template<class charT, class traits>
37*053d81ceSMarshall Clow    constexpr bool operator<=(basic_string_view<charT, traits> x,
38*053d81ceSMarshall Clow                                 basic_string_view<charT, traits> y) noexcept;
39*053d81ceSMarshall Clow    template<class charT, class traits>
40*053d81ceSMarshall Clow    constexpr bool operator>=(basic_string_view<charT, traits> x,
41*053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
42*053d81ceSMarshall Clow    // see below, sufficient additional overloads of comparison functions
43*053d81ceSMarshall Clow
44*053d81ceSMarshall Clow    // 7.10, Inserters and extractors
45*053d81ceSMarshall Clow    template<class charT, class traits>
46*053d81ceSMarshall Clow      basic_ostream<charT, traits>&
47*053d81ceSMarshall Clow        operator<<(basic_ostream<charT, traits>& os,
48*053d81ceSMarshall Clow                   basic_string_view<charT, traits> str);
49*053d81ceSMarshall Clow
50*053d81ceSMarshall Clow    // basic_string_view typedef names
51*053d81ceSMarshall Clow    typedef basic_string_view<char> string_view;
52*053d81ceSMarshall Clow    typedef basic_string_view<char16_t> u16string_view;
53*053d81ceSMarshall Clow    typedef basic_string_view<char32_t> u32string_view;
54*053d81ceSMarshall Clow    typedef basic_string_view<wchar_t> wstring_view;
55*053d81ceSMarshall Clow
56*053d81ceSMarshall Clow    template<class charT, class traits = char_traits<charT>>
57*053d81ceSMarshall Clow    class basic_string_view {
58*053d81ceSMarshall Clow      public:
59*053d81ceSMarshall Clow      // types
60*053d81ceSMarshall Clow      typedef traits traits_type;
61*053d81ceSMarshall Clow      typedef charT value_type;
62*053d81ceSMarshall Clow      typedef charT* pointer;
63*053d81ceSMarshall Clow      typedef const charT* const_pointer;
64*053d81ceSMarshall Clow      typedef charT& reference;
65*053d81ceSMarshall Clow      typedef const charT& const_reference;
66*053d81ceSMarshall Clow      typedef implementation-defined const_iterator;
67*053d81ceSMarshall Clow      typedef const_iterator iterator;
68*053d81ceSMarshall Clow      typedef reverse_iterator<const_iterator> const_reverse_iterator;
69*053d81ceSMarshall Clow      typedef const_reverse_iterator reverse_iterator;
70*053d81ceSMarshall Clow      typedef size_t size_type;
71*053d81ceSMarshall Clow      typedef ptrdiff_t difference_type;
72*053d81ceSMarshall Clow      static constexpr size_type npos = size_type(-1);
73*053d81ceSMarshall Clow
74*053d81ceSMarshall Clow      // 7.3, basic_string_view constructors and assignment operators
75*053d81ceSMarshall Clow      constexpr basic_string_view() noexcept;
76*053d81ceSMarshall Clow      constexpr basic_string_view(const basic_string_view&) noexcept = default;
77*053d81ceSMarshall Clow      basic_string_view& operator=(const basic_string_view&) noexcept = default;
78*053d81ceSMarshall Clow      template<class Allocator>
79*053d81ceSMarshall Clow      constexpr basic_string_view(const charT* str);
80*053d81ceSMarshall Clow      constexpr basic_string_view(const charT* str, size_type len);
81*053d81ceSMarshall Clow
82*053d81ceSMarshall Clow      // 7.4, basic_string_view iterator support
83*053d81ceSMarshall Clow      constexpr const_iterator begin() const noexcept;
84*053d81ceSMarshall Clow      constexpr const_iterator end() const noexcept;
85*053d81ceSMarshall Clow      constexpr const_iterator cbegin() const noexcept;
86*053d81ceSMarshall Clow      constexpr const_iterator cend() const noexcept;
87*053d81ceSMarshall Clow      const_reverse_iterator rbegin() const noexcept;
88*053d81ceSMarshall Clow      const_reverse_iterator rend() const noexcept;
89*053d81ceSMarshall Clow      const_reverse_iterator crbegin() const noexcept;
90*053d81ceSMarshall Clow      const_reverse_iterator crend() const noexcept;
91*053d81ceSMarshall Clow
92*053d81ceSMarshall Clow      // 7.5, basic_string_view capacity
93*053d81ceSMarshall Clow      constexpr size_type size() const noexcept;
94*053d81ceSMarshall Clow      constexpr size_type length() const noexcept;
95*053d81ceSMarshall Clow      constexpr size_type max_size() const noexcept;
96*053d81ceSMarshall Clow      constexpr bool empty() const noexcept;
97*053d81ceSMarshall Clow
98*053d81ceSMarshall Clow      // 7.6, basic_string_view element access
99*053d81ceSMarshall Clow      constexpr const_reference operator[](size_type pos) const;
100*053d81ceSMarshall Clow      constexpr const_reference at(size_type pos) const;
101*053d81ceSMarshall Clow      constexpr const_reference front() const;
102*053d81ceSMarshall Clow      constexpr const_reference back() const;
103*053d81ceSMarshall Clow      constexpr const_pointer data() const noexcept;
104*053d81ceSMarshall Clow
105*053d81ceSMarshall Clow      // 7.7, basic_string_view modifiers
106*053d81ceSMarshall Clow      constexpr void clear() noexcept;
107*053d81ceSMarshall Clow      constexpr void remove_prefix(size_type n);
108*053d81ceSMarshall Clow      constexpr void remove_suffix(size_type n);
109*053d81ceSMarshall Clow      constexpr void swap(basic_string_view& s) noexcept;
110*053d81ceSMarshall Clow
111*053d81ceSMarshall Clow      size_type copy(charT* s, size_type n, size_type pos = 0) const;
112*053d81ceSMarshall Clow
113*053d81ceSMarshall Clow      constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
114*053d81ceSMarshall Clow      constexpr int compare(basic_string_view s) const noexcept;
115*053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
116*053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1,
117*053d81ceSMarshall Clow                            basic_string_view s, size_type pos2, size_type n2) const;
118*053d81ceSMarshall Clow      constexpr int compare(const charT* s) const;
119*053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
120*053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1,
121*053d81ceSMarshall Clow                            const charT* s, size_type n2) const;
122*053d81ceSMarshall Clow      constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
123*053d81ceSMarshall Clow      constexpr size_type find(charT c, size_type pos = 0) const noexcept;
124*053d81ceSMarshall Clow      constexpr size_type find(const charT* s, size_type pos, size_type n) const;
125*053d81ceSMarshall Clow      constexpr size_type find(const charT* s, size_type pos = 0) const;
126*053d81ceSMarshall Clow      constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
127*053d81ceSMarshall Clow      constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
128*053d81ceSMarshall Clow      constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
129*053d81ceSMarshall Clow      constexpr size_type rfind(const charT* s, size_type pos = npos) const;
130*053d81ceSMarshall Clow      constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
131*053d81ceSMarshall Clow      constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
132*053d81ceSMarshall Clow      constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
133*053d81ceSMarshall Clow      constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
134*053d81ceSMarshall Clow      constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
135*053d81ceSMarshall Clow      constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
136*053d81ceSMarshall Clow      constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const;
137*053d81ceSMarshall Clow      constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;
138*053d81ceSMarshall Clow      constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
139*053d81ceSMarshall Clow      constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
140*053d81ceSMarshall Clow      constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
141*053d81ceSMarshall Clow      constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const;
142*053d81ceSMarshall Clow      constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
143*053d81ceSMarshall Clow      constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
144*053d81ceSMarshall Clow      constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
145*053d81ceSMarshall Clow      constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
146*053d81ceSMarshall Clow
147*053d81ceSMarshall Clow     private:
148*053d81ceSMarshall Clow      const_pointer data_;  // exposition only
149*053d81ceSMarshall Clow      size_type     size_;  // exposition only
150*053d81ceSMarshall Clow    };
151*053d81ceSMarshall Clow
152*053d81ceSMarshall Clow  // 7.11, Hash support
153*053d81ceSMarshall Clow  template <class T> struct hash;
154*053d81ceSMarshall Clow  template <> struct hash<string_view>;
155*053d81ceSMarshall Clow  template <> struct hash<u16string_view>;
156*053d81ceSMarshall Clow  template <> struct hash<u32string_view>;
157*053d81ceSMarshall Clow  template <> struct hash<wstring_view>;
158*053d81ceSMarshall Clow
159*053d81ceSMarshall Clow}  // namespace std
160*053d81ceSMarshall Clow
161*053d81ceSMarshall Clow
162*053d81ceSMarshall Clow*/
163*053d81ceSMarshall Clow
164*053d81ceSMarshall Clow#include <__config>
165*053d81ceSMarshall Clow
166*053d81ceSMarshall Clow#include <__string>
167*053d81ceSMarshall Clow#include <algorithm>
168*053d81ceSMarshall Clow#include <iterator>
169*053d81ceSMarshall Clow#include <__debug>
170*053d81ceSMarshall Clow
171*053d81ceSMarshall Clow#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
172*053d81ceSMarshall Clow#pragma GCC system_header
173*053d81ceSMarshall Clow#endif
174*053d81ceSMarshall Clow
175*053d81ceSMarshall Clow_LIBCPP_BEGIN_NAMESPACE_STD
176*053d81ceSMarshall Clow
177*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits = char_traits<_CharT> >
178*053d81ceSMarshall Clowclass _LIBCPP_TYPE_VIS_ONLY basic_string_view {
179*053d81ceSMarshall Clowpublic:
180*053d81ceSMarshall Clow	// types
181*053d81ceSMarshall Clow	typedef _Traits                                    traits_type;
182*053d81ceSMarshall Clow	typedef _CharT                                     value_type;
183*053d81ceSMarshall Clow	typedef const _CharT*                              pointer;
184*053d81ceSMarshall Clow	typedef const _CharT*                              const_pointer;
185*053d81ceSMarshall Clow	typedef const _CharT&                              reference;
186*053d81ceSMarshall Clow	typedef const _CharT&                              const_reference;
187*053d81ceSMarshall Clow	typedef const_pointer                              const_iterator; // See [string.view.iterators]
188*053d81ceSMarshall Clow	typedef const_iterator                             iterator;
189*053d81ceSMarshall Clow	typedef _VSTD::reverse_iterator<const_iterator>    const_reverse_iterator;
190*053d81ceSMarshall Clow	typedef const_reverse_iterator                     reverse_iterator;
191*053d81ceSMarshall Clow	typedef size_t                                     size_type;
192*053d81ceSMarshall Clow	typedef ptrdiff_t                                  difference_type;
193*053d81ceSMarshall Clow	static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
194*053d81ceSMarshall Clow
195*053d81ceSMarshall Clow	// [string.view.cons], construct/copy
196*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
197*053d81ceSMarshall Clow	basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {}
198*053d81ceSMarshall Clow
199*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
200*053d81ceSMarshall Clow	basic_string_view(const basic_string_view&) _NOEXCEPT = default;
201*053d81ceSMarshall Clow
202*053d81ceSMarshall Clow	_LIBCPP_INLINE_VISIBILITY
203*053d81ceSMarshall Clow	basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
204*053d81ceSMarshall Clow
205*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
206*053d81ceSMarshall Clow	basic_string_view(const _CharT* __s, size_type __len)
207*053d81ceSMarshall Clow		: __data(__s), __size(__len)
208*053d81ceSMarshall Clow	{
209*053d81ceSMarshall Clow#if _LIBCPP_STD_VER > 11
210*053d81ceSMarshall Clow        _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
211*053d81ceSMarshall Clow#endif
212*053d81ceSMarshall Clow	}
213*053d81ceSMarshall Clow
214*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
215*053d81ceSMarshall Clow	basic_string_view(const _CharT* __s)
216*053d81ceSMarshall Clow		: __data(__s), __size(_Traits::length(__s)) {}
217*053d81ceSMarshall Clow
218*053d81ceSMarshall Clow	// [string.view.iterators], iterators
219*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
220*053d81ceSMarshall Clow	const_iterator begin()  const _NOEXCEPT { return cbegin(); }
221*053d81ceSMarshall Clow
222*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
223*053d81ceSMarshall Clow	const_iterator end()    const _NOEXCEPT { return cend(); }
224*053d81ceSMarshall Clow
225*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
226*053d81ceSMarshall Clow	const_iterator cbegin() const _NOEXCEPT { return __data; }
227*053d81ceSMarshall Clow
228*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
229*053d81ceSMarshall Clow	const_iterator cend()   const _NOEXCEPT { return __data + __size; }
230*053d81ceSMarshall Clow
231*053d81ceSMarshall Clow	_LIBCPP_INLINE_VISIBILITY
232*053d81ceSMarshall Clow	const_reverse_iterator rbegin()   const _NOEXCEPT { return const_reverse_iterator(cend()); }
233*053d81ceSMarshall Clow
234*053d81ceSMarshall Clow	_LIBCPP_INLINE_VISIBILITY
235*053d81ceSMarshall Clow	const_reverse_iterator rend()     const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
236*053d81ceSMarshall Clow
237*053d81ceSMarshall Clow	_LIBCPP_INLINE_VISIBILITY
238*053d81ceSMarshall Clow	const_reverse_iterator crbegin()  const _NOEXCEPT { return const_reverse_iterator(cend()); }
239*053d81ceSMarshall Clow
240*053d81ceSMarshall Clow	_LIBCPP_INLINE_VISIBILITY
241*053d81ceSMarshall Clow	const_reverse_iterator crend()    const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
242*053d81ceSMarshall Clow
243*053d81ceSMarshall Clow	// [string.view.capacity], capacity
244*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
245*053d81ceSMarshall Clow	size_type size()     const _NOEXCEPT { return __size; }
246*053d81ceSMarshall Clow
247*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
248*053d81ceSMarshall Clow	size_type length()   const _NOEXCEPT { return __size; }
249*053d81ceSMarshall Clow
250*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
251*053d81ceSMarshall Clow	size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max(); }
252*053d81ceSMarshall Clow
253*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR bool _LIBCPP_INLINE_VISIBILITY
254*053d81ceSMarshall Clow	empty()         const _NOEXCEPT { return __size == 0; }
255*053d81ceSMarshall Clow
256*053d81ceSMarshall Clow	// [string.view.access], element access
257*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
258*053d81ceSMarshall Clow	const_reference operator[](size_type __pos) const _NOEXCEPT { return __data[__pos]; }
259*053d81ceSMarshall Clow
260*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
261*053d81ceSMarshall Clow	const_reference at(size_type __pos) const
262*053d81ceSMarshall Clow	{
263*053d81ceSMarshall Clow		return __pos >= size()
264*053d81ceSMarshall Clow			? (__libcpp_throw(out_of_range("string_view::at")), __data[0])
265*053d81ceSMarshall Clow			: __data[__pos];
266*053d81ceSMarshall Clow	}
267*053d81ceSMarshall Clow
268*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
269*053d81ceSMarshall Clow	const_reference front() const
270*053d81ceSMarshall Clow	{
271*053d81ceSMarshall Clow		return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0];
272*053d81ceSMarshall Clow	}
273*053d81ceSMarshall Clow
274*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
275*053d81ceSMarshall Clow	const_reference back() const
276*053d81ceSMarshall Clow	{
277*053d81ceSMarshall Clow		return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1];
278*053d81ceSMarshall Clow	}
279*053d81ceSMarshall Clow
280*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
281*053d81ceSMarshall Clow	const_pointer data() const _NOEXCEPT { return __data; }
282*053d81ceSMarshall Clow
283*053d81ceSMarshall Clow	// [string.view.modifiers], modifiers:
284*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
285*053d81ceSMarshall Clow	void clear() _NOEXCEPT
286*053d81ceSMarshall Clow	{
287*053d81ceSMarshall Clow		__data = nullptr;
288*053d81ceSMarshall Clow		__size = 0;
289*053d81ceSMarshall Clow	}
290*053d81ceSMarshall Clow
291*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
292*053d81ceSMarshall Clow	void remove_prefix(size_type __n) _NOEXCEPT
293*053d81ceSMarshall Clow	{
294*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()");
295*053d81ceSMarshall Clow		__data += __n;
296*053d81ceSMarshall Clow		__size -= __n;
297*053d81ceSMarshall Clow	}
298*053d81ceSMarshall Clow
299*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
300*053d81ceSMarshall Clow	void remove_suffix(size_type __n) _NOEXCEPT
301*053d81ceSMarshall Clow	{
302*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()");
303*053d81ceSMarshall Clow		__size -= __n;
304*053d81ceSMarshall Clow	}
305*053d81ceSMarshall Clow
306*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
307*053d81ceSMarshall Clow	void swap(basic_string_view& __other) _NOEXCEPT
308*053d81ceSMarshall Clow	{
309*053d81ceSMarshall Clow		const value_type *__p = __data;
310*053d81ceSMarshall Clow		__data = __other.__data;
311*053d81ceSMarshall Clow		__other.__data = __p;
312*053d81ceSMarshall Clow
313*053d81ceSMarshall Clow		size_type __sz = __size;
314*053d81ceSMarshall Clow		__size = __other.__size;
315*053d81ceSMarshall Clow		__other.__size = __sz;
316*053d81ceSMarshall Clow	}
317*053d81ceSMarshall Clow
318*053d81ceSMarshall Clow	_LIBCPP_INLINE_VISIBILITY
319*053d81ceSMarshall Clow	size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const
320*053d81ceSMarshall Clow	{
321*053d81ceSMarshall Clow		if (__pos > size())
322*053d81ceSMarshall Clow			__libcpp_throw(out_of_range("string_view::copy"));
323*053d81ceSMarshall Clow		size_type __rlen = _VSTD::min( __n, size() - __pos );
324*053d81ceSMarshall Clow		copy_n(begin() + __pos, __rlen, __s );
325*053d81ceSMarshall Clow		return __rlen;
326*053d81ceSMarshall Clow	}
327*053d81ceSMarshall Clow
328*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
329*053d81ceSMarshall Clow	basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
330*053d81ceSMarshall Clow	{
331*053d81ceSMarshall Clow		return __pos > size()
332*053d81ceSMarshall Clow			? (__libcpp_throw((out_of_range("string_view::substr"))), basic_string_view())
333*053d81ceSMarshall Clow			: basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos));
334*053d81ceSMarshall Clow	}
335*053d81ceSMarshall Clow
336*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT
337*053d81ceSMarshall Clow	{
338*053d81ceSMarshall Clow		size_type __rlen = _VSTD::min( size(), __sv.size());
339*053d81ceSMarshall Clow		int __retval = _Traits::compare(data(), __sv.data(), __rlen);
340*053d81ceSMarshall Clow		if ( __retval == 0 ) // first __rlen chars matched
341*053d81ceSMarshall Clow			__retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 );
342*053d81ceSMarshall Clow		return __retval;
343*053d81ceSMarshall Clow	}
344*053d81ceSMarshall Clow
345*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
346*053d81ceSMarshall Clow	int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const
347*053d81ceSMarshall Clow	{
348*053d81ceSMarshall Clow		return substr(__pos1, __n1).compare(__sv);
349*053d81ceSMarshall Clow	}
350*053d81ceSMarshall Clow
351*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
352*053d81ceSMarshall Clow	int compare(                       size_type __pos1, size_type __n1,
353*053d81ceSMarshall Clow				basic_string_view _sv, size_type __pos2, size_type __n2) const
354*053d81ceSMarshall Clow	{
355*053d81ceSMarshall Clow		return substr(__pos1, __n1).compare(_sv.substr(__pos2, __n2));
356*053d81ceSMarshall Clow	}
357*053d81ceSMarshall Clow
358*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
359*053d81ceSMarshall Clow	int compare(const _CharT* __s) const
360*053d81ceSMarshall Clow	{
361*053d81ceSMarshall Clow		return compare(basic_string_view(__s));
362*053d81ceSMarshall Clow	}
363*053d81ceSMarshall Clow
364*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
365*053d81ceSMarshall Clow	int compare(size_type __pos1, size_type __n1, const _CharT* __s) const
366*053d81ceSMarshall Clow	{
367*053d81ceSMarshall Clow		return substr(__pos1, __n1).compare(basic_string_view(__s));
368*053d81ceSMarshall Clow	}
369*053d81ceSMarshall Clow
370*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
371*053d81ceSMarshall Clow	int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
372*053d81ceSMarshall Clow	{
373*053d81ceSMarshall Clow		return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
374*053d81ceSMarshall Clow	}
375*053d81ceSMarshall Clow
376*053d81ceSMarshall Clow	// find
377*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
378*053d81ceSMarshall Clow	size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
379*053d81ceSMarshall Clow	{
380*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
381*053d81ceSMarshall Clow		return __str_find<value_type, size_type, traits_type, npos>
382*053d81ceSMarshall Clow			(data(), size(), __s.data(), __pos, __s.size());
383*053d81ceSMarshall Clow	}
384*053d81ceSMarshall Clow
385*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
386*053d81ceSMarshall Clow	size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT
387*053d81ceSMarshall Clow	{
388*053d81ceSMarshall Clow		return __str_find<value_type, size_type, traits_type, npos>
389*053d81ceSMarshall Clow			(data(), size(), __c, __pos);
390*053d81ceSMarshall Clow	}
391*053d81ceSMarshall Clow
392*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
393*053d81ceSMarshall Clow	size_type find(const _CharT* __s, size_type __pos, size_type __n) const
394*053d81ceSMarshall Clow	{
395*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
396*053d81ceSMarshall Clow		return __str_find<value_type, size_type, traits_type, npos>
397*053d81ceSMarshall Clow			(data(), size(), __s, __pos, __n);
398*053d81ceSMarshall Clow	}
399*053d81ceSMarshall Clow
400*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
401*053d81ceSMarshall Clow	size_type find(const _CharT* __s, size_type __pos = 0) const
402*053d81ceSMarshall Clow	{
403*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr");
404*053d81ceSMarshall Clow		return __str_find<value_type, size_type, traits_type, npos>
405*053d81ceSMarshall Clow			(data(), size(), __s, __pos, traits_type::length(__s));
406*053d81ceSMarshall Clow	}
407*053d81ceSMarshall Clow
408*053d81ceSMarshall Clow	// rfind
409*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
410*053d81ceSMarshall Clow	size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT
411*053d81ceSMarshall Clow	{
412*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
413*053d81ceSMarshall Clow		return __str_rfind<value_type, size_type, traits_type, npos>
414*053d81ceSMarshall Clow			(data(), size(), __s.data(), __pos, __s.size());
415*053d81ceSMarshall Clow	}
416*053d81ceSMarshall Clow
417*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
418*053d81ceSMarshall Clow	size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT
419*053d81ceSMarshall Clow	{
420*053d81ceSMarshall Clow		return __str_rfind<value_type, size_type, traits_type, npos>
421*053d81ceSMarshall Clow			(data(), size(), __c, __pos);
422*053d81ceSMarshall Clow	}
423*053d81ceSMarshall Clow
424*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
425*053d81ceSMarshall Clow	size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const
426*053d81ceSMarshall Clow	{
427*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
428*053d81ceSMarshall Clow		return __str_rfind<value_type, size_type, traits_type, npos>
429*053d81ceSMarshall Clow			(data(), size(), __s, __pos, __n);
430*053d81ceSMarshall Clow	}
431*053d81ceSMarshall Clow
432*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
433*053d81ceSMarshall Clow	size_type rfind(const _CharT* __s, size_type __pos=npos) const
434*053d81ceSMarshall Clow	{
435*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr");
436*053d81ceSMarshall Clow		return __str_rfind<value_type, size_type, traits_type, npos>
437*053d81ceSMarshall Clow			(data(), size(), __s, __pos, traits_type::length(__s));
438*053d81ceSMarshall Clow	}
439*053d81ceSMarshall Clow
440*053d81ceSMarshall Clow	// find_first_of
441*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
442*053d81ceSMarshall Clow	size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
443*053d81ceSMarshall Clow	{
444*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
445*053d81ceSMarshall Clow		return __str_find_first_of<value_type, size_type, traits_type, npos>
446*053d81ceSMarshall Clow			(data(), size(), __s.data(), __pos, __s.size());
447*053d81ceSMarshall Clow	}
448*053d81ceSMarshall Clow
449*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
450*053d81ceSMarshall Clow	size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT
451*053d81ceSMarshall Clow	{ return find(__c, __pos); }
452*053d81ceSMarshall Clow
453*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
454*053d81ceSMarshall Clow	size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
455*053d81ceSMarshall Clow	{
456*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
457*053d81ceSMarshall Clow		return __str_find_first_of<value_type, size_type, traits_type, npos>
458*053d81ceSMarshall Clow			(data(), size(), __s, __pos, __n);
459*053d81ceSMarshall Clow	}
460*053d81ceSMarshall Clow
461*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
462*053d81ceSMarshall Clow	size_type find_first_of(const _CharT* __s, size_type __pos=0) const
463*053d81ceSMarshall Clow	{
464*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr");
465*053d81ceSMarshall Clow		return __str_find_first_of<value_type, size_type, traits_type, npos>
466*053d81ceSMarshall Clow			(data(), size(), __s, __pos, traits_type::length(__s));
467*053d81ceSMarshall Clow	}
468*053d81ceSMarshall Clow
469*053d81ceSMarshall Clow	// find_last_of
470*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
471*053d81ceSMarshall Clow	size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
472*053d81ceSMarshall Clow	{
473*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
474*053d81ceSMarshall Clow		return __str_find_last_of<value_type, size_type, traits_type, npos>
475*053d81ceSMarshall Clow			(data(), size(), __s.data(), __pos, __s.size());
476*053d81ceSMarshall Clow	}
477*053d81ceSMarshall Clow
478*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
479*053d81ceSMarshall Clow	size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT
480*053d81ceSMarshall Clow	{ return rfind(__c, __pos); }
481*053d81ceSMarshall Clow
482*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
483*053d81ceSMarshall Clow	size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
484*053d81ceSMarshall Clow	{
485*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
486*053d81ceSMarshall Clow		return __str_find_last_of<value_type, size_type, traits_type, npos>
487*053d81ceSMarshall Clow			(data(), size(), __s, __pos, __n);
488*053d81ceSMarshall Clow	}
489*053d81ceSMarshall Clow
490*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
491*053d81ceSMarshall Clow	size_type find_last_of(const _CharT* __s, size_type __pos=npos) const
492*053d81ceSMarshall Clow	{
493*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr");
494*053d81ceSMarshall Clow		return __str_find_last_of<value_type, size_type, traits_type, npos>
495*053d81ceSMarshall Clow			(data(), size(), __s, __pos, traits_type::length(__s));
496*053d81ceSMarshall Clow	}
497*053d81ceSMarshall Clow
498*053d81ceSMarshall Clow	// find_first_not_of
499*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
500*053d81ceSMarshall Clow	size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT
501*053d81ceSMarshall Clow	{
502*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
503*053d81ceSMarshall Clow		return __str_find_first_not_of<value_type, size_type, traits_type, npos>
504*053d81ceSMarshall Clow			(data(), size(), __s.data(), __pos, __s.size());
505*053d81ceSMarshall Clow	}
506*053d81ceSMarshall Clow
507*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
508*053d81ceSMarshall Clow	size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT
509*053d81ceSMarshall Clow	{
510*053d81ceSMarshall Clow		return __str_find_first_not_of<value_type, size_type, traits_type, npos>
511*053d81ceSMarshall Clow			(data(), size(), __c, __pos);
512*053d81ceSMarshall Clow	}
513*053d81ceSMarshall Clow
514*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
515*053d81ceSMarshall Clow	size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
516*053d81ceSMarshall Clow	{
517*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
518*053d81ceSMarshall Clow		return __str_find_first_not_of<value_type, size_type, traits_type, npos>
519*053d81ceSMarshall Clow			(data(), size(), __s, __pos, __n);
520*053d81ceSMarshall Clow	}
521*053d81ceSMarshall Clow
522*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
523*053d81ceSMarshall Clow	size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const
524*053d81ceSMarshall Clow	{
525*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
526*053d81ceSMarshall Clow		return __str_find_first_not_of<value_type, size_type, traits_type, npos>
527*053d81ceSMarshall Clow			(data(), size(), __s, __pos, traits_type::length(__s));
528*053d81ceSMarshall Clow	}
529*053d81ceSMarshall Clow
530*053d81ceSMarshall Clow	// find_last_not_of
531*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
532*053d81ceSMarshall Clow	size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
533*053d81ceSMarshall Clow	{
534*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
535*053d81ceSMarshall Clow		return __str_find_last_not_of<value_type, size_type, traits_type, npos>
536*053d81ceSMarshall Clow			(data(), size(), __s.data(), __pos, __s.size());
537*053d81ceSMarshall Clow	}
538*053d81ceSMarshall Clow
539*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
540*053d81ceSMarshall Clow	size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT
541*053d81ceSMarshall Clow	{
542*053d81ceSMarshall Clow		return __str_find_last_not_of<value_type, size_type, traits_type, npos>
543*053d81ceSMarshall Clow			(data(), size(), __c, __pos);
544*053d81ceSMarshall Clow	}
545*053d81ceSMarshall Clow
546*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
547*053d81ceSMarshall Clow	size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
548*053d81ceSMarshall Clow	{
549*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
550*053d81ceSMarshall Clow		return __str_find_last_not_of<value_type, size_type, traits_type, npos>
551*053d81ceSMarshall Clow			(data(), size(), __s, __pos, __n);
552*053d81ceSMarshall Clow	}
553*053d81ceSMarshall Clow
554*053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
555*053d81ceSMarshall Clow	size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const
556*053d81ceSMarshall Clow	{
557*053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
558*053d81ceSMarshall Clow		return __str_find_last_not_of<value_type, size_type, traits_type, npos>
559*053d81ceSMarshall Clow			(data(), size(), __s, __pos, traits_type::length(__s));
560*053d81ceSMarshall Clow	}
561*053d81ceSMarshall Clow
562*053d81ceSMarshall Clowprivate:
563*053d81ceSMarshall Clow	const   value_type* __data;
564*053d81ceSMarshall Clow	size_type           __size;
565*053d81ceSMarshall Clow};
566*053d81ceSMarshall Clow
567*053d81ceSMarshall Clow
568*053d81ceSMarshall Clow// [string.view.comparison]
569*053d81ceSMarshall Clow// operator ==
570*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
571*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
572*053d81ceSMarshall Clowbool operator==(basic_string_view<_CharT, _Traits> __lhs,
573*053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
574*053d81ceSMarshall Clow{
575*053d81ceSMarshall Clow	if ( __lhs.size() != __rhs.size()) return false;
576*053d81ceSMarshall Clow	return __lhs.compare(__rhs) == 0;
577*053d81ceSMarshall Clow}
578*053d81ceSMarshall Clow
579*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
580*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
581*053d81ceSMarshall Clowbool operator==(basic_string_view<_CharT, _Traits> __lhs,
582*053d81ceSMarshall Clow				typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
583*053d81ceSMarshall Clow{
584*053d81ceSMarshall Clow	if ( __lhs.size() != __rhs.size()) return false;
585*053d81ceSMarshall Clow	return __lhs.compare(__rhs) == 0;
586*053d81ceSMarshall Clow}
587*053d81ceSMarshall Clow
588*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
589*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
590*053d81ceSMarshall Clowbool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
591*053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
592*053d81ceSMarshall Clow{
593*053d81ceSMarshall Clow	if ( __lhs.size() != __rhs.size()) return false;
594*053d81ceSMarshall Clow	return __lhs.compare(__rhs) == 0;
595*053d81ceSMarshall Clow}
596*053d81ceSMarshall Clow
597*053d81ceSMarshall Clow
598*053d81ceSMarshall Clow// operator !=
599*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
600*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
601*053d81ceSMarshall Clowbool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
602*053d81ceSMarshall Clow{
603*053d81ceSMarshall Clow	if ( __lhs.size() != __rhs.size())
604*053d81ceSMarshall Clow		return true;
605*053d81ceSMarshall Clow	return __lhs.compare(__rhs) != 0;
606*053d81ceSMarshall Clow}
607*053d81ceSMarshall Clow
608*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
609*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
610*053d81ceSMarshall Clowbool operator!=(basic_string_view<_CharT, _Traits> __lhs,
611*053d81ceSMarshall Clow				typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
612*053d81ceSMarshall Clow{
613*053d81ceSMarshall Clow	if ( __lhs.size() != __rhs.size())
614*053d81ceSMarshall Clow		return true;
615*053d81ceSMarshall Clow	return __lhs.compare(__rhs) != 0;
616*053d81ceSMarshall Clow}
617*053d81ceSMarshall Clow
618*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
619*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
620*053d81ceSMarshall Clowbool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
621*053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
622*053d81ceSMarshall Clow{
623*053d81ceSMarshall Clow	if ( __lhs.size() != __rhs.size())
624*053d81ceSMarshall Clow		return true;
625*053d81ceSMarshall Clow	return __lhs.compare(__rhs) != 0;
626*053d81ceSMarshall Clow}
627*053d81ceSMarshall Clow
628*053d81ceSMarshall Clow
629*053d81ceSMarshall Clow// operator <
630*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
631*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
632*053d81ceSMarshall Clowbool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
633*053d81ceSMarshall Clow{
634*053d81ceSMarshall Clow	return __lhs.compare(__rhs) < 0;
635*053d81ceSMarshall Clow}
636*053d81ceSMarshall Clow
637*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
638*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
639*053d81ceSMarshall Clowbool operator<(basic_string_view<_CharT, _Traits> __lhs,
640*053d81ceSMarshall Clow				typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
641*053d81ceSMarshall Clow{
642*053d81ceSMarshall Clow	return __lhs.compare(__rhs) < 0;
643*053d81ceSMarshall Clow}
644*053d81ceSMarshall Clow
645*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
646*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
647*053d81ceSMarshall Clowbool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
648*053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
649*053d81ceSMarshall Clow{
650*053d81ceSMarshall Clow	return __lhs.compare(__rhs) < 0;
651*053d81ceSMarshall Clow}
652*053d81ceSMarshall Clow
653*053d81ceSMarshall Clow
654*053d81ceSMarshall Clow// operator >
655*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
656*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
657*053d81ceSMarshall Clowbool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
658*053d81ceSMarshall Clow{
659*053d81ceSMarshall Clow	return __lhs.compare(__rhs) > 0;
660*053d81ceSMarshall Clow}
661*053d81ceSMarshall Clow
662*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
663*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
664*053d81ceSMarshall Clowbool operator>(basic_string_view<_CharT, _Traits> __lhs,
665*053d81ceSMarshall Clow				typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
666*053d81ceSMarshall Clow{
667*053d81ceSMarshall Clow	return __lhs.compare(__rhs) > 0;
668*053d81ceSMarshall Clow}
669*053d81ceSMarshall Clow
670*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
671*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
672*053d81ceSMarshall Clowbool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
673*053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
674*053d81ceSMarshall Clow{
675*053d81ceSMarshall Clow	return __lhs.compare(__rhs) > 0;
676*053d81ceSMarshall Clow}
677*053d81ceSMarshall Clow
678*053d81ceSMarshall Clow
679*053d81ceSMarshall Clow// operator <=
680*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
681*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
682*053d81ceSMarshall Clowbool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
683*053d81ceSMarshall Clow{
684*053d81ceSMarshall Clow	return __lhs.compare(__rhs) <= 0;
685*053d81ceSMarshall Clow}
686*053d81ceSMarshall Clow
687*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
688*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
689*053d81ceSMarshall Clowbool operator<=(basic_string_view<_CharT, _Traits> __lhs,
690*053d81ceSMarshall Clow				typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
691*053d81ceSMarshall Clow{
692*053d81ceSMarshall Clow	return __lhs.compare(__rhs) <= 0;
693*053d81ceSMarshall Clow}
694*053d81ceSMarshall Clow
695*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
696*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
697*053d81ceSMarshall Clowbool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
698*053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
699*053d81ceSMarshall Clow{
700*053d81ceSMarshall Clow	return __lhs.compare(__rhs) <= 0;
701*053d81ceSMarshall Clow}
702*053d81ceSMarshall Clow
703*053d81ceSMarshall Clow
704*053d81ceSMarshall Clow// operator >=
705*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
706*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
707*053d81ceSMarshall Clowbool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
708*053d81ceSMarshall Clow{
709*053d81ceSMarshall Clow	return __lhs.compare(__rhs) >= 0;
710*053d81ceSMarshall Clow}
711*053d81ceSMarshall Clow
712*053d81ceSMarshall Clow
713*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
714*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
715*053d81ceSMarshall Clowbool operator>=(basic_string_view<_CharT, _Traits> __lhs,
716*053d81ceSMarshall Clow				typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
717*053d81ceSMarshall Clow{
718*053d81ceSMarshall Clow	return __lhs.compare(__rhs) >= 0;
719*053d81ceSMarshall Clow}
720*053d81ceSMarshall Clow
721*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
722*053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
723*053d81ceSMarshall Clowbool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
724*053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
725*053d81ceSMarshall Clow{
726*053d81ceSMarshall Clow	return __lhs.compare(__rhs) >= 0;
727*053d81ceSMarshall Clow}
728*053d81ceSMarshall Clow
729*053d81ceSMarshall Clowtypedef basic_string_view<char>     string_view;
730*053d81ceSMarshall Clowtypedef basic_string_view<char16_t> u16string_view;
731*053d81ceSMarshall Clowtypedef basic_string_view<char32_t> u32string_view;
732*053d81ceSMarshall Clowtypedef basic_string_view<wchar_t>  wstring_view;
733*053d81ceSMarshall Clow
734*053d81ceSMarshall Clow// [string.view.hash]
735*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
736*053d81ceSMarshall Clowstruct _LIBCPP_TYPE_VIS_ONLY hash<basic_string_view<_CharT, _Traits> >
737*053d81ceSMarshall Clow    : public unary_function<basic_string_view<_CharT, _Traits>, size_t>
738*053d81ceSMarshall Clow{
739*053d81ceSMarshall Clow    size_t operator()(const basic_string_view<_CharT, _Traits> __val) const _NOEXCEPT;
740*053d81ceSMarshall Clow};
741*053d81ceSMarshall Clow
742*053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
743*053d81ceSMarshall Clowsize_t
744*053d81ceSMarshall Clowhash<basic_string_view<_CharT, _Traits> >::operator()(
745*053d81ceSMarshall Clow        const basic_string_view<_CharT, _Traits> __val) const _NOEXCEPT
746*053d81ceSMarshall Clow{
747*053d81ceSMarshall Clow    return __do_string_hash(__val.data(), __val.data() + __val.size());
748*053d81ceSMarshall Clow}
749*053d81ceSMarshall Clow
750*053d81ceSMarshall Clow#if _LIBCPP_STD_VER > 11
751*053d81ceSMarshall Clow
752*053d81ceSMarshall Clowtemplate <class _CharT, class _Traits>
753*053d81ceSMarshall Clow__quoted_output_proxy<_CharT, const _CharT *, _Traits>
754*053d81ceSMarshall Clowquoted (basic_string_view <_CharT, _Traits> __sv,
755*053d81ceSMarshall Clow             _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
756*053d81ceSMarshall Clow{
757*053d81ceSMarshall Clow    return __quoted_output_proxy<_CharT, const _CharT *, _Traits>
758*053d81ceSMarshall Clow         ( __sv.data(), __sv.data() + __sv.size(), __delim, __escape );
759*053d81ceSMarshall Clow}
760*053d81ceSMarshall Clow#endif // _LIBCPP_STD_VER > 11
761*053d81ceSMarshall Clow
762*053d81ceSMarshall Clow_LIBCPP_END_NAMESPACE_STD
763*053d81ceSMarshall Clow
764*053d81ceSMarshall Clow#endif // _LIBCPP_STRING_VIEW
765