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;
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*;
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
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
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
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*))
178 _GLIBCXX_NODISCARD
constexpr bool
179 empty()
const noexcept
180 {
return this->_M_len == 0; }
184 constexpr const _CharT&
187 __glibcxx_assert(__pos < this->_M_len);
188 return *(this->_M_str + __pos);
191 constexpr const _CharT&
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; }
226 __glibcxx_assert(this->_M_len >= __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 };
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());
269 for (
auto __begin = this->_M_str + __pos,
270 __end = __begin + __rlen; __begin != __end;)
271 *__str++ = *__begin++;
281 return __pos <= this->_M_len
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); }
307 {
return this->substr(__pos1, __n1).compare(__str.substr(__pos2, __n2)); }
310 compare(
const _CharT* __str)
const noexcept
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;
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;
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); }
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)); }
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); }
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)); }
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,
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));
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,
416 find_last_not_of(
const _CharT* __str,
419 return this->find_last_not_of(__str, __pos,
420 traits_type::length(__str));
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>
469 {
return !(__x == __y); }
471 template<
typename _CharT,
typename _Traits>
476 {
return !(__x == __y); }
478 template<
typename _CharT,
typename _Traits>
482 {
return !(__x == __y); }
484 template<
typename _CharT,
typename _Traits>
488 {
return __x.compare(__y) < 0; }
490 template<
typename _CharT,
typename _Traits>
495 {
return __x.compare(__y) < 0; }
497 template<
typename _CharT,
typename _Traits>
501 {
return __x.compare(__y) < 0; }
503 template<
typename _CharT,
typename _Traits>
507 {
return __x.compare(__y) > 0; }
509 template<
typename _CharT,
typename _Traits>
514 {
return __x.compare(__y) > 0; }
516 template<
typename _CharT,
typename _Traits>
520 {
return __x.compare(__y) > 0; }
522 template<
typename _CharT,
typename _Traits>
526 {
return __x.compare(__y) <= 0; }
528 template<
typename _CharT,
typename _Traits>
533 {
return __x.compare(__y) <= 0; }
535 template<
typename _CharT,
typename _Traits>
539 {
return __x.compare(__y) <= 0; }
541 template<
typename _CharT,
typename _Traits>
545 {
return __x.compare(__y) >= 0; }
547 template<
typename _CharT,
typename _Traits>
552 {
return __x.compare(__y) >= 0; }
554 template<
typename _CharT,
typename _Traits>
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,
565 {
return __ostream_insert(__os, __str.data(), __str.size()); }
572#ifdef _GLIBCXX_USE_CHAR8_T
582 template<
typename _Tp>
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()); }
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)); }
612#ifdef _GLIBCXX_USE_CHAR8_T
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()); }
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)); }
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)); }
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
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
_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 rbegin(_Container &__cont) noexcept(noexcept(__cont.rbegin())) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last 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 crbegin(const _Container &__cont) noexcept(noexcept(std::rbegin(__cont))) -> decltype(std::rbegin(__cont))
Return a reverse iterator pointing to the last element of the const container.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a 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.
constexpr auto rend(_Container &__cont) noexcept(noexcept(__cont.rend())) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
constexpr auto crend(const _Container &__cont) noexcept(noexcept(std::rend(__cont))) -> decltype(std::rend(__cont))
Return a reverse iterator pointing one past 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.