]> git.proxmox.com Git - ceph.git/blame_incremental - ceph/src/boost/boost/utility/string_view.hpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / boost / utility / string_view.hpp
... / ...
CommitLineData
1/*
2 Copyright (c) Marshall Clow 2012-2015.
3 Copyright (c) Beman Dawes 2015
4 Copyright (c) Glen Joseph Fernandes 2019 (glenjofe@gmail.com)
5
6 Distributed under the Boost Software License, Version 1.0. (See accompanying
7 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8
9 For more information, see http://www.boost.org
10
11 Based on the StringRef implementation in LLVM (http://llvm.org) and
12 N3422 by Jeffrey Yasskin
13 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3442.html
14 Updated July 2015 to reflect the Library Fundamentals TS
15 http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4480.html
16*/
17
18#ifndef BOOST_STRING_VIEW_HPP
19#define BOOST_STRING_VIEW_HPP
20
21#include <boost/config.hpp>
22#include <boost/detail/workaround.hpp>
23#include <boost/io/ostream_put.hpp>
24#include <boost/utility/string_view_fwd.hpp>
25#include <boost/throw_exception.hpp>
26
27#include <cstddef>
28#include <stdexcept>
29#include <algorithm>
30#include <iterator>
31#include <string>
32#include <cstring>
33#include <iosfwd>
34
35#if defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) || (defined(BOOST_GCC) && ((BOOST_GCC+0) / 100) <= 406)
36// GCC 4.6 cannot handle a defaulted function with noexcept specifier
37#define BOOST_STRING_VIEW_NO_CXX11_DEFAULTED_NOEXCEPT_FUNCTIONS
38#endif
39
40namespace boost {
41
42 namespace detail {
43 // A helper functor because sometimes we don't have lambdas
44 template <typename charT, typename traits>
45 class string_view_traits_eq {
46 public:
47 string_view_traits_eq ( charT ch ) : ch_(ch) {}
48 bool operator()( charT val ) const { return traits::eq (ch_, val); }
49 charT ch_;
50 };
51 }
52
53 template<typename charT, typename traits> // traits defaulted in string_view_fwd.hpp
54 class basic_string_view {
55 public:
56 // types
57 typedef traits traits_type;
58 typedef charT value_type;
59 typedef charT* pointer;
60 typedef const charT* const_pointer;
61 typedef charT& reference;
62 typedef const charT& const_reference;
63 typedef const_pointer const_iterator; // impl-defined
64 typedef const_iterator iterator;
65 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
66 typedef const_reverse_iterator reverse_iterator;
67 typedef std::size_t size_type;
68 typedef std::ptrdiff_t difference_type;
69 static BOOST_CONSTEXPR_OR_CONST size_type npos = size_type(-1);
70
71 // construct/copy
72 BOOST_CONSTEXPR basic_string_view() BOOST_NOEXCEPT
73 : ptr_(NULL), len_(0) {}
74
75 // by defaulting these functions, basic_string_ref becomes
76 // trivially copy/move constructible.
77 BOOST_CONSTEXPR basic_string_view(const basic_string_view &rhs) BOOST_NOEXCEPT
78#ifndef BOOST_STRING_VIEW_NO_CXX11_DEFAULTED_NOEXCEPT_FUNCTIONS
79 = default;
80#else
81 : ptr_(rhs.ptr_), len_(rhs.len_) {}
82#endif
83
84 basic_string_view& operator=(const basic_string_view &rhs) BOOST_NOEXCEPT
85#ifndef BOOST_STRING_VIEW_NO_CXX11_DEFAULTED_NOEXCEPT_FUNCTIONS
86 = default;
87#else
88 {
89 ptr_ = rhs.ptr_;
90 len_ = rhs.len_;
91 return *this;
92 }
93#endif
94
95 template<typename Allocator>
96 basic_string_view(const std::basic_string<charT, traits, Allocator>& str) BOOST_NOEXCEPT
97 : ptr_(str.data()), len_(str.length()) {}
98
99// #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
100// // Constructing a string_view from a temporary string is a bad idea
101// template<typename Allocator>
102// basic_string_view( std::basic_string<charT, traits, Allocator>&&)
103// = delete;
104// #endif
105
106 BOOST_CONSTEXPR basic_string_view(const charT* str)
107 : ptr_(str), len_(traits::length(str)) {}
108
109 BOOST_CONSTEXPR basic_string_view(const charT* str, size_type len)
110 : ptr_(str), len_(len) {}
111
112 // iterators
113 BOOST_CONSTEXPR const_iterator begin() const BOOST_NOEXCEPT { return ptr_; }
114 BOOST_CONSTEXPR const_iterator cbegin() const BOOST_NOEXCEPT { return ptr_; }
115 BOOST_CONSTEXPR const_iterator end() const BOOST_NOEXCEPT { return ptr_ + len_; }
116 BOOST_CONSTEXPR const_iterator cend() const BOOST_NOEXCEPT { return ptr_ + len_; }
117 const_reverse_iterator rbegin() const BOOST_NOEXCEPT { return const_reverse_iterator(end()); }
118 const_reverse_iterator crbegin() const BOOST_NOEXCEPT { return const_reverse_iterator(end()); }
119 const_reverse_iterator rend() const BOOST_NOEXCEPT { return const_reverse_iterator(begin()); }
120 const_reverse_iterator crend() const BOOST_NOEXCEPT { return const_reverse_iterator(begin()); }
121
122 // capacity
123 BOOST_CONSTEXPR size_type size() const BOOST_NOEXCEPT { return len_; }
124 BOOST_CONSTEXPR size_type length() const BOOST_NOEXCEPT { return len_; }
125 BOOST_CONSTEXPR size_type max_size() const BOOST_NOEXCEPT { return len_; }
126 BOOST_CONSTEXPR bool empty() const BOOST_NOEXCEPT { return len_ == 0; }
127
128 // element access
129 BOOST_CONSTEXPR const_reference operator[](size_type pos) const BOOST_NOEXCEPT { return ptr_[pos]; }
130
131 BOOST_CONSTEXPR const_reference at(size_t pos) const {
132 return pos >= len_ ? BOOST_THROW_EXCEPTION(std::out_of_range("boost::string_view::at")), ptr_[0] : ptr_[pos];
133 }
134
135 BOOST_CONSTEXPR const_reference front() const { return ptr_[0]; }
136 BOOST_CONSTEXPR const_reference back() const { return ptr_[len_-1]; }
137 BOOST_CONSTEXPR const_pointer data() const BOOST_NOEXCEPT { return ptr_; }
138
139 // modifiers
140 void clear() BOOST_NOEXCEPT { len_ = 0; } // Boost extension
141
142 BOOST_CXX14_CONSTEXPR void remove_prefix(size_type n) {
143 if ( n > len_ )
144 n = len_;
145 ptr_ += n;
146 len_ -= n;
147 }
148
149 BOOST_CXX14_CONSTEXPR void remove_suffix(size_type n) {
150 if ( n > len_ )
151 n = len_;
152 len_ -= n;
153 }
154
155 BOOST_CXX14_CONSTEXPR void swap(basic_string_view& s) BOOST_NOEXCEPT {
156 std::swap(ptr_, s.ptr_);
157 std::swap(len_, s.len_);
158 }
159
160 // basic_string_view string operations
161#ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
162 template<typename Allocator>
163 explicit operator std::basic_string<charT, traits, Allocator>() const {
164 return std::basic_string<charT, traits, Allocator>(begin(), end());
165 }
166#endif
167
168#ifndef BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS
169 template<typename Allocator = std::allocator<charT> >
170 std::basic_string<charT, traits, Allocator> to_string(const Allocator& a = Allocator()) const {
171 return std::basic_string<charT, traits, Allocator>(begin(), end(), a);
172 }
173#else
174 std::basic_string<charT, traits> to_string() const {
175 return std::basic_string<charT, traits>(begin(), end());
176 }
177
178 template<typename Allocator>
179 std::basic_string<charT, traits, Allocator> to_string(const Allocator& a) const {
180 return std::basic_string<charT, traits, Allocator>(begin(), end(), a);
181 }
182#endif
183
184 size_type copy(charT* s, size_type n, size_type pos=0) const {
185 if (pos > size())
186 BOOST_THROW_EXCEPTION(std::out_of_range("string_view::copy" ));
187 size_type rlen = (std::min)(n, len_ - pos);
188 traits_type::copy(s, data() + pos, rlen);
189 return rlen;
190 }
191
192 BOOST_CXX14_CONSTEXPR basic_string_view substr(size_type pos, size_type n=npos) const {
193 if ( pos > size())
194 BOOST_THROW_EXCEPTION( std::out_of_range ( "string_view::substr" ) );
195 return basic_string_view(data() + pos, (std::min)(size() - pos, n));
196 }
197
198 BOOST_CXX14_CONSTEXPR int compare(basic_string_view x) const BOOST_NOEXCEPT {
199 const int cmp = traits::compare(ptr_, x.ptr_, (std::min)(len_, x.len_));
200 return cmp != 0 ? cmp : (len_ == x.len_ ? 0 : len_ < x.len_ ? -1 : 1);
201 }
202
203 BOOST_CXX14_CONSTEXPR int compare(size_type pos1, size_type n1, basic_string_view x)
204 const BOOST_NOEXCEPT {
205 return substr(pos1, n1).compare(x);
206 }
207
208 BOOST_CXX14_CONSTEXPR int compare(size_type pos1, size_type n1,
209 basic_string_view x, size_type pos2, size_type n2) const {
210 return substr(pos1, n1).compare(x.substr(pos2, n2));
211 }
212
213 BOOST_CXX14_CONSTEXPR int compare(const charT* x) const {
214 return compare(basic_string_view(x));
215 }
216
217 BOOST_CXX14_CONSTEXPR int compare(size_type pos1, size_type n1, const charT* x) const {
218 return substr(pos1, n1).compare(basic_string_view(x));
219 }
220
221 BOOST_CXX14_CONSTEXPR int compare(size_type pos1, size_type n1,
222 const charT* x, size_type n2) const {
223 return substr(pos1, n1).compare(basic_string_view(x, n2));
224 }
225
226 // Searches
227 BOOST_CONSTEXPR bool starts_with(charT c) const BOOST_NOEXCEPT { // Boost extension
228 return !empty() && traits::eq(c, front());
229 }
230
231 BOOST_CONSTEXPR bool starts_with(basic_string_view x) const BOOST_NOEXCEPT { // Boost extension
232 return len_ >= x.len_ && traits::compare(ptr_, x.ptr_, x.len_) == 0;
233 }
234
235 BOOST_CONSTEXPR bool ends_with(charT c) const BOOST_NOEXCEPT { // Boost extension
236 return !empty() && traits::eq(c, back());
237 }
238
239 BOOST_CONSTEXPR bool ends_with(basic_string_view x) const BOOST_NOEXCEPT { // Boost extension
240 return len_ >= x.len_ &&
241 traits::compare(ptr_ + len_ - x.len_, x.ptr_, x.len_) == 0;
242 }
243
244 // find
245 BOOST_CXX14_CONSTEXPR size_type find(basic_string_view s, size_type pos = 0) const BOOST_NOEXCEPT {
246 if (pos > size())
247 return npos;
248 if (s.empty())
249 return pos;
250 if (s.size() > size() - pos)
251 return npos;
252 const charT* cur = ptr_ + pos;
253 const charT* last = cend() - s.size() + 1;
254 for (; cur != last ; ++cur) {
255 cur = traits::find(cur, last - cur, s[0]);
256 if (!cur)
257 return npos;
258 if (traits::compare(cur, s.cbegin(), s.size()) == 0)
259 return cur - ptr_;
260 }
261 return npos;
262 }
263 BOOST_CXX14_CONSTEXPR size_type find(charT c, size_type pos = 0) const BOOST_NOEXCEPT {
264 if (pos > size())
265 return npos;
266 const charT* ret_ptr = traits::find(ptr_ + pos, len_ - pos, c);
267 if (ret_ptr)
268 return ret_ptr - ptr_;
269 return npos;
270 }
271 BOOST_CXX14_CONSTEXPR size_type find(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
272 { return find(basic_string_view(s, n), pos); }
273 BOOST_CXX14_CONSTEXPR size_type find(const charT* s, size_type pos = 0) const BOOST_NOEXCEPT
274 { return find(basic_string_view(s), pos); }
275
276 // rfind
277 BOOST_CXX14_CONSTEXPR size_type rfind(basic_string_view s, size_type pos = npos) const BOOST_NOEXCEPT {
278 if (len_ < s.len_)
279 return npos;
280 if (pos > len_ - s.len_)
281 pos = len_ - s.len_;
282 if (s.len_ == 0u) // an empty string is always found
283 return pos;
284 for (const charT* cur = ptr_ + pos; ; --cur) {
285 if (traits::compare(cur, s.ptr_, s.len_) == 0)
286 return cur - ptr_;
287 if (cur == ptr_)
288 return npos;
289 };
290 }
291 BOOST_CXX14_CONSTEXPR size_type rfind(charT c, size_type pos = npos) const BOOST_NOEXCEPT
292 { return rfind(basic_string_view(&c, 1), pos); }
293 BOOST_CXX14_CONSTEXPR size_type rfind(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
294 { return rfind(basic_string_view(s, n), pos); }
295 BOOST_CXX14_CONSTEXPR size_type rfind(const charT* s, size_type pos = npos) const BOOST_NOEXCEPT
296 { return rfind(basic_string_view(s), pos); }
297
298 // find_first_of
299 BOOST_CXX14_CONSTEXPR size_type find_first_of(basic_string_view s, size_type pos = 0) const BOOST_NOEXCEPT {
300 if (pos >= len_ || s.len_ == 0)
301 return npos;
302 const_iterator iter = std::find_first_of
303 (this->cbegin () + pos, this->cend (), s.cbegin (), s.cend (), traits::eq);
304 return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
305 }
306 BOOST_CXX14_CONSTEXPR size_type find_first_of(charT c, size_type pos = 0) const BOOST_NOEXCEPT
307 { return find(c, pos); }
308 BOOST_CXX14_CONSTEXPR size_type find_first_of(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
309 { return find_first_of(basic_string_view(s, n), pos); }
310 BOOST_CXX14_CONSTEXPR size_type find_first_of(const charT* s, size_type pos = 0) const BOOST_NOEXCEPT
311 { return find_first_of(basic_string_view(s), pos); }
312
313 // find_last_of
314 BOOST_CXX14_CONSTEXPR size_type find_last_of(basic_string_view s, size_type pos = npos) const BOOST_NOEXCEPT {
315 if (s.len_ == 0u)
316 return npos;
317 if (pos >= len_)
318 pos = 0;
319 else
320 pos = len_ - (pos+1);
321 const_reverse_iterator iter = std::find_first_of
322 ( this->crbegin () + pos, this->crend (), s.cbegin (), s.cend (), traits::eq );
323 return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter);
324 }
325 BOOST_CXX14_CONSTEXPR size_type find_last_of(charT c, size_type pos = npos) const BOOST_NOEXCEPT
326 { return find_last_of(basic_string_view(&c, 1), pos); }
327 BOOST_CXX14_CONSTEXPR size_type find_last_of(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
328 { return find_last_of(basic_string_view(s, n), pos); }
329 BOOST_CXX14_CONSTEXPR size_type find_last_of(const charT* s, size_type pos = npos) const BOOST_NOEXCEPT
330 { return find_last_of(basic_string_view(s), pos); }
331
332 // find_first_not_of
333 BOOST_CXX14_CONSTEXPR size_type find_first_not_of(basic_string_view s, size_type pos = 0) const BOOST_NOEXCEPT {
334 if (pos >= len_)
335 return npos;
336 if (s.len_ == 0)
337 return pos;
338 const_iterator iter = find_not_of ( this->cbegin () + pos, this->cend (), s );
339 return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
340 }
341 BOOST_CXX14_CONSTEXPR size_type find_first_not_of(charT c, size_type pos = 0) const BOOST_NOEXCEPT
342 { return find_first_not_of(basic_string_view(&c, 1), pos); }
343 BOOST_CXX14_CONSTEXPR size_type find_first_not_of(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
344 { return find_first_not_of(basic_string_view(s, n), pos); }
345 BOOST_CXX14_CONSTEXPR size_type find_first_not_of(const charT* s, size_type pos = 0) const BOOST_NOEXCEPT
346 { return find_first_not_of(basic_string_view(s), pos); }
347
348 // find_last_not_of
349 BOOST_CXX14_CONSTEXPR size_type find_last_not_of(basic_string_view s, size_type pos = npos) const BOOST_NOEXCEPT {
350 if (pos >= len_)
351 pos = len_ - 1;
352 if (s.len_ == 0u)
353 return pos;
354 pos = len_ - (pos+1);
355 const_reverse_iterator iter = find_not_of ( this->crbegin () + pos, this->crend (), s );
356 return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter );
357 }
358 BOOST_CXX14_CONSTEXPR size_type find_last_not_of(charT c, size_type pos = npos) const BOOST_NOEXCEPT
359 { return find_last_not_of(basic_string_view(&c, 1), pos); }
360 BOOST_CXX14_CONSTEXPR size_type find_last_not_of(const charT* s, size_type pos, size_type n) const BOOST_NOEXCEPT
361 { return find_last_not_of(basic_string_view(s, n), pos); }
362 BOOST_CXX14_CONSTEXPR size_type find_last_not_of(const charT* s, size_type pos = npos) const BOOST_NOEXCEPT
363 { return find_last_not_of(basic_string_view(s), pos); }
364
365 private:
366 template <typename r_iter>
367 size_type reverse_distance(r_iter first, r_iter last) const BOOST_NOEXCEPT {
368 // Portability note here: std::distance is not NOEXCEPT, but calling it with a string_view::reverse_iterator will not throw.
369 return len_ - 1 - std::distance ( first, last );
370 }
371
372 template <typename Iterator>
373 Iterator find_not_of(Iterator first, Iterator last, basic_string_view s) const BOOST_NOEXCEPT {
374 for (; first != last ; ++first)
375 if ( 0 == traits::find(s.ptr_, s.len_, *first))
376 return first;
377 return last;
378 }
379
380 const charT *ptr_;
381 std::size_t len_;
382 };
383
384
385// Comparison operators
386// Equality
387 template<typename charT, typename traits>
388 inline BOOST_CXX14_CONSTEXPR bool operator==(basic_string_view<charT, traits> x,
389 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
390 if (x.size () != y.size ()) return false;
391 return x.compare(y) == 0;
392 }
393
394// Inequality
395 template<typename charT, typename traits>
396 inline BOOST_CXX14_CONSTEXPR bool operator!=(basic_string_view<charT, traits> x,
397 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
398 if ( x.size () != y.size ()) return true;
399 return x.compare(y) != 0;
400 }
401
402// Less than
403 template<typename charT, typename traits>
404 inline BOOST_CXX14_CONSTEXPR bool operator<(basic_string_view<charT, traits> x,
405 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
406 return x.compare(y) < 0;
407 }
408
409// Greater than
410 template<typename charT, typename traits>
411 inline BOOST_CXX14_CONSTEXPR bool operator>(basic_string_view<charT, traits> x,
412 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
413 return x.compare(y) > 0;
414 }
415
416// Less than or equal to
417 template<typename charT, typename traits>
418 inline BOOST_CXX14_CONSTEXPR bool operator<=(basic_string_view<charT, traits> x,
419 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
420 return x.compare(y) <= 0;
421 }
422
423// Greater than or equal to
424 template<typename charT, typename traits>
425 inline BOOST_CXX14_CONSTEXPR bool operator>=(basic_string_view<charT, traits> x,
426 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
427 return x.compare(y) >= 0;
428 }
429
430// "sufficient additional overloads of comparison functions"
431 template<typename charT, typename traits, typename Allocator>
432 inline BOOST_CXX14_CONSTEXPR bool operator==(basic_string_view<charT, traits> x,
433 const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
434 return x == basic_string_view<charT, traits>(y);
435 }
436
437 template<typename charT, typename traits, typename Allocator>
438 inline BOOST_CXX14_CONSTEXPR bool operator==(const std::basic_string<charT, traits, Allocator> & x,
439 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
440 return basic_string_view<charT, traits>(x) == y;
441 }
442
443 template<typename charT, typename traits>
444 inline BOOST_CXX14_CONSTEXPR bool operator==(basic_string_view<charT, traits> x,
445 const charT * y) BOOST_NOEXCEPT {
446 return x == basic_string_view<charT, traits>(y);
447 }
448
449 template<typename charT, typename traits>
450 inline BOOST_CXX14_CONSTEXPR bool operator==(const charT * x,
451 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
452 return basic_string_view<charT, traits>(x) == y;
453 }
454
455 template<typename charT, typename traits, typename Allocator>
456 inline BOOST_CXX14_CONSTEXPR bool operator!=(basic_string_view<charT, traits> x,
457 const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
458 return x != basic_string_view<charT, traits>(y);
459 }
460
461 template<typename charT, typename traits, typename Allocator>
462 inline BOOST_CXX14_CONSTEXPR bool operator!=(const std::basic_string<charT, traits, Allocator> & x,
463 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
464 return basic_string_view<charT, traits>(x) != y;
465 }
466
467 template<typename charT, typename traits>
468 inline BOOST_CXX14_CONSTEXPR bool operator!=(basic_string_view<charT, traits> x,
469 const charT * y) BOOST_NOEXCEPT {
470 return x != basic_string_view<charT, traits>(y);
471 }
472
473 template<typename charT, typename traits>
474 inline BOOST_CXX14_CONSTEXPR bool operator!=(const charT * x,
475 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
476 return basic_string_view<charT, traits>(x) != y;
477 }
478
479 template<typename charT, typename traits, typename Allocator>
480 inline BOOST_CXX14_CONSTEXPR bool operator<(basic_string_view<charT, traits> x,
481 const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
482 return x < basic_string_view<charT, traits>(y);
483 }
484
485 template<typename charT, typename traits, typename Allocator>
486 inline BOOST_CXX14_CONSTEXPR bool operator<(const std::basic_string<charT, traits, Allocator> & x,
487 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
488 return basic_string_view<charT, traits>(x) < y;
489 }
490
491 template<typename charT, typename traits>
492 inline BOOST_CXX14_CONSTEXPR bool operator<(basic_string_view<charT, traits> x,
493 const charT * y) BOOST_NOEXCEPT {
494 return x < basic_string_view<charT, traits>(y);
495 }
496
497 template<typename charT, typename traits>
498 inline BOOST_CXX14_CONSTEXPR bool operator<(const charT * x,
499 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
500 return basic_string_view<charT, traits>(x) < y;
501 }
502
503 template<typename charT, typename traits, typename Allocator>
504 inline BOOST_CXX14_CONSTEXPR bool operator>(basic_string_view<charT, traits> x,
505 const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
506 return x > basic_string_view<charT, traits>(y);
507 }
508
509 template<typename charT, typename traits, typename Allocator>
510 inline BOOST_CXX14_CONSTEXPR bool operator>(const std::basic_string<charT, traits, Allocator> & x,
511 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
512 return basic_string_view<charT, traits>(x) > y;
513 }
514
515 template<typename charT, typename traits>
516 inline BOOST_CXX14_CONSTEXPR bool operator>(basic_string_view<charT, traits> x,
517 const charT * y) BOOST_NOEXCEPT {
518 return x > basic_string_view<charT, traits>(y);
519 }
520
521 template<typename charT, typename traits>
522 inline BOOST_CXX14_CONSTEXPR bool operator>(const charT * x,
523 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
524 return basic_string_view<charT, traits>(x) > y;
525 }
526
527 template<typename charT, typename traits, typename Allocator>
528 inline BOOST_CXX14_CONSTEXPR bool operator<=(basic_string_view<charT, traits> x,
529 const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
530 return x <= basic_string_view<charT, traits>(y);
531 }
532
533 template<typename charT, typename traits, typename Allocator>
534 inline BOOST_CXX14_CONSTEXPR bool operator<=(const std::basic_string<charT, traits, Allocator> & x,
535 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
536 return basic_string_view<charT, traits>(x) <= y;
537 }
538
539 template<typename charT, typename traits>
540 inline BOOST_CXX14_CONSTEXPR bool operator<=(basic_string_view<charT, traits> x,
541 const charT * y) BOOST_NOEXCEPT {
542 return x <= basic_string_view<charT, traits>(y);
543 }
544
545 template<typename charT, typename traits>
546 inline BOOST_CXX14_CONSTEXPR bool operator<=(const charT * x,
547 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
548 return basic_string_view<charT, traits>(x) <= y;
549 }
550
551 template<typename charT, typename traits, typename Allocator>
552 inline BOOST_CXX14_CONSTEXPR bool operator>=(basic_string_view<charT, traits> x,
553 const std::basic_string<charT, traits, Allocator> & y) BOOST_NOEXCEPT {
554 return x >= basic_string_view<charT, traits>(y);
555 }
556
557 template<typename charT, typename traits, typename Allocator>
558 inline BOOST_CXX14_CONSTEXPR bool operator>=(const std::basic_string<charT, traits, Allocator> & x,
559 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
560 return basic_string_view<charT, traits>(x) >= y;
561 }
562
563 template<typename charT, typename traits>
564 inline BOOST_CXX14_CONSTEXPR bool operator>=(basic_string_view<charT, traits> x,
565 const charT * y) BOOST_NOEXCEPT {
566 return x >= basic_string_view<charT, traits>(y);
567 }
568
569 template<typename charT, typename traits>
570 inline BOOST_CXX14_CONSTEXPR bool operator>=(const charT * x,
571 basic_string_view<charT, traits> y) BOOST_NOEXCEPT {
572 return basic_string_view<charT, traits>(x) >= y;
573 }
574
575 // Inserter
576 template<class charT, class traits>
577 inline std::basic_ostream<charT, traits>&
578 operator<<(std::basic_ostream<charT, traits>& os,
579 const basic_string_view<charT,traits>& str) {
580 return boost::io::ostream_put(os, str.data(), str.size());
581 }
582
583#if 0
584 // numeric conversions
585 //
586 // These are short-term implementations.
587 // In a production environment, I would rather avoid the copying.
588 //
589 inline int stoi (string_view str, size_t* idx=0, int base=10) {
590 return std::stoi ( std::string(str), idx, base );
591 }
592
593 inline long stol (string_view str, size_t* idx=0, int base=10) {
594 return std::stol ( std::string(str), idx, base );
595 }
596
597 inline unsigned long stoul (string_view str, size_t* idx=0, int base=10) {
598 return std::stoul ( std::string(str), idx, base );
599 }
600
601 inline long long stoll (string_view str, size_t* idx=0, int base=10) {
602 return std::stoll ( std::string(str), idx, base );
603 }
604
605 inline unsigned long long stoull (string_view str, size_t* idx=0, int base=10) {
606 return std::stoull ( std::string(str), idx, base );
607 }
608
609 inline float stof (string_view str, size_t* idx=0) {
610 return std::stof ( std::string(str), idx );
611 }
612
613 inline double stod (string_view str, size_t* idx=0) {
614 return std::stod ( std::string(str), idx );
615 }
616
617 inline long double stold (string_view str, size_t* idx=0) {
618 return std::stold ( std::string(str), idx );
619 }
620
621 inline int stoi (wstring_view str, size_t* idx=0, int base=10) {
622 return std::stoi ( std::wstring(str), idx, base );
623 }
624
625 inline long stol (wstring_view str, size_t* idx=0, int base=10) {
626 return std::stol ( std::wstring(str), idx, base );
627 }
628
629 inline unsigned long stoul (wstring_view str, size_t* idx=0, int base=10) {
630 return std::stoul ( std::wstring(str), idx, base );
631 }
632
633 inline long long stoll (wstring_view str, size_t* idx=0, int base=10) {
634 return std::stoll ( std::wstring(str), idx, base );
635 }
636
637 inline unsigned long long stoull (wstring_view str, size_t* idx=0, int base=10) {
638 return std::stoull ( std::wstring(str), idx, base );
639 }
640
641 inline float stof (wstring_view str, size_t* idx=0) {
642 return std::stof ( std::wstring(str), idx );
643 }
644
645 inline double stod (wstring_view str, size_t* idx=0) {
646 return std::stod ( std::wstring(str), idx );
647 }
648
649 inline long double stold (wstring_view str, size_t* idx=0) {
650 return std::stold ( std::wstring(str), idx );
651 }
652#endif
653
654 // Forward declaration of Boost.ContainerHash function
655 template <class It> std::size_t hash_range(It, It);
656
657 template <class charT, class traits>
658 std::size_t hash_value(basic_string_view<charT, traits> s) {
659 return boost::hash_range(s.begin(), s.end());
660 }
661}
662
663#if 0
664namespace std {
665 // Hashing
666 template<> struct hash<boost::string_view>;
667 template<> struct hash<boost::u16string_view>;
668 template<> struct hash<boost::u32string_view>;
669 template<> struct hash<boost::wstring_view>;
670}
671#endif
672
673#endif