34#ifndef _GLIBCXX_EXPERIMENTAL_STRING_VIEW
35#define _GLIBCXX_EXPERIMENTAL_STRING_VIEW 1
38#pragma GCC system_header
43#if __cplusplus >= 201402L
50namespace std _GLIBCXX_VISIBILITY(default)
52_GLIBCXX_BEGIN_NAMESPACE_VERSION
56inline namespace fundamentals_v1
58#define __cpp_lib_experimental_string_view 201411
79 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>>
85 using traits_type = _Traits;
86 using value_type = _CharT;
87 using pointer = _CharT*;
88 using const_pointer =
const _CharT*;
89 using reference = _CharT&;
90 using const_reference =
const _CharT&;
91 using const_iterator =
const _CharT*;
95 using size_type = size_t;
96 using difference_type = ptrdiff_t;
97 static constexpr size_type npos = size_type(-1);
103 : _M_len{0}, _M_str{
nullptr}
108 template<
typename _Allocator>
110 _Allocator>& __str) noexcept
111 : _M_len{__str.length()}, _M_str{__str.data()}
115 : _M_len{__str ==
nullptr ? 0 : traits_type::length(__str)},
129 constexpr const_iterator
130 begin()
const noexcept
131 {
return this->_M_str; }
133 constexpr const_iterator
135 {
return this->_M_str + this->_M_len; }
137 constexpr const_iterator
138 cbegin()
const noexcept
139 {
return this->_M_str; }
141 constexpr const_iterator
142 cend()
const noexcept
143 {
return this->_M_str + this->_M_len; }
145 const_reverse_iterator
146 rbegin()
const noexcept
147 {
return const_reverse_iterator(this->end()); }
149 const_reverse_iterator
150 rend()
const noexcept
151 {
return const_reverse_iterator(this->begin()); }
153 const_reverse_iterator
154 crbegin()
const noexcept
155 {
return const_reverse_iterator(this->end()); }
157 const_reverse_iterator
158 crend()
const noexcept
159 {
return const_reverse_iterator(this->begin()); }
164 size()
const noexcept
165 {
return this->_M_len; }
168 length()
const noexcept
172 max_size()
const noexcept
174 return (npos -
sizeof(size_type) -
sizeof(
void*))
175 /
sizeof(value_type) / 4;
178 _GLIBCXX_NODISCARD
constexpr bool
179 empty()
const noexcept
180 {
return this->_M_len == 0; }
184 constexpr const _CharT&
185 operator[](size_type __pos)
const
187 __glibcxx_assert(__pos < this->_M_len);
188 return *(this->_M_str + __pos);
191 constexpr const _CharT&
192 at(size_type __pos)
const
194 return __pos < this->_M_len
195 ? *(this->_M_str + __pos)
196 : (__throw_out_of_range_fmt(__N(
"basic_string_view::at: __pos "
197 "(which is %zu) >= this->size() "
199 __pos, this->size()),
203 constexpr const _CharT&
206 __glibcxx_assert(this->_M_len > 0);
207 return *this->_M_str;
210 constexpr const _CharT&
213 __glibcxx_assert(this->_M_len > 0);
214 return *(this->_M_str + this->_M_len - 1);
217 constexpr const _CharT*
218 data()
const noexcept
219 {
return this->_M_str; }
224 remove_prefix(size_type __n)
226 __glibcxx_assert(this->_M_len >= __n);
232 remove_suffix(size_type __n)
233 { this->_M_len -= __n; }
246 template<
typename _Allocator>
249 return { this->_M_str, this->_M_len };
252 template<
typename _Allocator = std::allocator<_CharT>>
254 to_string(
const _Allocator& __alloc = _Allocator())
const
256 return { this->_M_str, this->_M_len, __alloc };
260 copy(_CharT* __str, size_type __n, size_type __pos = 0)
const
262 __glibcxx_requires_string_len(__str, __n);
263 if (__pos > this->_M_len)
264 __throw_out_of_range_fmt(__N(
"basic_string_view::copy: __pos "
265 "(which is %zu) > this->size() "
267 __pos, this->size());
268 size_type __rlen{
std::min(__n, size_type{this->_M_len - __pos})};
269 for (
auto __begin = this->_M_str + __pos,
270 __end = __begin + __rlen; __begin != __end;)
271 *__str++ = *__begin++;
279 substr(size_type __pos = 0, size_type __n = npos)
const
281 return __pos <= this->_M_len
283 std::min(__n, size_type{this->_M_len - __pos})}
284 : (__throw_out_of_range_fmt(__N(
"basic_string_view::substr: __pos "
285 "(which is %zu) > this->size() "
293 int __ret = traits_type::compare(this->_M_str, __str._M_str,
294 std::min(this->_M_len, __str._M_len));
296 __ret = _S_compare(this->_M_len, __str._M_len);
302 {
return this->substr(__pos1, __n1).compare(__str); }
305 compare(size_type __pos1, size_type __n1,
307 {
return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); }
310 compare(
const _CharT* __str)
const noexcept
314 compare(size_type __pos1, size_type __n1,
const _CharT* __str)
const
318 compare(size_type __pos1, size_type __n1,
319 const _CharT* __str, size_type __n2)
const
321 return this->substr(__pos1, __n1)
327 {
return this->find(__str._M_str, __pos, __str._M_len); }
330 find(_CharT __c, size_type __pos=0)
const noexcept;
333 find(
const _CharT* __str, size_type __pos, size_type __n)
const noexcept;
336 find(
const _CharT* __str, size_type __pos=0)
const noexcept
337 {
return this->find(__str, __pos, traits_type::length(__str)); }
341 {
return this->rfind(__str._M_str, __pos, __str._M_len); }
344 rfind(_CharT __c, size_type __pos = npos)
const noexcept;
347 rfind(
const _CharT* __str, size_type __pos, size_type __n)
const noexcept;
350 rfind(
const _CharT* __str, size_type __pos = npos)
const noexcept
351 {
return this->rfind(__str, __pos, traits_type::length(__str)); }
355 {
return this->find_first_of(__str._M_str, __pos, __str._M_len); }
358 find_first_of(_CharT __c, size_type __pos = 0)
const noexcept
359 {
return this->find(__c, __pos); }
362 find_first_of(
const _CharT* __str, size_type __pos, size_type __n)
const;
365 find_first_of(
const _CharT* __str, size_type __pos = 0)
const noexcept
366 {
return this->find_first_of(__str, __pos, traits_type::length(__str)); }
370 size_type __pos = npos)
const noexcept
371 {
return this->find_last_of(__str._M_str, __pos, __str._M_len); }
374 find_last_of(_CharT __c, size_type __pos=npos)
const noexcept
375 {
return this->rfind(__c, __pos); }
378 find_last_of(
const _CharT* __str, size_type __pos, size_type __n)
const;
381 find_last_of(
const _CharT* __str, size_type __pos = npos)
const noexcept
382 {
return this->find_last_of(__str, __pos, traits_type::length(__str)); }
386 size_type __pos = 0)
const noexcept
387 {
return this->find_first_not_of(__str._M_str, __pos, __str._M_len); }
390 find_first_not_of(_CharT __c, size_type __pos = 0)
const noexcept;
393 find_first_not_of(
const _CharT* __str,
394 size_type __pos, size_type __n)
const;
397 find_first_not_of(
const _CharT* __str, size_type __pos = 0)
const noexcept
399 return this->find_first_not_of(__str, __pos,
400 traits_type::length(__str));
405 size_type __pos = npos)
const noexcept
406 {
return this->find_last_not_of(__str._M_str, __pos, __str._M_len); }
409 find_last_not_of(_CharT __c, size_type __pos = npos)
const noexcept;
412 find_last_not_of(
const _CharT* __str,
413 size_type __pos, size_type __n)
const;
416 find_last_not_of(
const _CharT* __str,
417 size_type __pos = npos)
const noexcept
419 return this->find_last_not_of(__str, __pos,
420 traits_type::length(__str));
426 _S_compare(size_type __n1, size_type __n2)
noexcept
432 :
static_cast<int>(difference_type(__n1 - __n2));
436 const _CharT* _M_str;
446 template<
typename _CharT,
typename _Traits>
450 {
return __x.size() == __y.size() && __x.compare(__y) == 0; }
452 template<
typename _CharT,
typename _Traits>
457 {
return __x.size() == __y.size() && __x.compare(__y) == 0; }
459 template<
typename _CharT,
typename _Traits>
461 operator==(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
462 basic_string_view<_CharT, _Traits> __y)
noexcept
463 {
return __x.size() == __y.size() && __x.compare(__y) == 0; }
465 template<
typename _CharT,
typename _Traits>
467 operator!=(basic_string_view<_CharT, _Traits> __x,
468 basic_string_view<_CharT, _Traits> __y)
noexcept
469 {
return !(__x == __y); }
471 template<
typename _CharT,
typename _Traits>
473 operator!=(basic_string_view<_CharT, _Traits> __x,
474 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
476 {
return !(__x == __y); }
478 template<
typename _CharT,
typename _Traits>
480 operator!=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
481 basic_string_view<_CharT, _Traits> __y)
noexcept
482 {
return !(__x == __y); }
484 template<
typename _CharT,
typename _Traits>
486 operator< (basic_string_view<_CharT, _Traits> __x,
487 basic_string_view<_CharT, _Traits> __y)
noexcept
488 {
return __x.compare(__y) < 0; }
490 template<
typename _CharT,
typename _Traits>
492 operator< (basic_string_view<_CharT, _Traits> __x,
493 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
495 {
return __x.compare(__y) < 0; }
497 template<
typename _CharT,
typename _Traits>
499 operator< (__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
500 basic_string_view<_CharT, _Traits> __y)
noexcept
501 {
return __x.compare(__y) < 0; }
503 template<
typename _CharT,
typename _Traits>
505 operator> (basic_string_view<_CharT, _Traits> __x,
506 basic_string_view<_CharT, _Traits> __y)
noexcept
507 {
return __x.compare(__y) > 0; }
509 template<
typename _CharT,
typename _Traits>
511 operator> (basic_string_view<_CharT, _Traits> __x,
512 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
514 {
return __x.compare(__y) > 0; }
516 template<
typename _CharT,
typename _Traits>
518 operator> (__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
519 basic_string_view<_CharT, _Traits> __y)
noexcept
520 {
return __x.compare(__y) > 0; }
522 template<
typename _CharT,
typename _Traits>
524 operator<=(basic_string_view<_CharT, _Traits> __x,
525 basic_string_view<_CharT, _Traits> __y)
noexcept
526 {
return __x.compare(__y) <= 0; }
528 template<
typename _CharT,
typename _Traits>
530 operator<=(basic_string_view<_CharT, _Traits> __x,
531 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
533 {
return __x.compare(__y) <= 0; }
535 template<
typename _CharT,
typename _Traits>
537 operator<=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
538 basic_string_view<_CharT, _Traits> __y)
noexcept
539 {
return __x.compare(__y) <= 0; }
541 template<
typename _CharT,
typename _Traits>
543 operator>=(basic_string_view<_CharT, _Traits> __x,
544 basic_string_view<_CharT, _Traits> __y)
noexcept
545 {
return __x.compare(__y) >= 0; }
547 template<
typename _CharT,
typename _Traits>
549 operator>=(basic_string_view<_CharT, _Traits> __x,
550 __type_identity_t<basic_string_view<_CharT, _Traits>> __y)
552 {
return __x.compare(__y) >= 0; }
554 template<
typename _CharT,
typename _Traits>
556 operator>=(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
557 basic_string_view<_CharT, _Traits> __y)
noexcept
558 {
return __x.compare(__y) >= 0; }
561 template<
typename _CharT,
typename _Traits>
562 inline basic_ostream<_CharT, _Traits>&
563 operator<<(basic_ostream<_CharT, _Traits>& __os,
564 basic_string_view<_CharT,_Traits> __str)
565 {
return __ostream_insert(__os, __str.data(), __str.size()); }
570 using string_view = basic_string_view<char>;
571 using wstring_view = basic_string_view<wchar_t>;
572#ifdef _GLIBCXX_USE_CHAR8_T
573 using u8string_view = basic_string_view<char8_t>;
575 using u16string_view = basic_string_view<char16_t>;
576 using u32string_view = basic_string_view<char32_t>;
582 template<
typename _Tp>
586 struct hash<experimental::string_view>
587 :
public __hash_base<size_t, experimental::string_view>
590 operator()(
const experimental::string_view& __str)
const noexcept
591 {
return std::_Hash_impl::hash(__str.data(), __str.length()); }
595 struct __is_fast_hash<hash<experimental::string_view>> :
std::false_type
599 struct hash<experimental::wstring_view>
600 :
public __hash_base<size_t, wstring>
603 operator()(
const experimental::wstring_view& __s)
const noexcept
604 {
return std::_Hash_impl::hash(__s.data(),
605 __s.length() *
sizeof(
wchar_t)); }
609 struct __is_fast_hash<hash<experimental::wstring_view>> :
std::false_type
612#ifdef _GLIBCXX_USE_CHAR8_T
614 struct hash<experimental::u8string_view>
615 :
public __hash_base<size_t, experimental::u8string_view>
618 operator()(
const experimental::u8string_view& __s)
const noexcept
619 {
return std::_Hash_impl::hash(__s.data(), __s.length()); }
623 struct __is_fast_hash<hash<experimental::u8string_view>> :
std::false_type
628 struct hash<experimental::u16string_view>
629 :
public __hash_base<size_t, experimental::u16string_view>
632 operator()(
const experimental::u16string_view& __s)
const noexcept
633 {
return std::_Hash_impl::hash(__s.data(),
634 __s.length() *
sizeof(
char16_t)); }
638 struct __is_fast_hash<hash<experimental::u16string_view>> :
std::false_type
642 struct hash<experimental::u32string_view>
643 :
public __hash_base<size_t, experimental::u32string_view>
646 operator()(
const experimental::u32string_view& __s)
const noexcept
647 {
return std::_Hash_impl::hash(__s.data(),
648 __s.length() *
sizeof(
char32_t)); }
652 struct __is_fast_hash<hash<experimental::u32string_view>> :
std::false_type
655namespace experimental
658 inline namespace literals
660 inline namespace string_view_literals
662#pragma GCC diagnostic push
663#pragma GCC diagnostic ignored "-Wliteral-suffix"
664 inline constexpr basic_string_view<char>
665 operator""sv(
const char* __str,
size_t __len)
noexcept
666 {
return basic_string_view<char>{__str, __len}; }
668 inline constexpr basic_string_view<wchar_t>
669 operator""sv(
const wchar_t* __str,
size_t __len)
noexcept
670 {
return basic_string_view<wchar_t>{__str, __len}; }
672#ifdef _GLIBCXX_USE_CHAR8_T
673 inline constexpr basic_string_view<char8_t>
674 operator""sv(
const char8_t* __str,
size_t __len)
noexcept
675 {
return basic_string_view<char8_t>{__str, __len}; }
678 inline constexpr basic_string_view<char16_t>
679 operator""sv(
const char16_t* __str,
size_t __len)
noexcept
680 {
return basic_string_view<char16_t>{__str, __len}; }
682 inline constexpr basic_string_view<char32_t>
683 operator""sv(
const char32_t* __str,
size_t __len)
noexcept
684 {
return basic_string_view<char32_t>{__str, __len}; }
685#pragma GCC diagnostic pop
690#if __cpp_lib_concepts
694 template<
typename _CharT,
typename _Traits>
695 inline constexpr bool
696 enable_borrowed_range<experimental::basic_string_view<_CharT, _Traits>>
700 template<
typename _CharT,
typename _Traits>
701 inline constexpr bool
702 enable_view<experimental::basic_string_view<_CharT, _Traits>> =
true;
706_GLIBCXX_END_NAMESPACE_VERSION
constexpr bool operator<=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
constexpr bool operator>=(const duration< _Rep1, _Period1 > &__lhs, const duration< _Rep2, _Period2 > &__rhs)
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
ISO C++ entities toplevel namespace is std.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
static constexpr _Tp max() noexcept
static constexpr _Tp min() noexcept
A non-owning reference to a string.
Managing sequences of characters and character-like objects.
A non-owning reference to a string.