34#ifndef _GLIBCXX_EXPERIMENTAL_STRING_VIEW
35#define _GLIBCXX_EXPERIMENTAL_STRING_VIEW 1
37#pragma GCC system_header
41#if __cplusplus >= 201402L
48namespace std _GLIBCXX_VISIBILITY(default)
50_GLIBCXX_BEGIN_NAMESPACE_VERSION
54inline namespace fundamentals_v1
56#define __cpp_lib_experimental_string_view 201411
77 template<
typename _CharT,
typename _Traits = std::
char_traits<_CharT>>
83 using traits_type = _Traits;
85 using pointer = _CharT*;
86 using const_pointer =
const _CharT*;
87 using reference = _CharT&;
88 using const_reference =
const _CharT&;
89 using const_iterator =
const _CharT*;
101 : _M_len{0}, _M_str{
nullptr}
106 template<
typename _Allocator>
108 _Allocator>& __str) noexcept
109 : _M_len{__str.length()}, _M_str{__str.data()}
113 : _M_len{__str ==
nullptr ? 0 : traits_type::length(__str)},
127 constexpr const_iterator
128 begin()
const noexcept
129 {
return this->_M_str; }
131 constexpr const_iterator
133 {
return this->_M_str + this->_M_len; }
135 constexpr const_iterator
137 {
return this->_M_str; }
139 constexpr const_iterator
140 cend()
const noexcept
141 {
return this->_M_str + this->_M_len; }
143 const_reverse_iterator
145 {
return const_reverse_iterator(this->
end()); }
147 const_reverse_iterator
148 rend()
const noexcept
149 {
return const_reverse_iterator(this->
begin()); }
151 const_reverse_iterator
153 {
return const_reverse_iterator(this->
end()); }
155 const_reverse_iterator
156 crend()
const noexcept
157 {
return const_reverse_iterator(this->
begin()); }
162 size()
const noexcept
163 {
return this->_M_len; }
166 length()
const noexcept
170 max_size()
const noexcept
172 return (npos -
sizeof(
size_type) -
sizeof(
void*))
176 _GLIBCXX_NODISCARD
constexpr bool
177 empty()
const noexcept
178 {
return this->_M_len == 0; }
182 constexpr const _CharT&
185 __glibcxx_assert(__pos < this->_M_len);
186 return *(this->_M_str + __pos);
189 constexpr const _CharT&
192 return __pos < this->_M_len
193 ? *(this->_M_str + __pos)
194 : (__throw_out_of_range_fmt(__N(
"basic_string_view::at: __pos "
195 "(which is %zu) >= this->size() "
197 __pos, this->
size()),
201 constexpr const _CharT&
204 __glibcxx_assert(this->_M_len > 0);
205 return *this->_M_str;
208 constexpr const _CharT&
211 __glibcxx_assert(this->_M_len > 0);
212 return *(this->_M_str + this->_M_len - 1);
215 constexpr const _CharT*
216 data()
const noexcept
217 {
return this->_M_str; }
224 __glibcxx_assert(this->_M_len >= __n);
231 { this->_M_len -= __n; }
244 template<
typename _Allocator>
247 return { this->_M_str, this->_M_len };
250 template<
typename _Allocator = std::allocator<_CharT>>
252 to_string(
const _Allocator& __alloc = _Allocator())
const
254 return { this->_M_str, this->_M_len, __alloc };
260 __glibcxx_requires_string_len(__str, __n);
261 if (__pos > this->_M_len)
262 __throw_out_of_range_fmt(__N(
"basic_string_view::copy: __pos "
263 "(which is %zu) > this->size() "
265 __pos, this->
size());
267 for (
auto __begin = this->_M_str + __pos,
268 __end = __begin + __rlen; __begin != __end;)
269 *__str++ = *__begin++;
279 return __pos <= this->_M_len
282 : (__throw_out_of_range_fmt(__N(
"basic_string_view::substr: __pos "
283 "(which is %zu) > this->size() "
291 int __ret = traits_type::compare(this->_M_str, __str._M_str,
292 std::min(this->_M_len, __str._M_len));
294 __ret = _S_compare(this->_M_len, __str._M_len);
300 {
return this->substr(__pos1, __n1).compare(__str); }
305 {
return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); }
308 compare(
const _CharT* __str)
const noexcept
317 const _CharT* __str,
size_type __n2)
const
319 return this->substr(__pos1, __n1)
325 {
return this->find(__str._M_str, __pos, __str._M_len); }
328 find(_CharT __c,
size_type __pos=0)
const noexcept;
334 find(
const _CharT* __str,
size_type __pos=0)
const noexcept
335 {
return this->find(__str, __pos, traits_type::length(__str)); }
339 {
return this->rfind(__str._M_str, __pos, __str._M_len); }
342 rfind(_CharT __c,
size_type __pos = npos)
const noexcept;
348 rfind(
const _CharT* __str,
size_type __pos = npos)
const noexcept
349 {
return this->rfind(__str, __pos, traits_type::length(__str)); }
353 {
return this->find_first_of(__str._M_str, __pos, __str._M_len); }
356 find_first_of(_CharT __c,
size_type __pos = 0)
const noexcept
357 {
return this->find(__c, __pos); }
363 find_first_of(
const _CharT* __str,
size_type __pos = 0)
const noexcept
364 {
return this->find_first_of(__str, __pos, traits_type::length(__str)); }
369 {
return this->find_last_of(__str._M_str, __pos, __str._M_len); }
372 find_last_of(_CharT __c,
size_type __pos=npos)
const noexcept
373 {
return this->rfind(__c, __pos); }
379 find_last_of(
const _CharT* __str,
size_type __pos = npos)
const noexcept
380 {
return this->find_last_of(__str, __pos, traits_type::length(__str)); }
385 {
return this->find_first_not_of(__str._M_str, __pos, __str._M_len); }
388 find_first_not_of(_CharT __c,
size_type __pos = 0)
const noexcept;
391 find_first_not_of(
const _CharT* __str,
395 find_first_not_of(
const _CharT* __str,
size_type __pos = 0)
const noexcept
397 return this->find_first_not_of(__str, __pos,
398 traits_type::length(__str));
404 {
return this->find_last_not_of(__str._M_str, __pos, __str._M_len); }
407 find_last_not_of(_CharT __c,
size_type __pos = npos)
const noexcept;
410 find_last_not_of(
const _CharT* __str,
414 find_last_not_of(
const _CharT* __str,
417 return this->find_last_not_of(__str, __pos,
418 traits_type::length(__str));
434 const _CharT* _M_str;
444 template<
typename _CharT,
typename _Traits>
448 {
return __x.size() == __y.size() && __x.compare(__y) == 0; }
450 template<
typename _CharT,
typename _Traits>
455 {
return __x.size() == __y.size() && __x.compare(__y) == 0; }
457 template<
typename _CharT,
typename _Traits>
459 operator==(__type_identity_t<basic_string_view<_CharT, _Traits>> __x,
460 basic_string_view<_CharT, _Traits> __y)
noexcept
461 {
return __x.size() == __y.size() && __x.compare(__y) == 0; }
463 template<
typename _CharT,
typename _Traits>
467 {
return !(__x == __y); }
469 template<
typename _CharT,
typename _Traits>
474 {
return !(__x == __y); }
476 template<
typename _CharT,
typename _Traits>
480 {
return !(__x == __y); }
482 template<
typename _CharT,
typename _Traits>
486 {
return __x.compare(__y) < 0; }
488 template<
typename _CharT,
typename _Traits>
493 {
return __x.compare(__y) < 0; }
495 template<
typename _CharT,
typename _Traits>
499 {
return __x.compare(__y) < 0; }
501 template<
typename _CharT,
typename _Traits>
505 {
return __x.compare(__y) > 0; }
507 template<
typename _CharT,
typename _Traits>
512 {
return __x.compare(__y) > 0; }
514 template<
typename _CharT,
typename _Traits>
518 {
return __x.compare(__y) > 0; }
520 template<
typename _CharT,
typename _Traits>
524 {
return __x.compare(__y) <= 0; }
526 template<
typename _CharT,
typename _Traits>
531 {
return __x.compare(__y) <= 0; }
533 template<
typename _CharT,
typename _Traits>
537 {
return __x.compare(__y) <= 0; }
539 template<
typename _CharT,
typename _Traits>
543 {
return __x.compare(__y) >= 0; }
545 template<
typename _CharT,
typename _Traits>
550 {
return __x.compare(__y) >= 0; }
552 template<
typename _CharT,
typename _Traits>
556 {
return __x.compare(__y) >= 0; }
559 template<
typename _CharT,
typename _Traits>
560 inline basic_ostream<_CharT, _Traits>&
561 operator<<(basic_ostream<_CharT, _Traits>& __os,
563 {
return __ostream_insert(__os, __str.data(), __str.size()); }
570#ifdef _GLIBCXX_USE_CHAR8_T
580 template<
typename _Tp>
585 :
public __hash_base<size_t, experimental::string_view>
588 operator()(
const experimental::string_view& __str)
const noexcept
589 {
return std::_Hash_impl::hash(__str.data(), __str.length()); }
598 :
public __hash_base<size_t, wstring>
601 operator()(
const experimental::wstring_view& __s)
const noexcept
602 {
return std::_Hash_impl::hash(__s.data(),
603 __s.length() *
sizeof(
wchar_t)); }
610#ifdef _GLIBCXX_USE_CHAR8_T
613 :
public __hash_base<size_t, experimental::u8string_view>
616 operator()(
const experimental::u8string_view& __s)
const noexcept
617 {
return std::_Hash_impl::hash(__s.data(), __s.length()); }
627 :
public __hash_base<size_t, experimental::u16string_view>
630 operator()(
const experimental::u16string_view& __s)
const noexcept
631 {
return std::_Hash_impl::hash(__s.data(),
632 __s.length() *
sizeof(
char16_t)); }
641 :
public __hash_base<size_t, experimental::u32string_view>
644 operator()(
const experimental::u32string_view& __s)
const noexcept
645 {
return std::_Hash_impl::hash(__s.data(),
646 __s.length() *
sizeof(
char32_t)); }
656 inline namespace literals
658 inline namespace string_view_literals
660#pragma GCC diagnostic push
661#pragma GCC diagnostic ignored "-Wliteral-suffix"
662 inline constexpr basic_string_view<char>
663 operator""sv(
const char* __str,
size_t __len)
noexcept
664 {
return basic_string_view<char>{__str, __len}; }
666 inline constexpr basic_string_view<wchar_t>
667 operator""sv(
const wchar_t* __str,
size_t __len)
noexcept
668 {
return basic_string_view<wchar_t>{__str, __len}; }
670#ifdef _GLIBCXX_USE_CHAR8_T
671 inline constexpr basic_string_view<char8_t>
672 operator""sv(
const char8_t* __str,
size_t __len)
noexcept
673 {
return basic_string_view<char8_t>{__str, __len}; }
676 inline constexpr basic_string_view<char16_t>
677 operator""sv(
const char16_t* __str,
size_t __len)
noexcept
678 {
return basic_string_view<char16_t>{__str, __len}; }
680 inline constexpr basic_string_view<char32_t>
681 operator""sv(
const char32_t* __str,
size_t __len)
noexcept
682 {
return basic_string_view<char32_t>{__str, __len}; }
683#pragma GCC diagnostic pop
688#if __cpp_lib_concepts
692 template<
typename _CharT,
typename _Traits>
693 inline constexpr bool
694 enable_borrowed_range<experimental::basic_string_view<_CharT, _Traits>>
698 template<
typename _CharT,
typename _Traits>
699 inline constexpr bool
704_GLIBCXX_END_NAMESPACE_VERSION
constexpr bool enable_view
[range.view] The ranges::enable_view boolean.
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
_Tp * end(valarray< _Tp > &__va) noexcept
Return an iterator pointing to one past the last element of the valarray.
_Tp * begin(valarray< _Tp > &__va) noexcept
Return an iterator pointing to the first element of the valarray.
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
ISO C++ entities toplevel namespace is std.
constexpr auto crend(const _Container &__cont) -> decltype(std::rend(__cont))
Return a reverse iterator pointing one past the first element of the const container.
constexpr auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
constexpr auto cend(const _Container &__cont) noexcept(noexcept(std::end(__cont))) -> decltype(std::end(__cont))
Return an iterator pointing to one past the last element of the const container.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
constexpr auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
constexpr auto crbegin(const _Container &__cont) -> decltype(std::rbegin(__cont))
Return a reverse iterator pointing to the last element of the const container.
constexpr auto data(_Container &__cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data())
Return the data pointer of a container.
constexpr auto cbegin(const _Container &__cont) noexcept(noexcept(std::begin(__cont))) -> decltype(std::begin(__cont))
Return an iterator pointing to the first element of the const container.
Namespace for features defined in ISO Technical Specifications.
static constexpr _Tp max() noexcept
static constexpr _Tp min() noexcept
A non-owning reference to a string.
Primary class template hash.
Managing sequences of characters and character-like objects.
A non-owning reference to a string.