1053d81ceSMarshall Clow// -*- C++ -*-
2053d81ceSMarshall Clow//===------------------------ string_view ---------------------------------===//
3053d81ceSMarshall Clow//
4053d81ceSMarshall Clow//                     The LLVM Compiler Infrastructure
5053d81ceSMarshall Clow//
6053d81ceSMarshall Clow// This file is distributed under the University of Illinois Open Source
7053d81ceSMarshall Clow// License. See LICENSE.TXT for details.
8053d81ceSMarshall Clow//
9053d81ceSMarshall Clow//===----------------------------------------------------------------------===//
10053d81ceSMarshall Clow
11053d81ceSMarshall Clow#ifndef _LIBCPP_STRING_VIEW
12053d81ceSMarshall Clow#define _LIBCPP_STRING_VIEW
13053d81ceSMarshall Clow
14053d81ceSMarshall Clow/*
15053d81ceSMarshall Clowstring_view synopsis
16053d81ceSMarshall Clow
17053d81ceSMarshall Clownamespace std {
18053d81ceSMarshall Clow
19053d81ceSMarshall Clow    // 7.2, Class template basic_string_view
20053d81ceSMarshall Clow    template<class charT, class traits = char_traits<charT>>
21053d81ceSMarshall Clow        class basic_string_view;
22053d81ceSMarshall Clow
23053d81ceSMarshall Clow    // 7.9, basic_string_view non-member comparison functions
24053d81ceSMarshall Clow    template<class charT, class traits>
25053d81ceSMarshall Clow    constexpr bool operator==(basic_string_view<charT, traits> x,
26053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
27053d81ceSMarshall Clow    template<class charT, class traits>
28053d81ceSMarshall Clow    constexpr bool operator!=(basic_string_view<charT, traits> x,
29053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
30053d81ceSMarshall Clow    template<class charT, class traits>
31053d81ceSMarshall Clow    constexpr bool operator< (basic_string_view<charT, traits> x,
32053d81ceSMarshall Clow                                 basic_string_view<charT, traits> y) noexcept;
33053d81ceSMarshall Clow    template<class charT, class traits>
34053d81ceSMarshall Clow    constexpr bool operator> (basic_string_view<charT, traits> x,
35053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
36053d81ceSMarshall Clow    template<class charT, class traits>
37053d81ceSMarshall Clow    constexpr bool operator<=(basic_string_view<charT, traits> x,
38053d81ceSMarshall Clow                                 basic_string_view<charT, traits> y) noexcept;
39053d81ceSMarshall Clow    template<class charT, class traits>
40053d81ceSMarshall Clow    constexpr bool operator>=(basic_string_view<charT, traits> x,
41053d81ceSMarshall Clow                              basic_string_view<charT, traits> y) noexcept;
42053d81ceSMarshall Clow    // see below, sufficient additional overloads of comparison functions
43053d81ceSMarshall Clow
44053d81ceSMarshall Clow    // 7.10, Inserters and extractors
45053d81ceSMarshall Clow    template<class charT, class traits>
46053d81ceSMarshall Clow      basic_ostream<charT, traits>&
47053d81ceSMarshall Clow        operator<<(basic_ostream<charT, traits>& os,
48053d81ceSMarshall Clow                   basic_string_view<charT, traits> str);
49053d81ceSMarshall Clow
50053d81ceSMarshall Clow    // basic_string_view typedef names
51053d81ceSMarshall Clow    typedef basic_string_view<char> string_view;
52053d81ceSMarshall Clow    typedef basic_string_view<char16_t> u16string_view;
53053d81ceSMarshall Clow    typedef basic_string_view<char32_t> u32string_view;
54053d81ceSMarshall Clow    typedef basic_string_view<wchar_t> wstring_view;
55053d81ceSMarshall Clow
56053d81ceSMarshall Clow    template<class charT, class traits = char_traits<charT>>
57053d81ceSMarshall Clow    class basic_string_view {
58053d81ceSMarshall Clow      public:
59053d81ceSMarshall Clow      // types
60053d81ceSMarshall Clow      typedef traits traits_type;
61053d81ceSMarshall Clow      typedef charT value_type;
62053d81ceSMarshall Clow      typedef charT* pointer;
63053d81ceSMarshall Clow      typedef const charT* const_pointer;
64053d81ceSMarshall Clow      typedef charT& reference;
65053d81ceSMarshall Clow      typedef const charT& const_reference;
66053d81ceSMarshall Clow      typedef implementation-defined const_iterator;
67053d81ceSMarshall Clow      typedef const_iterator iterator;
68053d81ceSMarshall Clow      typedef reverse_iterator<const_iterator> const_reverse_iterator;
69053d81ceSMarshall Clow      typedef const_reverse_iterator reverse_iterator;
70053d81ceSMarshall Clow      typedef size_t size_type;
71053d81ceSMarshall Clow      typedef ptrdiff_t difference_type;
72053d81ceSMarshall Clow      static constexpr size_type npos = size_type(-1);
73053d81ceSMarshall Clow
74053d81ceSMarshall Clow      // 7.3, basic_string_view constructors and assignment operators
75053d81ceSMarshall Clow      constexpr basic_string_view() noexcept;
76053d81ceSMarshall Clow      constexpr basic_string_view(const basic_string_view&) noexcept = default;
77053d81ceSMarshall Clow      basic_string_view& operator=(const basic_string_view&) noexcept = default;
78053d81ceSMarshall Clow      template<class Allocator>
79053d81ceSMarshall Clow      constexpr basic_string_view(const charT* str);
80053d81ceSMarshall Clow      constexpr basic_string_view(const charT* str, size_type len);
81053d81ceSMarshall Clow
82053d81ceSMarshall Clow      // 7.4, basic_string_view iterator support
83053d81ceSMarshall Clow      constexpr const_iterator begin() const noexcept;
84053d81ceSMarshall Clow      constexpr const_iterator end() const noexcept;
85053d81ceSMarshall Clow      constexpr const_iterator cbegin() const noexcept;
86053d81ceSMarshall Clow      constexpr const_iterator cend() const noexcept;
87053d81ceSMarshall Clow      const_reverse_iterator rbegin() const noexcept;
88053d81ceSMarshall Clow      const_reverse_iterator rend() const noexcept;
89053d81ceSMarshall Clow      const_reverse_iterator crbegin() const noexcept;
90053d81ceSMarshall Clow      const_reverse_iterator crend() const noexcept;
91053d81ceSMarshall Clow
92053d81ceSMarshall Clow      // 7.5, basic_string_view capacity
93053d81ceSMarshall Clow      constexpr size_type size() const noexcept;
94053d81ceSMarshall Clow      constexpr size_type length() const noexcept;
95053d81ceSMarshall Clow      constexpr size_type max_size() const noexcept;
96053d81ceSMarshall Clow      constexpr bool empty() const noexcept;
97053d81ceSMarshall Clow
98053d81ceSMarshall Clow      // 7.6, basic_string_view element access
99053d81ceSMarshall Clow      constexpr const_reference operator[](size_type pos) const;
100053d81ceSMarshall Clow      constexpr const_reference at(size_type pos) const;
101053d81ceSMarshall Clow      constexpr const_reference front() const;
102053d81ceSMarshall Clow      constexpr const_reference back() const;
103053d81ceSMarshall Clow      constexpr const_pointer data() const noexcept;
104053d81ceSMarshall Clow
105053d81ceSMarshall Clow      // 7.7, basic_string_view modifiers
106053d81ceSMarshall Clow      constexpr void clear() noexcept;
107053d81ceSMarshall Clow      constexpr void remove_prefix(size_type n);
108053d81ceSMarshall Clow      constexpr void remove_suffix(size_type n);
109053d81ceSMarshall Clow      constexpr void swap(basic_string_view& s) noexcept;
110053d81ceSMarshall Clow
111053d81ceSMarshall Clow      size_type copy(charT* s, size_type n, size_type pos = 0) const;
112053d81ceSMarshall Clow
113053d81ceSMarshall Clow      constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
114053d81ceSMarshall Clow      constexpr int compare(basic_string_view s) const noexcept;
115053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
116053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1,
117053d81ceSMarshall Clow                            basic_string_view s, size_type pos2, size_type n2) const;
118053d81ceSMarshall Clow      constexpr int compare(const charT* s) const;
119053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
120053d81ceSMarshall Clow      constexpr int compare(size_type pos1, size_type n1,
121053d81ceSMarshall Clow                            const charT* s, size_type n2) const;
122053d81ceSMarshall Clow      constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
123053d81ceSMarshall Clow      constexpr size_type find(charT c, size_type pos = 0) const noexcept;
124053d81ceSMarshall Clow      constexpr size_type find(const charT* s, size_type pos, size_type n) const;
125053d81ceSMarshall Clow      constexpr size_type find(const charT* s, size_type pos = 0) const;
126053d81ceSMarshall Clow      constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
127053d81ceSMarshall Clow      constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
128053d81ceSMarshall Clow      constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
129053d81ceSMarshall Clow      constexpr size_type rfind(const charT* s, size_type pos = npos) const;
130053d81ceSMarshall Clow      constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
131053d81ceSMarshall Clow      constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
132053d81ceSMarshall Clow      constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
133053d81ceSMarshall Clow      constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
134053d81ceSMarshall Clow      constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
135053d81ceSMarshall Clow      constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
136053d81ceSMarshall Clow      constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const;
137053d81ceSMarshall Clow      constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;
138053d81ceSMarshall Clow      constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
139053d81ceSMarshall Clow      constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
140053d81ceSMarshall Clow      constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
141053d81ceSMarshall Clow      constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const;
142053d81ceSMarshall Clow      constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
143053d81ceSMarshall Clow      constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
144053d81ceSMarshall Clow      constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
145053d81ceSMarshall Clow      constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
146053d81ceSMarshall Clow
147053d81ceSMarshall Clow     private:
148053d81ceSMarshall Clow      const_pointer data_;  // exposition only
149053d81ceSMarshall Clow      size_type     size_;  // exposition only
150053d81ceSMarshall Clow    };
151053d81ceSMarshall Clow
152053d81ceSMarshall Clow  // 7.11, Hash support
153053d81ceSMarshall Clow  template <class T> struct hash;
154053d81ceSMarshall Clow  template <> struct hash<string_view>;
155053d81ceSMarshall Clow  template <> struct hash<u16string_view>;
156053d81ceSMarshall Clow  template <> struct hash<u32string_view>;
157053d81ceSMarshall Clow  template <> struct hash<wstring_view>;
158053d81ceSMarshall Clow
159053d81ceSMarshall Clow}  // namespace std
160053d81ceSMarshall Clow
161053d81ceSMarshall Clow
162053d81ceSMarshall Clow*/
163053d81ceSMarshall Clow
164053d81ceSMarshall Clow#include <__config>
165053d81ceSMarshall Clow
166053d81ceSMarshall Clow#include <__string>
167053d81ceSMarshall Clow#include <algorithm>
168053d81ceSMarshall Clow#include <iterator>
169053d81ceSMarshall Clow#include <__debug>
170053d81ceSMarshall Clow
171053d81ceSMarshall Clow#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
172053d81ceSMarshall Clow#pragma GCC system_header
173053d81ceSMarshall Clow#endif
174053d81ceSMarshall Clow
175053d81ceSMarshall Clow_LIBCPP_BEGIN_NAMESPACE_STD
176053d81ceSMarshall Clow
177053d81ceSMarshall Clowtemplate<class _CharT, class _Traits = char_traits<_CharT> >
178053d81ceSMarshall Clowclass _LIBCPP_TYPE_VIS_ONLY basic_string_view {
179053d81ceSMarshall Clowpublic:
180053d81ceSMarshall Clow	// types
181053d81ceSMarshall Clow	typedef _Traits                                    traits_type;
182053d81ceSMarshall Clow	typedef _CharT                                     value_type;
183053d81ceSMarshall Clow	typedef const _CharT*                              pointer;
184053d81ceSMarshall Clow	typedef const _CharT*                              const_pointer;
185053d81ceSMarshall Clow	typedef const _CharT&                              reference;
186053d81ceSMarshall Clow	typedef const _CharT&                              const_reference;
187053d81ceSMarshall Clow	typedef const_pointer                              const_iterator; // See [string.view.iterators]
188053d81ceSMarshall Clow	typedef const_iterator                             iterator;
189053d81ceSMarshall Clow	typedef _VSTD::reverse_iterator<const_iterator>    const_reverse_iterator;
190053d81ceSMarshall Clow	typedef const_reverse_iterator                     reverse_iterator;
191053d81ceSMarshall Clow	typedef size_t                                     size_type;
192053d81ceSMarshall Clow	typedef ptrdiff_t                                  difference_type;
193053d81ceSMarshall Clow	static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
194053d81ceSMarshall Clow
195053d81ceSMarshall Clow	// [string.view.cons], construct/copy
196053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
197053d81ceSMarshall Clow	basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {}
198053d81ceSMarshall Clow
199053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
200053d81ceSMarshall Clow	basic_string_view(const basic_string_view&) _NOEXCEPT = default;
201053d81ceSMarshall Clow
202053d81ceSMarshall Clow	_LIBCPP_INLINE_VISIBILITY
203053d81ceSMarshall Clow	basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
204053d81ceSMarshall Clow
205053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
206053d81ceSMarshall Clow	basic_string_view(const _CharT* __s, size_type __len)
207053d81ceSMarshall Clow		: __data(__s), __size(__len)
208053d81ceSMarshall Clow	{
209187db169SMarshall Clow// #if _LIBCPP_STD_VER > 11
210187db169SMarshall Clow//         _LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
211187db169SMarshall Clow// #endif
212053d81ceSMarshall Clow	}
213053d81ceSMarshall Clow
214053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
215053d81ceSMarshall Clow	basic_string_view(const _CharT* __s)
216053d81ceSMarshall Clow		: __data(__s), __size(_Traits::length(__s)) {}
217053d81ceSMarshall Clow
218053d81ceSMarshall Clow	// [string.view.iterators], iterators
219053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
220053d81ceSMarshall Clow	const_iterator begin()  const _NOEXCEPT { return cbegin(); }
221053d81ceSMarshall Clow
222053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
223053d81ceSMarshall Clow	const_iterator end()    const _NOEXCEPT { return cend(); }
224053d81ceSMarshall Clow
225053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
226053d81ceSMarshall Clow	const_iterator cbegin() const _NOEXCEPT { return __data; }
227053d81ceSMarshall Clow
228053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
229053d81ceSMarshall Clow	const_iterator cend()   const _NOEXCEPT { return __data + __size; }
230053d81ceSMarshall Clow
231053d81ceSMarshall Clow	_LIBCPP_INLINE_VISIBILITY
232053d81ceSMarshall Clow	const_reverse_iterator rbegin()   const _NOEXCEPT { return const_reverse_iterator(cend()); }
233053d81ceSMarshall Clow
234053d81ceSMarshall Clow	_LIBCPP_INLINE_VISIBILITY
235053d81ceSMarshall Clow	const_reverse_iterator rend()     const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
236053d81ceSMarshall Clow
237053d81ceSMarshall Clow	_LIBCPP_INLINE_VISIBILITY
238053d81ceSMarshall Clow	const_reverse_iterator crbegin()  const _NOEXCEPT { return const_reverse_iterator(cend()); }
239053d81ceSMarshall Clow
240053d81ceSMarshall Clow	_LIBCPP_INLINE_VISIBILITY
241053d81ceSMarshall Clow	const_reverse_iterator crend()    const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
242053d81ceSMarshall Clow
243053d81ceSMarshall Clow	// [string.view.capacity], capacity
244053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
245053d81ceSMarshall Clow	size_type size()     const _NOEXCEPT { return __size; }
246053d81ceSMarshall Clow
247053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
248053d81ceSMarshall Clow	size_type length()   const _NOEXCEPT { return __size; }
249053d81ceSMarshall Clow
250053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
251053d81ceSMarshall Clow	size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max(); }
252053d81ceSMarshall Clow
253053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR bool _LIBCPP_INLINE_VISIBILITY
254053d81ceSMarshall Clow	empty()         const _NOEXCEPT { return __size == 0; }
255053d81ceSMarshall Clow
256053d81ceSMarshall Clow	// [string.view.access], element access
257053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
258053d81ceSMarshall Clow	const_reference operator[](size_type __pos) const _NOEXCEPT { return __data[__pos]; }
259053d81ceSMarshall Clow
260053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
261053d81ceSMarshall Clow	const_reference at(size_type __pos) const
262053d81ceSMarshall Clow	{
263053d81ceSMarshall Clow		return __pos >= size()
264*0fc8cec7SMarshall Clow			? (__throw_out_of_range("string_view::at"), __data[0])
265053d81ceSMarshall Clow			: __data[__pos];
266053d81ceSMarshall Clow	}
267053d81ceSMarshall Clow
268053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
269053d81ceSMarshall Clow	const_reference front() const
270053d81ceSMarshall Clow	{
271053d81ceSMarshall Clow		return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0];
272053d81ceSMarshall Clow	}
273053d81ceSMarshall Clow
274053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
275053d81ceSMarshall Clow	const_reference back() const
276053d81ceSMarshall Clow	{
277053d81ceSMarshall Clow		return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1];
278053d81ceSMarshall Clow	}
279053d81ceSMarshall Clow
280053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
281053d81ceSMarshall Clow	const_pointer data() const _NOEXCEPT { return __data; }
282053d81ceSMarshall Clow
283053d81ceSMarshall Clow	// [string.view.modifiers], modifiers:
284053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
285053d81ceSMarshall Clow	void clear() _NOEXCEPT
286053d81ceSMarshall Clow	{
287053d81ceSMarshall Clow		__data = nullptr;
288053d81ceSMarshall Clow		__size = 0;
289053d81ceSMarshall Clow	}
290053d81ceSMarshall Clow
291053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
292053d81ceSMarshall Clow	void remove_prefix(size_type __n) _NOEXCEPT
293053d81ceSMarshall Clow	{
294053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()");
295053d81ceSMarshall Clow		__data += __n;
296053d81ceSMarshall Clow		__size -= __n;
297053d81ceSMarshall Clow	}
298053d81ceSMarshall Clow
299053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
300053d81ceSMarshall Clow	void remove_suffix(size_type __n) _NOEXCEPT
301053d81ceSMarshall Clow	{
302053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()");
303053d81ceSMarshall Clow		__size -= __n;
304053d81ceSMarshall Clow	}
305053d81ceSMarshall Clow
306053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
307053d81ceSMarshall Clow	void swap(basic_string_view& __other) _NOEXCEPT
308053d81ceSMarshall Clow	{
309053d81ceSMarshall Clow		const value_type *__p = __data;
310053d81ceSMarshall Clow		__data = __other.__data;
311053d81ceSMarshall Clow		__other.__data = __p;
312053d81ceSMarshall Clow
313053d81ceSMarshall Clow		size_type __sz = __size;
314053d81ceSMarshall Clow		__size = __other.__size;
315053d81ceSMarshall Clow		__other.__size = __sz;
316053d81ceSMarshall Clow	}
317053d81ceSMarshall Clow
318053d81ceSMarshall Clow	_LIBCPP_INLINE_VISIBILITY
319053d81ceSMarshall Clow	size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const
320053d81ceSMarshall Clow	{
321053d81ceSMarshall Clow		if (__pos > size())
322*0fc8cec7SMarshall Clow			__throw_out_of_range("string_view::copy");
323053d81ceSMarshall Clow		size_type __rlen = _VSTD::min( __n, size() - __pos );
324053d81ceSMarshall Clow		copy_n(begin() + __pos, __rlen, __s );
325053d81ceSMarshall Clow		return __rlen;
326053d81ceSMarshall Clow	}
327053d81ceSMarshall Clow
328053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
329053d81ceSMarshall Clow	basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
330053d81ceSMarshall Clow	{
331053d81ceSMarshall Clow		return __pos > size()
332*0fc8cec7SMarshall Clow			? (__throw_out_of_range("string_view::substr"), basic_string_view())
333053d81ceSMarshall Clow			: basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos));
334053d81ceSMarshall Clow	}
335053d81ceSMarshall Clow
336053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT
337053d81ceSMarshall Clow	{
338053d81ceSMarshall Clow		size_type __rlen = _VSTD::min( size(), __sv.size());
339053d81ceSMarshall Clow		int __retval = _Traits::compare(data(), __sv.data(), __rlen);
340053d81ceSMarshall Clow		if ( __retval == 0 ) // first __rlen chars matched
341053d81ceSMarshall Clow			__retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 );
342053d81ceSMarshall Clow		return __retval;
343053d81ceSMarshall Clow	}
344053d81ceSMarshall Clow
345053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
346053d81ceSMarshall Clow	int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const
347053d81ceSMarshall Clow	{
348053d81ceSMarshall Clow		return substr(__pos1, __n1).compare(__sv);
349053d81ceSMarshall Clow	}
350053d81ceSMarshall Clow
351053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
352053d81ceSMarshall Clow	int compare(                       size_type __pos1, size_type __n1,
353053d81ceSMarshall Clow				basic_string_view _sv, size_type __pos2, size_type __n2) const
354053d81ceSMarshall Clow	{
355053d81ceSMarshall Clow		return substr(__pos1, __n1).compare(_sv.substr(__pos2, __n2));
356053d81ceSMarshall Clow	}
357053d81ceSMarshall Clow
358053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
359aa849bc2SMarshall Clow	int compare(const _CharT* __s) const _NOEXCEPT
360053d81ceSMarshall Clow	{
361053d81ceSMarshall Clow		return compare(basic_string_view(__s));
362053d81ceSMarshall Clow	}
363053d81ceSMarshall Clow
364053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
365053d81ceSMarshall Clow	int compare(size_type __pos1, size_type __n1, const _CharT* __s) const
366053d81ceSMarshall Clow	{
367053d81ceSMarshall Clow		return substr(__pos1, __n1).compare(basic_string_view(__s));
368053d81ceSMarshall Clow	}
369053d81ceSMarshall Clow
370053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
371053d81ceSMarshall Clow	int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
372053d81ceSMarshall Clow	{
373053d81ceSMarshall Clow		return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
374053d81ceSMarshall Clow	}
375053d81ceSMarshall Clow
376053d81ceSMarshall Clow	// find
377053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
378053d81ceSMarshall Clow	size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
379053d81ceSMarshall Clow	{
380053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
381053d81ceSMarshall Clow		return __str_find<value_type, size_type, traits_type, npos>
382053d81ceSMarshall Clow			(data(), size(), __s.data(), __pos, __s.size());
383053d81ceSMarshall Clow	}
384053d81ceSMarshall Clow
385053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
386053d81ceSMarshall Clow	size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT
387053d81ceSMarshall Clow	{
388053d81ceSMarshall Clow		return __str_find<value_type, size_type, traits_type, npos>
389053d81ceSMarshall Clow			(data(), size(), __c, __pos);
390053d81ceSMarshall Clow	}
391053d81ceSMarshall Clow
392053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
393053d81ceSMarshall Clow	size_type find(const _CharT* __s, size_type __pos, size_type __n) const
394053d81ceSMarshall Clow	{
395053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
396053d81ceSMarshall Clow		return __str_find<value_type, size_type, traits_type, npos>
397053d81ceSMarshall Clow			(data(), size(), __s, __pos, __n);
398053d81ceSMarshall Clow	}
399053d81ceSMarshall Clow
400053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
401053d81ceSMarshall Clow	size_type find(const _CharT* __s, size_type __pos = 0) const
402053d81ceSMarshall Clow	{
403053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr");
404053d81ceSMarshall Clow		return __str_find<value_type, size_type, traits_type, npos>
405053d81ceSMarshall Clow			(data(), size(), __s, __pos, traits_type::length(__s));
406053d81ceSMarshall Clow	}
407053d81ceSMarshall Clow
408053d81ceSMarshall Clow	// rfind
409053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
410053d81ceSMarshall Clow	size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT
411053d81ceSMarshall Clow	{
412053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
413053d81ceSMarshall Clow		return __str_rfind<value_type, size_type, traits_type, npos>
414053d81ceSMarshall Clow			(data(), size(), __s.data(), __pos, __s.size());
415053d81ceSMarshall Clow	}
416053d81ceSMarshall Clow
417053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
418053d81ceSMarshall Clow	size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT
419053d81ceSMarshall Clow	{
420053d81ceSMarshall Clow		return __str_rfind<value_type, size_type, traits_type, npos>
421053d81ceSMarshall Clow			(data(), size(), __c, __pos);
422053d81ceSMarshall Clow	}
423053d81ceSMarshall Clow
424053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
425053d81ceSMarshall Clow	size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const
426053d81ceSMarshall Clow	{
427053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
428053d81ceSMarshall Clow		return __str_rfind<value_type, size_type, traits_type, npos>
429053d81ceSMarshall Clow			(data(), size(), __s, __pos, __n);
430053d81ceSMarshall Clow	}
431053d81ceSMarshall Clow
432053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
433053d81ceSMarshall Clow	size_type rfind(const _CharT* __s, size_type __pos=npos) const
434053d81ceSMarshall Clow	{
435053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr");
436053d81ceSMarshall Clow		return __str_rfind<value_type, size_type, traits_type, npos>
437053d81ceSMarshall Clow			(data(), size(), __s, __pos, traits_type::length(__s));
438053d81ceSMarshall Clow	}
439053d81ceSMarshall Clow
440053d81ceSMarshall Clow	// find_first_of
441053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
442053d81ceSMarshall Clow	size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
443053d81ceSMarshall Clow	{
444053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
445053d81ceSMarshall Clow		return __str_find_first_of<value_type, size_type, traits_type, npos>
446053d81ceSMarshall Clow			(data(), size(), __s.data(), __pos, __s.size());
447053d81ceSMarshall Clow	}
448053d81ceSMarshall Clow
449053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
450053d81ceSMarshall Clow	size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT
451053d81ceSMarshall Clow	{ return find(__c, __pos); }
452053d81ceSMarshall Clow
453053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
454053d81ceSMarshall Clow	size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
455053d81ceSMarshall Clow	{
456053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
457053d81ceSMarshall Clow		return __str_find_first_of<value_type, size_type, traits_type, npos>
458053d81ceSMarshall Clow			(data(), size(), __s, __pos, __n);
459053d81ceSMarshall Clow	}
460053d81ceSMarshall Clow
461053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
462053d81ceSMarshall Clow	size_type find_first_of(const _CharT* __s, size_type __pos=0) const
463053d81ceSMarshall Clow	{
464053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr");
465053d81ceSMarshall Clow		return __str_find_first_of<value_type, size_type, traits_type, npos>
466053d81ceSMarshall Clow			(data(), size(), __s, __pos, traits_type::length(__s));
467053d81ceSMarshall Clow	}
468053d81ceSMarshall Clow
469053d81ceSMarshall Clow	// find_last_of
470053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
471053d81ceSMarshall Clow	size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
472053d81ceSMarshall Clow	{
473053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
474053d81ceSMarshall Clow		return __str_find_last_of<value_type, size_type, traits_type, npos>
475053d81ceSMarshall Clow			(data(), size(), __s.data(), __pos, __s.size());
476053d81ceSMarshall Clow	}
477053d81ceSMarshall Clow
478053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
479053d81ceSMarshall Clow	size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT
480053d81ceSMarshall Clow	{ return rfind(__c, __pos); }
481053d81ceSMarshall Clow
482053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
483053d81ceSMarshall Clow	size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
484053d81ceSMarshall Clow	{
485053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
486053d81ceSMarshall Clow		return __str_find_last_of<value_type, size_type, traits_type, npos>
487053d81ceSMarshall Clow			(data(), size(), __s, __pos, __n);
488053d81ceSMarshall Clow	}
489053d81ceSMarshall Clow
490053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
491053d81ceSMarshall Clow	size_type find_last_of(const _CharT* __s, size_type __pos=npos) const
492053d81ceSMarshall Clow	{
493053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr");
494053d81ceSMarshall Clow		return __str_find_last_of<value_type, size_type, traits_type, npos>
495053d81ceSMarshall Clow			(data(), size(), __s, __pos, traits_type::length(__s));
496053d81ceSMarshall Clow	}
497053d81ceSMarshall Clow
498053d81ceSMarshall Clow	// find_first_not_of
499053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
500053d81ceSMarshall Clow	size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT
501053d81ceSMarshall Clow	{
502053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
503053d81ceSMarshall Clow		return __str_find_first_not_of<value_type, size_type, traits_type, npos>
504053d81ceSMarshall Clow			(data(), size(), __s.data(), __pos, __s.size());
505053d81ceSMarshall Clow	}
506053d81ceSMarshall Clow
507053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
508053d81ceSMarshall Clow	size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT
509053d81ceSMarshall Clow	{
510053d81ceSMarshall Clow		return __str_find_first_not_of<value_type, size_type, traits_type, npos>
511053d81ceSMarshall Clow			(data(), size(), __c, __pos);
512053d81ceSMarshall Clow	}
513053d81ceSMarshall Clow
514053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
515053d81ceSMarshall Clow	size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
516053d81ceSMarshall Clow	{
517053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
518053d81ceSMarshall Clow		return __str_find_first_not_of<value_type, size_type, traits_type, npos>
519053d81ceSMarshall Clow			(data(), size(), __s, __pos, __n);
520053d81ceSMarshall Clow	}
521053d81ceSMarshall Clow
522053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
523053d81ceSMarshall Clow	size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const
524053d81ceSMarshall Clow	{
525053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
526053d81ceSMarshall Clow		return __str_find_first_not_of<value_type, size_type, traits_type, npos>
527053d81ceSMarshall Clow			(data(), size(), __s, __pos, traits_type::length(__s));
528053d81ceSMarshall Clow	}
529053d81ceSMarshall Clow
530053d81ceSMarshall Clow	// find_last_not_of
531053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
532053d81ceSMarshall Clow	size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
533053d81ceSMarshall Clow	{
534053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
535053d81ceSMarshall Clow		return __str_find_last_not_of<value_type, size_type, traits_type, npos>
536053d81ceSMarshall Clow			(data(), size(), __s.data(), __pos, __s.size());
537053d81ceSMarshall Clow	}
538053d81ceSMarshall Clow
539053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
540053d81ceSMarshall Clow	size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT
541053d81ceSMarshall Clow	{
542053d81ceSMarshall Clow		return __str_find_last_not_of<value_type, size_type, traits_type, npos>
543053d81ceSMarshall Clow			(data(), size(), __c, __pos);
544053d81ceSMarshall Clow	}
545053d81ceSMarshall Clow
546053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
547053d81ceSMarshall Clow	size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
548053d81ceSMarshall Clow	{
549053d81ceSMarshall Clow		_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
550053d81ceSMarshall Clow		return __str_find_last_not_of<value_type, size_type, traits_type, npos>
551053d81ceSMarshall Clow			(data(), size(), __s, __pos, __n);
552053d81ceSMarshall Clow	}
553053d81ceSMarshall Clow
554053d81ceSMarshall Clow	_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
555053d81ceSMarshall Clow	size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const
556053d81ceSMarshall Clow	{
557053d81ceSMarshall Clow		_LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
558053d81ceSMarshall Clow		return __str_find_last_not_of<value_type, size_type, traits_type, npos>
559053d81ceSMarshall Clow			(data(), size(), __s, __pos, traits_type::length(__s));
560053d81ceSMarshall Clow	}
561053d81ceSMarshall Clow
562053d81ceSMarshall Clowprivate:
563053d81ceSMarshall Clow	const   value_type* __data;
564053d81ceSMarshall Clow	size_type           __size;
565053d81ceSMarshall Clow};
566053d81ceSMarshall Clow
567053d81ceSMarshall Clow
568053d81ceSMarshall Clow// [string.view.comparison]
569053d81ceSMarshall Clow// operator ==
570053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
571053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
572053d81ceSMarshall Clowbool operator==(basic_string_view<_CharT, _Traits> __lhs,
573053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
574053d81ceSMarshall Clow{
575053d81ceSMarshall Clow	if ( __lhs.size() != __rhs.size()) return false;
576053d81ceSMarshall Clow	return __lhs.compare(__rhs) == 0;
577053d81ceSMarshall Clow}
578053d81ceSMarshall Clow
579053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
580053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
581053d81ceSMarshall Clowbool operator==(basic_string_view<_CharT, _Traits> __lhs,
582053d81ceSMarshall Clow				typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
583053d81ceSMarshall Clow{
584053d81ceSMarshall Clow	if ( __lhs.size() != __rhs.size()) return false;
585053d81ceSMarshall Clow	return __lhs.compare(__rhs) == 0;
586053d81ceSMarshall Clow}
587053d81ceSMarshall Clow
588053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
589053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
590053d81ceSMarshall Clowbool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
591053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
592053d81ceSMarshall Clow{
593053d81ceSMarshall Clow	if ( __lhs.size() != __rhs.size()) return false;
594053d81ceSMarshall Clow	return __lhs.compare(__rhs) == 0;
595053d81ceSMarshall Clow}
596053d81ceSMarshall Clow
597053d81ceSMarshall Clow
598053d81ceSMarshall Clow// operator !=
599053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
600053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
601053d81ceSMarshall Clowbool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
602053d81ceSMarshall Clow{
603053d81ceSMarshall Clow	if ( __lhs.size() != __rhs.size())
604053d81ceSMarshall Clow		return true;
605053d81ceSMarshall Clow	return __lhs.compare(__rhs) != 0;
606053d81ceSMarshall Clow}
607053d81ceSMarshall Clow
608053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
609053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
610053d81ceSMarshall Clowbool operator!=(basic_string_view<_CharT, _Traits> __lhs,
611053d81ceSMarshall Clow				typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
612053d81ceSMarshall Clow{
613053d81ceSMarshall Clow	if ( __lhs.size() != __rhs.size())
614053d81ceSMarshall Clow		return true;
615053d81ceSMarshall Clow	return __lhs.compare(__rhs) != 0;
616053d81ceSMarshall Clow}
617053d81ceSMarshall Clow
618053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
619053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
620053d81ceSMarshall Clowbool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
621053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
622053d81ceSMarshall Clow{
623053d81ceSMarshall Clow	if ( __lhs.size() != __rhs.size())
624053d81ceSMarshall Clow		return true;
625053d81ceSMarshall Clow	return __lhs.compare(__rhs) != 0;
626053d81ceSMarshall Clow}
627053d81ceSMarshall Clow
628053d81ceSMarshall Clow
629053d81ceSMarshall Clow// operator <
630053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
631053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
632053d81ceSMarshall Clowbool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
633053d81ceSMarshall Clow{
634053d81ceSMarshall Clow	return __lhs.compare(__rhs) < 0;
635053d81ceSMarshall Clow}
636053d81ceSMarshall Clow
637053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
638053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
639053d81ceSMarshall Clowbool operator<(basic_string_view<_CharT, _Traits> __lhs,
640053d81ceSMarshall Clow				typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
641053d81ceSMarshall Clow{
642053d81ceSMarshall Clow	return __lhs.compare(__rhs) < 0;
643053d81ceSMarshall Clow}
644053d81ceSMarshall Clow
645053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
646053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
647053d81ceSMarshall Clowbool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
648053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
649053d81ceSMarshall Clow{
650053d81ceSMarshall Clow	return __lhs.compare(__rhs) < 0;
651053d81ceSMarshall Clow}
652053d81ceSMarshall Clow
653053d81ceSMarshall Clow
654053d81ceSMarshall Clow// operator >
655053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
656053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
657053d81ceSMarshall Clowbool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
658053d81ceSMarshall Clow{
659053d81ceSMarshall Clow	return __lhs.compare(__rhs) > 0;
660053d81ceSMarshall Clow}
661053d81ceSMarshall Clow
662053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
663053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
664053d81ceSMarshall Clowbool operator>(basic_string_view<_CharT, _Traits> __lhs,
665053d81ceSMarshall Clow				typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
666053d81ceSMarshall Clow{
667053d81ceSMarshall Clow	return __lhs.compare(__rhs) > 0;
668053d81ceSMarshall Clow}
669053d81ceSMarshall Clow
670053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
671053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
672053d81ceSMarshall Clowbool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
673053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
674053d81ceSMarshall Clow{
675053d81ceSMarshall Clow	return __lhs.compare(__rhs) > 0;
676053d81ceSMarshall Clow}
677053d81ceSMarshall Clow
678053d81ceSMarshall Clow
679053d81ceSMarshall Clow// operator <=
680053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
681053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
682053d81ceSMarshall Clowbool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
683053d81ceSMarshall Clow{
684053d81ceSMarshall Clow	return __lhs.compare(__rhs) <= 0;
685053d81ceSMarshall Clow}
686053d81ceSMarshall Clow
687053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
688053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
689053d81ceSMarshall Clowbool operator<=(basic_string_view<_CharT, _Traits> __lhs,
690053d81ceSMarshall Clow				typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
691053d81ceSMarshall Clow{
692053d81ceSMarshall Clow	return __lhs.compare(__rhs) <= 0;
693053d81ceSMarshall Clow}
694053d81ceSMarshall Clow
695053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
696053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
697053d81ceSMarshall Clowbool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
698053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
699053d81ceSMarshall Clow{
700053d81ceSMarshall Clow	return __lhs.compare(__rhs) <= 0;
701053d81ceSMarshall Clow}
702053d81ceSMarshall Clow
703053d81ceSMarshall Clow
704053d81ceSMarshall Clow// operator >=
705053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
706053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
707053d81ceSMarshall Clowbool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
708053d81ceSMarshall Clow{
709053d81ceSMarshall Clow	return __lhs.compare(__rhs) >= 0;
710053d81ceSMarshall Clow}
711053d81ceSMarshall Clow
712053d81ceSMarshall Clow
713053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
714053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
715053d81ceSMarshall Clowbool operator>=(basic_string_view<_CharT, _Traits> __lhs,
716053d81ceSMarshall Clow				typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
717053d81ceSMarshall Clow{
718053d81ceSMarshall Clow	return __lhs.compare(__rhs) >= 0;
719053d81ceSMarshall Clow}
720053d81ceSMarshall Clow
721053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
722053d81ceSMarshall Clow_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
723053d81ceSMarshall Clowbool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
724053d81ceSMarshall Clow				basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
725053d81ceSMarshall Clow{
726053d81ceSMarshall Clow	return __lhs.compare(__rhs) >= 0;
727053d81ceSMarshall Clow}
728053d81ceSMarshall Clow
729053d81ceSMarshall Clowtypedef basic_string_view<char>     string_view;
730053d81ceSMarshall Clowtypedef basic_string_view<char16_t> u16string_view;
731053d81ceSMarshall Clowtypedef basic_string_view<char32_t> u32string_view;
732053d81ceSMarshall Clowtypedef basic_string_view<wchar_t>  wstring_view;
733053d81ceSMarshall Clow
734053d81ceSMarshall Clow// [string.view.hash]
735053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
736053d81ceSMarshall Clowstruct _LIBCPP_TYPE_VIS_ONLY hash<basic_string_view<_CharT, _Traits> >
737053d81ceSMarshall Clow    : public unary_function<basic_string_view<_CharT, _Traits>, size_t>
738053d81ceSMarshall Clow{
739053d81ceSMarshall Clow    size_t operator()(const basic_string_view<_CharT, _Traits> __val) const _NOEXCEPT;
740053d81ceSMarshall Clow};
741053d81ceSMarshall Clow
742053d81ceSMarshall Clowtemplate<class _CharT, class _Traits>
743053d81ceSMarshall Clowsize_t
744053d81ceSMarshall Clowhash<basic_string_view<_CharT, _Traits> >::operator()(
745053d81ceSMarshall Clow        const basic_string_view<_CharT, _Traits> __val) const _NOEXCEPT
746053d81ceSMarshall Clow{
747053d81ceSMarshall Clow    return __do_string_hash(__val.data(), __val.data() + __val.size());
748053d81ceSMarshall Clow}
749053d81ceSMarshall Clow
750053d81ceSMarshall Clow#if _LIBCPP_STD_VER > 11
751053d81ceSMarshall Clow
752053d81ceSMarshall Clowtemplate <class _CharT, class _Traits>
753053d81ceSMarshall Clow__quoted_output_proxy<_CharT, const _CharT *, _Traits>
754053d81ceSMarshall Clowquoted (basic_string_view <_CharT, _Traits> __sv,
755053d81ceSMarshall Clow             _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
756053d81ceSMarshall Clow{
757053d81ceSMarshall Clow    return __quoted_output_proxy<_CharT, const _CharT *, _Traits>
758053d81ceSMarshall Clow         ( __sv.data(), __sv.data() + __sv.size(), __delim, __escape );
759053d81ceSMarshall Clow}
760053d81ceSMarshall Clow#endif // _LIBCPP_STD_VER > 11
761053d81ceSMarshall Clow
762053d81ceSMarshall Clow_LIBCPP_END_NAMESPACE_STD
763053d81ceSMarshall Clow
764053d81ceSMarshall Clow#endif // _LIBCPP_STRING_VIEW
765