_GLIBCXX_BEGIN_NAMESPACE_CXX11
#ifdef __cpp_lib_is_constant_evaluated
-// Support P1032R1 in C++20 (but not P0980R1 yet).
-# define __cpp_lib_constexpr_string 201811L
+// Support P0980R1 in C++20.
+# define __cpp_lib_constexpr_string 201907L
#elif __cplusplus >= 201703L && _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
// Support P0426R1 changes to char_traits in C++17.
# define __cpp_lib_constexpr_string 201611L
-#elif __cplusplus > 201703L
#endif
/**
_Res>;
// Allows an implicit conversion to __sv_type.
+ _GLIBCXX20_CONSTEXPR
static __sv_type
_S_to_string_view(__sv_type __svt) noexcept
{ return __svt; }
// is provided.
struct __sv_wrapper
{
- explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
+ _GLIBCXX20_CONSTEXPR explicit
+ __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { }
+
__sv_type _M_sv;
};
* @param __svw string view wrapper.
* @param __a Allocator to use.
*/
+ _GLIBCXX20_CONSTEXPR
explicit
basic_string(__sv_wrapper __svw, const _Alloc& __a)
: basic_string(__svw._M_sv.data(), __svw._M_sv.size(), __a) { }
_Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc())
: allocator_type(__a), _M_p(__dat) { }
#else
+ _GLIBCXX20_CONSTEXPR
_Alloc_hider(pointer __dat, const _Alloc& __a)
: allocator_type(__a), _M_p(__dat) { }
+ _GLIBCXX20_CONSTEXPR
_Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc())
: allocator_type(std::move(__a)), _M_p(__dat) { }
#endif
size_type _M_allocated_capacity;
};
+ _GLIBCXX20_CONSTEXPR
void
_M_data(pointer __p)
{ _M_dataplus._M_p = __p; }
+ _GLIBCXX20_CONSTEXPR
void
_M_length(size_type __length)
{ _M_string_length = __length; }
+ _GLIBCXX20_CONSTEXPR
pointer
_M_data() const
{ return _M_dataplus._M_p; }
+ _GLIBCXX20_CONSTEXPR
pointer
_M_local_data()
{
#endif
}
+ _GLIBCXX20_CONSTEXPR
const_pointer
_M_local_data() const
{
#endif
}
+ _GLIBCXX20_CONSTEXPR
void
_M_capacity(size_type __capacity)
{ _M_allocated_capacity = __capacity; }
+ _GLIBCXX20_CONSTEXPR
void
_M_set_length(size_type __n)
{
traits_type::assign(_M_data()[__n], _CharT());
}
+ _GLIBCXX20_CONSTEXPR
bool
_M_is_local() const
{ return _M_data() == _M_local_data(); }
// Create & Destroy
+ _GLIBCXX20_CONSTEXPR
pointer
_M_create(size_type&, size_type);
+ _GLIBCXX20_CONSTEXPR
void
_M_dispose()
{
_M_destroy(_M_allocated_capacity);
}
+ _GLIBCXX20_CONSTEXPR
void
_M_destroy(size_type __size) throw()
{ _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); }
// _M_construct_aux is used to implement the 21.3.1 para 15 which
// requires special behaviour if _InIterator is an integral type
template<typename _InIterator>
+ _GLIBCXX20_CONSTEXPR
void
_M_construct_aux(_InIterator __beg, _InIterator __end,
std::__false_type)
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 438. Ambiguity in the "do the right thing" clause
template<typename _Integer>
+ _GLIBCXX20_CONSTEXPR
void
_M_construct_aux(_Integer __beg, _Integer __end, std::__true_type)
{ _M_construct_aux_2(static_cast<size_type>(__beg), __end); }
+ _GLIBCXX20_CONSTEXPR
void
_M_construct_aux_2(size_type __req, _CharT __c)
{ _M_construct(__req, __c); }
template<typename _InIterator>
+ _GLIBCXX20_CONSTEXPR
void
_M_construct(_InIterator __beg, _InIterator __end)
{
// For Input Iterators, used in istreambuf_iterators, etc.
template<typename _InIterator>
+ _GLIBCXX20_CONSTEXPR
void
_M_construct(_InIterator __beg, _InIterator __end,
std::input_iterator_tag);
// For forward_iterators up to random_access_iterators, used for
// string::iterator, _CharT*, etc.
template<typename _FwdIterator>
+ _GLIBCXX20_CONSTEXPR
void
_M_construct(_FwdIterator __beg, _FwdIterator __end,
std::forward_iterator_tag);
+ _GLIBCXX20_CONSTEXPR
void
_M_construct(size_type __req, _CharT __c);
+ _GLIBCXX20_CONSTEXPR
allocator_type&
_M_get_allocator()
{ return _M_dataplus; }
+ _GLIBCXX20_CONSTEXPR
const allocator_type&
_M_get_allocator() const
{ return _M_dataplus; }
struct __enable_if_not_native_iterator<_Tp, false> { };
#endif
+ _GLIBCXX20_CONSTEXPR
size_type
_M_check(size_type __pos, const char* __s) const
{
return __pos;
}
+ _GLIBCXX20_CONSTEXPR
void
_M_check_length(size_type __n1, size_type __n2, const char* __s) const
{
// NB: _M_limit doesn't check for a bad __pos value.
+ _GLIBCXX20_CONSTEXPR
size_type
_M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT
{
// When __n = 1 way faster than the general multichar
// traits_type::copy/move/assign.
+ _GLIBCXX20_CONSTEXPR
static void
_S_copy(_CharT* __d, const _CharT* __s, size_type __n)
{
traits_type::copy(__d, __s, __n);
}
+ _GLIBCXX20_CONSTEXPR
static void
_S_move(_CharT* __d, const _CharT* __s, size_type __n)
{
traits_type::move(__d, __s, __n);
}
+ _GLIBCXX20_CONSTEXPR
static void
_S_assign(_CharT* __d, size_type __n, _CharT __c)
{
// _S_copy_chars is a separate template to permit specialization
// to optimize for the common case of pointers as iterators.
template<class _Iterator>
+ _GLIBCXX20_CONSTEXPR
static void
_S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2)
{
traits_type::assign(*__p, *__k1); // These types are off.
}
+ _GLIBCXX20_CONSTEXPR
static void
_S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT
{ _S_copy_chars(__p, __k1.base(), __k2.base()); }
+ _GLIBCXX20_CONSTEXPR
static void
_S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2)
_GLIBCXX_NOEXCEPT
{ _S_copy_chars(__p, __k1.base(), __k2.base()); }
+ _GLIBCXX20_CONSTEXPR
static void
_S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT
{ _S_copy(__p, __k1, __k2 - __k1); }
+ _GLIBCXX20_CONSTEXPR
static void
_S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2)
_GLIBCXX_NOEXCEPT
{ _S_copy(__p, __k1, __k2 - __k1); }
+ _GLIBCXX20_CONSTEXPR
static int
_S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT
{
return int(__d);
}
+ _GLIBCXX20_CONSTEXPR
void
_M_assign(const basic_string&);
+ _GLIBCXX20_CONSTEXPR
void
_M_mutate(size_type __pos, size_type __len1, const _CharT* __s,
size_type __len2);
+ _GLIBCXX20_CONSTEXPR
void
_M_erase(size_type __pos, size_type __n);
/**
* @brief Default constructor creates an empty string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string()
_GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value)
: _M_dataplus(_M_local_data())
/**
* @brief Construct an empty string using allocator @a a.
*/
+ _GLIBCXX20_CONSTEXPR
explicit
basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT
: _M_dataplus(_M_local_data(), __a)
* @brief Construct string with copy of value of @a __str.
* @param __str Source string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string(const basic_string& __str)
: _M_dataplus(_M_local_data(),
_Alloc_traits::_S_select_on_copy(__str._M_get_allocator()))
* @param __pos Index of first character to copy from.
* @param __a Allocator to use.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string(const basic_string& __str, size_type __pos,
const _Alloc& __a = _Alloc())
: _M_dataplus(_M_local_data(), __a)
* @param __pos Index of first character to copy from.
* @param __n Number of characters to copy.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string(const basic_string& __str, size_type __pos,
size_type __n)
: _M_dataplus(_M_local_data())
* @param __n Number of characters to copy.
* @param __a Allocator to use.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string(const basic_string& __str, size_type __pos,
size_type __n, const _Alloc& __a)
: _M_dataplus(_M_local_data(), __a)
* NB: @a __s must have at least @a __n characters, '\\0'
* has no special meaning.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string(const _CharT* __s, size_type __n,
const _Alloc& __a = _Alloc())
: _M_dataplus(_M_local_data(), __a)
// 3076. basic_string CTAD ambiguity
template<typename = _RequireAllocator<_Alloc>>
#endif
+ _GLIBCXX20_CONSTEXPR
basic_string(const _CharT* __s, const _Alloc& __a = _Alloc())
: _M_dataplus(_M_local_data(), __a)
{
// 3076. basic_string CTAD ambiguity
template<typename = _RequireAllocator<_Alloc>>
#endif
+ _GLIBCXX20_CONSTEXPR
basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc())
: _M_dataplus(_M_local_data(), __a)
{ _M_construct(__n, __c); }
* The newly-created string contains the exact contents of @a __str.
* @a __str is a valid, but unspecified string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string(basic_string&& __str) noexcept
: _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator()))
{
if (__str._M_is_local())
{
traits_type::copy(_M_local_buf, __str._M_local_buf,
- _S_local_capacity + 1);
+ __str.length() + 1);
}
else
{
* @param __l std::initializer_list of characters.
* @param __a Allocator to use (default is default allocator).
*/
+ _GLIBCXX20_CONSTEXPR
basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc())
: _M_dataplus(_M_local_data(), __a)
{ _M_construct(__l.begin(), __l.end()); }
+ _GLIBCXX20_CONSTEXPR
basic_string(const basic_string& __str, const _Alloc& __a)
: _M_dataplus(_M_local_data(), __a)
{ _M_construct(__str.begin(), __str.end()); }
+ _GLIBCXX20_CONSTEXPR
basic_string(basic_string&& __str, const _Alloc& __a)
noexcept(_Alloc_traits::_S_always_equal())
: _M_dataplus(_M_local_data(), __a)
if (__str._M_is_local())
{
traits_type::copy(_M_local_buf, __str._M_local_buf,
- _S_local_capacity + 1);
+ __str.length() + 1);
_M_length(__str.length());
__str._M_set_length(0);
}
#else
template<typename _InputIterator>
#endif
+ _GLIBCXX20_CONSTEXPR
basic_string(_InputIterator __beg, _InputIterator __end,
const _Alloc& __a = _Alloc())
: _M_dataplus(_M_local_data(), __a)
* @param __a Allocator to use.
*/
template<typename _Tp, typename = _If_sv<_Tp, void>>
+ _GLIBCXX20_CONSTEXPR
basic_string(const _Tp& __t, size_type __pos, size_type __n,
const _Alloc& __a = _Alloc())
: basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { }
* @param __a Allocator to use (default is default allocator).
*/
template<typename _Tp, typename = _If_sv<_Tp, void>>
+ _GLIBCXX20_CONSTEXPR
explicit
basic_string(const _Tp& __t, const _Alloc& __a = _Alloc())
: basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { }
/**
* @brief Destroy the string instance.
*/
+ _GLIBCXX20_CONSTEXPR
~basic_string()
{ _M_dispose(); }
* @brief Assign the value of @a str to this string.
* @param __str Source string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
operator=(const basic_string& __str)
{
* @brief Copy contents of @a s into this string.
* @param __s Source null-terminated string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
operator=(const _CharT* __s)
{ return this->assign(__s); }
* Assigning to a character makes this string length 1 and
* (*this)[0] == @a c.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
operator=(_CharT __c)
{
*/
// _GLIBCXX_RESOLVE_LIB_DEFECTS
// 2063. Contradictory requirements for string move assignment
+ _GLIBCXX20_CONSTEXPR
basic_string&
operator=(basic_string&& __str)
noexcept(_Alloc_traits::_S_nothrow_move())
* @brief Set value to string constructed from initializer %list.
* @param __l std::initializer_list.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
operator=(initializer_list<_CharT> __l)
{
* @param __svt An object convertible to string_view.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, basic_string&>
operator=(const _Tp& __svt)
{ return this->assign(__svt); }
* @brief Convert to a string_view.
* @return A string_view.
*/
+ _GLIBCXX20_CONSTEXPR
operator __sv_type() const noexcept
{ return __sv_type(data(), size()); }
#endif // C++17
* Returns a read/write iterator that points to the first character in
* the %string.
*/
+ _GLIBCXX20_CONSTEXPR
iterator
begin() _GLIBCXX_NOEXCEPT
{ return iterator(_M_data()); }
* Returns a read-only (constant) iterator that points to the first
* character in the %string.
*/
+ _GLIBCXX20_CONSTEXPR
const_iterator
begin() const _GLIBCXX_NOEXCEPT
{ return const_iterator(_M_data()); }
* Returns a read/write iterator that points one past the last
* character in the %string.
*/
+ _GLIBCXX20_CONSTEXPR
iterator
end() _GLIBCXX_NOEXCEPT
{ return iterator(_M_data() + this->size()); }
* Returns a read-only (constant) iterator that points one past the
* last character in the %string.
*/
+ _GLIBCXX20_CONSTEXPR
const_iterator
end() const _GLIBCXX_NOEXCEPT
{ return const_iterator(_M_data() + this->size()); }
* character in the %string. Iteration is done in reverse element
* order.
*/
+ _GLIBCXX20_CONSTEXPR
reverse_iterator
rbegin() _GLIBCXX_NOEXCEPT
{ return reverse_iterator(this->end()); }
* to the last character in the %string. Iteration is done in
* reverse element order.
*/
+ _GLIBCXX20_CONSTEXPR
const_reverse_iterator
rbegin() const _GLIBCXX_NOEXCEPT
{ return const_reverse_iterator(this->end()); }
* first character in the %string. Iteration is done in reverse
* element order.
*/
+ _GLIBCXX20_CONSTEXPR
reverse_iterator
rend() _GLIBCXX_NOEXCEPT
{ return reverse_iterator(this->begin()); }
* to one before the first character in the %string. Iteration
* is done in reverse element order.
*/
+ _GLIBCXX20_CONSTEXPR
const_reverse_iterator
rend() const _GLIBCXX_NOEXCEPT
{ return const_reverse_iterator(this->begin()); }
* Returns a read-only (constant) iterator that points to the first
* character in the %string.
*/
+ _GLIBCXX20_CONSTEXPR
const_iterator
cbegin() const noexcept
{ return const_iterator(this->_M_data()); }
* Returns a read-only (constant) iterator that points one past the
* last character in the %string.
*/
+ _GLIBCXX20_CONSTEXPR
const_iterator
cend() const noexcept
{ return const_iterator(this->_M_data() + this->size()); }
* to the last character in the %string. Iteration is done in
* reverse element order.
*/
+ _GLIBCXX20_CONSTEXPR
const_reverse_iterator
crbegin() const noexcept
{ return const_reverse_iterator(this->end()); }
* to one before the first character in the %string. Iteration
* is done in reverse element order.
*/
+ _GLIBCXX20_CONSTEXPR
const_reverse_iterator
crend() const noexcept
{ return const_reverse_iterator(this->begin()); }
// Capacity:
/// Returns the number of characters in the string, not including any
/// null-termination.
+ _GLIBCXX20_CONSTEXPR
size_type
size() const _GLIBCXX_NOEXCEPT
{ return _M_string_length; }
/// Returns the number of characters in the string, not including any
/// null-termination.
+ _GLIBCXX20_CONSTEXPR
size_type
length() const _GLIBCXX_NOEXCEPT
{ return _M_string_length; }
/// Returns the size() of the largest possible %string.
+ _GLIBCXX20_CONSTEXPR
size_type
max_size() const _GLIBCXX_NOEXCEPT
{ return (_Alloc_traits::max_size(_M_get_allocator()) - 1) / 2; }
* %string's current size the %string is truncated, otherwise
* the %string is extended and new elements are %set to @a __c.
*/
+ _GLIBCXX20_CONSTEXPR
void
resize(size_type __n, _CharT __c);
* are default-constructed. For basic types such as char, this means
* setting them to 0.
*/
+ _GLIBCXX20_CONSTEXPR
void
resize(size_type __n)
{ this->resize(__n, _CharT()); }
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
/// A non-binding request to reduce capacity() to size().
+ _GLIBCXX20_CONSTEXPR
void
shrink_to_fit() noexcept
{ reserve(); }
* Returns the total number of characters that the %string can hold
* before needing to allocate more memory.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
capacity() const _GLIBCXX_NOEXCEPT
{
* prevent a possible reallocation of memory and copying of %string
* data.
*/
+ _GLIBCXX20_CONSTEXPR
void
reserve(size_type __res_arg);
#if __cplusplus > 201703L
[[deprecated("use shrink_to_fit() instead")]]
#endif
+ _GLIBCXX20_CONSTEXPR
void
reserve();
/**
* Erases the string, making it empty.
*/
+ _GLIBCXX20_CONSTEXPR
void
clear() _GLIBCXX_NOEXCEPT
{ _M_set_length(0); }
* Returns true if the %string is empty. Equivalent to
* <code>*this == ""</code>.
*/
- _GLIBCXX_NODISCARD bool
+ _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR
+ bool
empty() const _GLIBCXX_NOEXCEPT
{ return this->size() == 0; }
* out_of_range lookups are not defined. (For checked lookups
* see at().)
*/
+ _GLIBCXX20_CONSTEXPR
const_reference
operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT
{
* out_of_range lookups are not defined. (For checked lookups
* see at().)
*/
+ _GLIBCXX20_CONSTEXPR
reference
operator[](size_type __pos)
{
* first checked that it is in the range of the string. The function
* throws out_of_range if the check fails.
*/
+ _GLIBCXX20_CONSTEXPR
const_reference
at(size_type __n) const
{
* first checked that it is in the range of the string. The function
* throws out_of_range if the check fails.
*/
+ _GLIBCXX20_CONSTEXPR
reference
at(size_type __n)
{
* Returns a read/write reference to the data at the first
* element of the %string.
*/
+ _GLIBCXX20_CONSTEXPR
reference
front() noexcept
{
* Returns a read-only (constant) reference to the data at the first
* element of the %string.
*/
+ _GLIBCXX20_CONSTEXPR
const_reference
front() const noexcept
{
* Returns a read/write reference to the data at the last
* element of the %string.
*/
+ _GLIBCXX20_CONSTEXPR
reference
back() noexcept
{
* Returns a read-only (constant) reference to the data at the
* last element of the %string.
*/
+ _GLIBCXX20_CONSTEXPR
const_reference
back() const noexcept
{
* @param __str The string to append.
* @return Reference to this string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
operator+=(const basic_string& __str)
{ return this->append(__str); }
* @param __s The C string to append.
* @return Reference to this string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
operator+=(const _CharT* __s)
{ return this->append(__s); }
* @param __c The character to append.
* @return Reference to this string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
operator+=(_CharT __c)
{
* @param __l The initializer_list of characters to be appended.
* @return Reference to this string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
operator+=(initializer_list<_CharT> __l)
{ return this->append(__l.begin(), __l.size()); }
* @return Reference to this string.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, basic_string&>
operator+=(const _Tp& __svt)
{ return this->append(__svt); }
* @param __str The string to append.
* @return Reference to this string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
append(const basic_string& __str)
{ return _M_append(__str._M_data(), __str.size()); }
* than the number of available characters in @a __str, the
* remainder of @a __str is appended.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
append(const basic_string& __str, size_type __pos, size_type __n = npos)
{ return _M_append(__str._M_data()
* @param __n The number of characters to append.
* @return Reference to this string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
append(const _CharT* __s, size_type __n)
{
* @param __s The C string to append.
* @return Reference to this string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
append(const _CharT* __s)
{
*
* Appends __n copies of __c to this string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
append(size_type __n, _CharT __c)
{ return _M_replace_aux(this->size(), size_type(0), __n, __c); }
* @param __l The initializer_list of characters to append.
* @return Reference to this string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
append(initializer_list<_CharT> __l)
{ return this->append(__l.begin(), __l.size()); }
#if __cplusplus >= 201103L
template<class _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
+ _GLIBCXX20_CONSTEXPR
#else
template<class _InputIterator>
#endif
* @return Reference to this string.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, basic_string&>
append(const _Tp& __svt)
{
* @return Reference to this string.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, basic_string&>
append(const _Tp& __svt, size_type __pos, size_type __n = npos)
{
* @brief Append a single character.
* @param __c Character to append.
*/
+ _GLIBCXX20_CONSTEXPR
void
push_back(_CharT __c)
{
* @param __str Source string to use.
* @return Reference to this string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
assign(const basic_string& __str)
{
* This function sets this string to the exact contents of @a __str.
* @a __str is a valid, but unspecified string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
assign(basic_string&& __str)
noexcept(_Alloc_traits::_S_nothrow_move())
* is larger than the number of available characters in @a
* __str, the remainder of @a __str is used.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
assign(const basic_string& __str, size_type __pos, size_type __n = npos)
{ return _M_replace(size_type(0), this->size(), __str._M_data()
* characters of @a __s. If @a __n is is larger than the number of
* available characters in @a __s, the remainder of @a __s is used.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
assign(const _CharT* __s, size_type __n)
{
* The data is copied, so there is no dependence on @a __s once the
* function returns.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
assign(const _CharT* __s)
{
* This function sets the value of this string to @a __n copies of
* character @a __c.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
assign(size_type __n, _CharT __c)
{ return _M_replace_aux(size_type(0), this->size(), __n, __c); }
#if __cplusplus >= 201103L
template<class _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
+ _GLIBCXX20_CONSTEXPR
#else
template<class _InputIterator>
#endif
* @param __l The initializer_list of characters to assign.
* @return Reference to this string.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
assign(initializer_list<_CharT> __l)
{ return this->assign(__l.begin(), __l.size()); }
* @return Reference to this string.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, basic_string&>
assign(const _Tp& __svt)
{
* @return Reference to this string.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, basic_string&>
assign(const _Tp& __svt, size_type __pos, size_type __n = npos)
{
* length_error is thrown. The value of the string doesn't
* change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
iterator
insert(const_iterator __p, size_type __n, _CharT __c)
{
*/
template<class _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
+ _GLIBCXX20_CONSTEXPR
iterator
insert(const_iterator __p, _InputIterator __beg, _InputIterator __end)
{
* @param __l The initializer_list of characters to insert.
* @throw std::length_error If new length exceeds @c max_size().
*/
+ _GLIBCXX20_CONSTEXPR
iterator
insert(const_iterator __p, initializer_list<_CharT> __l)
{ return this->insert(__p, __l.begin(), __l.end()); }
* length_error is thrown. The value of the string doesn't
* change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
insert(size_type __pos1, const basic_string& __str)
{ return this->replace(__pos1, size_type(0),
* beyond the end of @a __str, out_of_range is thrown. The
* value of the string doesn't change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
insert(size_type __pos1, const basic_string& __str,
size_type __pos2, size_type __n = npos)
* end(), out_of_range is thrown. The value of the string
* doesn't change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
insert(size_type __pos, const _CharT* __s, size_type __n)
{ return this->replace(__pos, size_type(0), __s, __n); }
* thrown. The value of the string doesn't change if an error is
* thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
insert(size_type __pos, const _CharT* __s)
{
* out_of_range is thrown. The value of the string doesn't
* change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
insert(size_type __pos, size_type __n, _CharT __c)
{ return _M_replace_aux(_M_check(__pos, "basic_string::insert"),
* out_of_range is thrown. The value of the string doesn't
* change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
iterator
insert(__const_iterator __p, _CharT __c)
{
* @return Reference to this string.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, basic_string&>
insert(size_type __pos, const _Tp& __svt)
{
* @return Reference to this string.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, basic_string&>
insert(size_type __pos1, const _Tp& __svt,
size_type __pos2, size_type __n = npos)
* out_of_range is thrown. The value of the string doesn't
* change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
erase(size_type __pos = 0, size_type __n = npos)
{
* Removes the character at @a __position from this string. The value
* of the string doesn't change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
iterator
erase(__const_iterator __position)
{
* Removes the characters in the range [first,last) from this string.
* The value of the string doesn't change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
iterator
erase(__const_iterator __first, __const_iterator __last)
{
*
* The string must be non-empty.
*/
+ _GLIBCXX20_CONSTEXPR
void
pop_back() noexcept
{
* is thrown. The value of the string doesn't change if an
* error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(size_type __pos, size_type __n, const basic_string& __str)
{ return this->replace(__pos, __n, __str._M_data(), __str.size()); }
* result exceeds max_size(), length_error is thrown. The value of the
* string doesn't change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(size_type __pos1, size_type __n1, const basic_string& __str,
size_type __pos2, size_type __n2 = npos)
* thrown. The value of the string doesn't change if an error
* is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(size_type __pos, size_type __n1, const _CharT* __s,
size_type __n2)
* length_error is thrown. The value of the string doesn't
* change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(size_type __pos, size_type __n1, const _CharT* __s)
{
* thrown. The value of the string doesn't change if an error
* is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c)
{ return _M_replace_aux(_M_check(__pos, "basic_string::replace"),
* exceeds max_size(), length_error is thrown. The value of
* the string doesn't change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(__const_iterator __i1, __const_iterator __i2,
const basic_string& __str)
* The value of the string doesn't change if an error is
* thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(__const_iterator __i1, __const_iterator __i2,
const _CharT* __s, size_type __n)
* result exceeds max_size(), length_error is thrown. The
* value of the string doesn't change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(__const_iterator __i1, __const_iterator __i2, const _CharT* __s)
{
* result exceeds max_size(), length_error is thrown. The
* value of the string doesn't change if an error is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(__const_iterator __i1, __const_iterator __i2, size_type __n,
_CharT __c)
#if __cplusplus >= 201103L
template<class _InputIterator,
typename = std::_RequireInputIter<_InputIterator>>
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(const_iterator __i1, const_iterator __i2,
_InputIterator __k1, _InputIterator __k2)
// Specializations for the common case of pointer and iterator:
// useful to avoid the overhead of temporary buffering in _M_replace.
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(__const_iterator __i1, __const_iterator __i2,
_CharT* __k1, _CharT* __k2)
__k1, __k2 - __k1);
}
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(__const_iterator __i1, __const_iterator __i2,
const _CharT* __k1, const _CharT* __k2)
__k1, __k2 - __k1);
}
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(__const_iterator __i1, __const_iterator __i2,
iterator __k1, iterator __k2)
__k1.base(), __k2 - __k1);
}
+ _GLIBCXX20_CONSTEXPR
basic_string&
replace(__const_iterator __i1, __const_iterator __i2,
const_iterator __k1, const_iterator __k2)
* The value of the string doesn't change if an error is
* thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string& replace(const_iterator __i1, const_iterator __i2,
initializer_list<_CharT> __l)
{ return this->replace(__i1, __i2, __l.begin(), __l.size()); }
* @return Reference to this string.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, basic_string&>
replace(size_type __pos, size_type __n, const _Tp& __svt)
{
* @return Reference to this string.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, basic_string&>
replace(size_type __pos1, size_type __n1, const _Tp& __svt,
size_type __pos2, size_type __n2 = npos)
* @return Reference to this string.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, basic_string&>
replace(const_iterator __i1, const_iterator __i2, const _Tp& __svt)
{
private:
template<class _Integer>
+ _GLIBCXX20_CONSTEXPR
basic_string&
_M_replace_dispatch(const_iterator __i1, const_iterator __i2,
_Integer __n, _Integer __val, __true_type)
{ return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __val); }
template<class _InputIterator>
+ _GLIBCXX20_CONSTEXPR
basic_string&
_M_replace_dispatch(const_iterator __i1, const_iterator __i2,
_InputIterator __k1, _InputIterator __k2,
__false_type);
+ _GLIBCXX20_CONSTEXPR
basic_string&
_M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
_CharT __c);
+ _GLIBCXX20_CONSTEXPR
basic_string&
_M_replace(size_type __pos, size_type __len1, const _CharT* __s,
const size_type __len2);
+ _GLIBCXX20_CONSTEXPR
basic_string&
_M_append(const _CharT* __s, size_type __n);
* C string @a __s. If @a __pos is %greater than size(),
* out_of_range is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
* Exchanges the contents of this string with that of @a __s in constant
* time.
*/
+ _GLIBCXX20_CONSTEXPR
void
swap(basic_string& __s) _GLIBCXX_NOEXCEPT;
* This is a handle to internal data. Do not modify or dire things may
* happen.
*/
+ _GLIBCXX20_CONSTEXPR
const _CharT*
c_str() const _GLIBCXX_NOEXCEPT
{ return _M_data(); }
* allows modifying the contents use @c &str[0] instead,
* (or in C++17 the non-const @c str.data() overload).
*/
+ _GLIBCXX20_CONSTEXPR
const _CharT*
data() const _GLIBCXX_NOEXCEPT
{ return _M_data(); }
* This is a pointer to the character sequence held by the string.
* Modifying the characters in the sequence is allowed.
*/
+ _GLIBCXX20_CONSTEXPR
_CharT*
data() noexcept
{ return _M_data(); }
/**
* @brief Return copy of allocator used to construct this string.
*/
+ _GLIBCXX20_CONSTEXPR
allocator_type
get_allocator() const _GLIBCXX_NOEXCEPT
{ return _M_get_allocator(); }
* returns the index where it begins. If not found, returns
* npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find(const _CharT* __s, size_type __pos, size_type __n) const
_GLIBCXX_NOEXCEPT;
* this string. If found, returns the index where it begins. If not
* found, returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find(const basic_string& __str, size_type __pos = 0) const
_GLIBCXX_NOEXCEPT
* @return Index of start of first occurrence.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, size_type>
find(const _Tp& __svt, size_type __pos = 0) const
noexcept(is_same<_Tp, __sv_type>::value)
* __s within this string. If found, returns the index where
* it begins. If not found, returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
{
* this string. If found, returns the index where it was
* found. If not found, returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT;
* __str within this string. If found, returns the index where
* it begins. If not found, returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
rfind(const basic_string& __str, size_type __pos = npos) const
_GLIBCXX_NOEXCEPT
* @return Index of start of last occurrence.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, size_type>
rfind(const _Tp& __svt, size_type __pos = npos) const
noexcept(is_same<_Tp, __sv_type>::value)
* returns the index where it begins. If not found, returns
* npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
rfind(const _CharT* __s, size_type __pos, size_type __n) const
_GLIBCXX_NOEXCEPT;
* @a __s within this string. If found, returns the index
* where it begins. If not found, returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
rfind(const _CharT* __s, size_type __pos = npos) const
{
* this string. If found, returns the index where it was
* found. If not found, returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT;
* returns the index where it was found. If not found, returns
* npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_first_of(const basic_string& __str, size_type __pos = 0) const
_GLIBCXX_NOEXCEPT
* @return Index of first occurrence.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, size_type>
find_first_of(const _Tp& __svt, size_type __pos = 0) const
noexcept(is_same<_Tp, __sv_type>::value)
* found, returns the index where it was found. If not found,
* returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
_GLIBCXX_NOEXCEPT;
* characters of @a __s within this string. If found, returns
* the index where it was found. If not found, returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_first_of(const _CharT* __s, size_type __pos = 0) const
_GLIBCXX_NOEXCEPT
*
* Note: equivalent to find(__c, __pos).
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT
{ return this->find(__c, __pos); }
* returns the index where it was found. If not found, returns
* npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_last_of(const basic_string& __str, size_type __pos = npos) const
_GLIBCXX_NOEXCEPT
* @return Index of last occurrence.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, size_type>
find_last_of(const _Tp& __svt, size_type __pos = npos) const
noexcept(is_same<_Tp, __sv_type>::value)
* found, returns the index where it was found. If not found,
* returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
_GLIBCXX_NOEXCEPT;
* characters of @a __s within this string. If found, returns
* the index where it was found. If not found, returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_last_of(const _CharT* __s, size_type __pos = npos) const
_GLIBCXX_NOEXCEPT
*
* Note: equivalent to rfind(__c, __pos).
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT
{ return this->rfind(__c, __pos); }
* in @a __str within this string. If found, returns the index where it
* was found. If not found, returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_first_not_of(const basic_string& __str, size_type __pos = 0) const
_GLIBCXX_NOEXCEPT
*/
template<typename _Tp>
_If_sv<_Tp, size_type>
+ _GLIBCXX20_CONSTEXPR
find_first_not_of(const _Tp& __svt, size_type __pos = 0) const
noexcept(is_same<_Tp, __sv_type>::value)
{
* this string. If found, returns the index where it was
* found. If not found, returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_first_not_of(const _CharT* __s, size_type __pos,
size_type __n) const _GLIBCXX_NOEXCEPT;
* contained in @a __s within this string. If found, returns
* the index where it was found. If not found, returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_first_not_of(const _CharT* __s, size_type __pos = 0) const
_GLIBCXX_NOEXCEPT
* other than @a __c within this string. If found, returns the
* index where it was found. If not found, returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_first_not_of(_CharT __c, size_type __pos = 0) const
_GLIBCXX_NOEXCEPT;
* returns the index where it was found. If not found, returns
* npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_last_not_of(const basic_string& __str, size_type __pos = npos) const
_GLIBCXX_NOEXCEPT
* @return Index of last occurrence.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, size_type>
find_last_not_of(const _Tp& __svt, size_type __pos = npos) const
noexcept(is_same<_Tp, __sv_type>::value)
* If found, returns the index where it was found. If not found,
* returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_last_not_of(const _CharT* __s, size_type __pos,
size_type __n) const _GLIBCXX_NOEXCEPT;
* returns the index where it was found. If not found, returns
* npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_last_not_of(const _CharT* __s, size_type __pos = npos) const
_GLIBCXX_NOEXCEPT
* @a __c within this string. If found, returns the index where it was
* found. If not found, returns npos.
*/
+ _GLIBCXX20_CONSTEXPR
size_type
find_last_not_of(_CharT __c, size_type __pos = npos) const
_GLIBCXX_NOEXCEPT;
* short, use the remainder of the characters. If @a __pos is
* beyond the end of the string, out_of_range is thrown.
*/
+ _GLIBCXX20_CONSTEXPR
basic_string
substr(size_type __pos = 0, size_type __n = npos) const
{ return basic_string(*this,
* If the result of the comparison is nonzero returns it,
* otherwise the shorter one is ordered first.
*/
+ _GLIBCXX20_CONSTEXPR
int
compare(const basic_string& __str) const
{
* @return Integer < 0, 0, or > 0.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, int>
compare(const _Tp& __svt) const
noexcept(is_same<_Tp, __sv_type>::value)
* @return Integer < 0, 0, or > 0.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, int>
compare(size_type __pos, size_type __n, const _Tp& __svt) const
noexcept(is_same<_Tp, __sv_type>::value)
* @return Integer < 0, 0, or > 0.
*/
template<typename _Tp>
+ _GLIBCXX20_CONSTEXPR
_If_sv<_Tp, int>
compare(size_type __pos1, size_type __n1, const _Tp& __svt,
size_type __pos2, size_type __n2 = npos) const
* result of the comparison is nonzero returns it, otherwise
* the shorter one is ordered first.
*/
+ _GLIBCXX20_CONSTEXPR
int
compare(size_type __pos, size_type __n, const basic_string& __str) const;
* If the result of the comparison is nonzero returns it,
* otherwise the shorter one is ordered first.
*/
+ _GLIBCXX20_CONSTEXPR
int
compare(size_type __pos1, size_type __n1, const basic_string& __str,
size_type __pos2, size_type __n2 = npos) const;
* comparison is nonzero returns it, otherwise the shorter one is
* ordered first.
*/
+ _GLIBCXX20_CONSTEXPR
int
compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT;
* the comparison is nonzero returns it, otherwise the shorter
* one is ordered first.
*/
+ _GLIBCXX20_CONSTEXPR
int
compare(size_type __pos, size_type __n1, const _CharT* __s) const;
* NB: s must have at least n2 characters, '\\0' has
* no special meaning.
*/
+ _GLIBCXX20_CONSTEXPR
int
compare(size_type __pos, size_type __n1, const _CharT* __s,
size_type __n2) const;
-#if __cplusplus > 201703L
- bool
+#if __cplusplus >= 202002L
+ constexpr bool
starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept
{ return __sv_type(this->data(), this->size()).starts_with(__x); }
- bool
+ constexpr bool
starts_with(_CharT __x) const noexcept
{ return __sv_type(this->data(), this->size()).starts_with(__x); }
- bool
+ constexpr bool
starts_with(const _CharT* __x) const noexcept
{ return __sv_type(this->data(), this->size()).starts_with(__x); }
- bool
+ constexpr bool
ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept
{ return __sv_type(this->data(), this->size()).ends_with(__x); }
- bool
+ constexpr bool
ends_with(_CharT __x) const noexcept
{ return __sv_type(this->data(), this->size()).ends_with(__x); }
- bool
+ constexpr bool
ends_with(const _CharT* __x) const noexcept
{ return __sv_type(this->data(), this->size()).ends_with(__x); }
#endif // C++20
#if __cplusplus > 202002L
- bool
+ constexpr bool
contains(basic_string_view<_CharT, _Traits> __x) const noexcept
{ return __sv_type(this->data(), this->size()).contains(__x); }
- bool
+ constexpr bool
contains(_CharT __x) const noexcept
{ return __sv_type(this->data(), this->size()).contains(__x); }
- bool
+ constexpr bool
contains(const _CharT* __x) const noexcept
{ return __sv_type(this->data(), this->size()).contains(__x); }
#endif // C++23
* @return New string with value of @a __lhs followed by @a __rhs.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
basic_string<_CharT, _Traits, _Alloc>
operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
const basic_string<_CharT, _Traits, _Alloc>& __rhs)
* @return New string with value of @a __lhs followed by @a __rhs.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
basic_string<_CharT,_Traits,_Alloc>
operator+(const _CharT* __lhs,
const basic_string<_CharT,_Traits,_Alloc>& __rhs);
* @return New string with @a __lhs followed by @a __rhs.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
basic_string<_CharT,_Traits,_Alloc>
operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs);
* @return New string with @a __lhs followed by @a __rhs.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline basic_string<_CharT, _Traits, _Alloc>
operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
const _CharT* __rhs)
* @return New string with @a __lhs followed by @a __rhs.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline basic_string<_CharT, _Traits, _Alloc>
operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs)
{
#if __cplusplus >= 201103L
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline basic_string<_CharT, _Traits, _Alloc>
operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
const basic_string<_CharT, _Traits, _Alloc>& __rhs)
{ return std::move(__lhs.append(__rhs)); }
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline basic_string<_CharT, _Traits, _Alloc>
operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
basic_string<_CharT, _Traits, _Alloc>&& __rhs)
{ return std::move(__rhs.insert(0, __lhs)); }
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline basic_string<_CharT, _Traits, _Alloc>
operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
basic_string<_CharT, _Traits, _Alloc>&& __rhs)
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline basic_string<_CharT, _Traits, _Alloc>
operator+(const _CharT* __lhs,
basic_string<_CharT, _Traits, _Alloc>&& __rhs)
{ return std::move(__rhs.insert(0, __lhs)); }
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline basic_string<_CharT, _Traits, _Alloc>
operator+(_CharT __lhs,
basic_string<_CharT, _Traits, _Alloc>&& __rhs)
{ return std::move(__rhs.insert(0, 1, __lhs)); }
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline basic_string<_CharT, _Traits, _Alloc>
operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
const _CharT* __rhs)
{ return std::move(__lhs.append(__rhs)); }
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline basic_string<_CharT, _Traits, _Alloc>
operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs,
_CharT __rhs)
* @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline bool
operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
const basic_string<_CharT, _Traits, _Alloc>& __rhs)
{ return __lhs.compare(__rhs) == 0; }
template<typename _CharT>
+ _GLIBCXX20_CONSTEXPR
inline
typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, bool>::__type
operator==(const basic_string<_CharT>& __lhs,
* @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline bool
operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
const _CharT* __rhs)
* greater than, or incomparable with `__rhs`.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline auto
operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
const basic_string<_CharT, _Traits, _Alloc>& __rhs) noexcept
* greater than, or incomparable with `__rhs`.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline auto
operator<=>(const basic_string<_CharT, _Traits, _Alloc>& __lhs,
const _CharT* __rhs) noexcept
* Exchanges the contents of @a __lhs and @a __rhs in constant time.
*/
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
inline void
swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
basic_string<_CharT, _Traits, _Alloc>& __rhs)
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wliteral-suffix"
- _GLIBCXX_DEFAULT_ABI_TAG
+
+#if __cpp_lib_constexpr_string >= 201907L
+# define _GLIBCXX_STRING_CONSTEXPR constexpr
+#else
+# define _GLIBCXX_STRING_CONSTEXPR
+#endif
+
+ _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
inline basic_string<char>
operator""s(const char* __str, size_t __len)
{ return basic_string<char>{__str, __len}; }
- _GLIBCXX_DEFAULT_ABI_TAG
+ _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
inline basic_string<wchar_t>
operator""s(const wchar_t* __str, size_t __len)
{ return basic_string<wchar_t>{__str, __len}; }
#ifdef _GLIBCXX_USE_CHAR8_T
- _GLIBCXX_DEFAULT_ABI_TAG
+ _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
inline basic_string<char8_t>
operator""s(const char8_t* __str, size_t __len)
{ return basic_string<char8_t>{__str, __len}; }
#endif
- _GLIBCXX_DEFAULT_ABI_TAG
+ _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
inline basic_string<char16_t>
operator""s(const char16_t* __str, size_t __len)
{ return basic_string<char16_t>{__str, __len}; }
- _GLIBCXX_DEFAULT_ABI_TAG
+ _GLIBCXX_DEFAULT_ABI_TAG _GLIBCXX_STRING_CONSTEXPR
inline basic_string<char32_t>
operator""s(const char32_t* __str, size_t __len)
{ return basic_string<char32_t>{__str, __len}; }
+#undef _GLIBCXX_STRING_CONSTEXPR
#pragma GCC diagnostic pop
} // inline namespace string_literals
} // inline namespace literals
basic_string<_CharT, _Traits, _Alloc>::npos;
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
void
basic_string<_CharT, _Traits, _Alloc>::
swap(basic_string& __s) _GLIBCXX_NOEXCEPT
{
_CharT __tmp_data[_S_local_capacity + 1];
traits_type::copy(__tmp_data, __s._M_local_buf,
- _S_local_capacity + 1);
+ __s.length() + 1);
traits_type::copy(__s._M_local_buf, _M_local_buf,
- _S_local_capacity + 1);
+ length() + 1);
traits_type::copy(_M_local_buf, __tmp_data,
- _S_local_capacity + 1);
+ __s.length() + 1);
}
else if (__s.length())
{
traits_type::copy(_M_local_buf, __s._M_local_buf,
- _S_local_capacity + 1);
+ __s.length() + 1);
_M_length(__s.length());
__s._M_set_length(0);
return;
else if (length())
{
traits_type::copy(__s._M_local_buf, _M_local_buf,
- _S_local_capacity + 1);
+ length() + 1);
__s._M_length(length());
_M_set_length(0);
return;
{
const size_type __tmp_capacity = __s._M_allocated_capacity;
traits_type::copy(__s._M_local_buf, _M_local_buf,
- _S_local_capacity + 1);
+ length() + 1);
_M_data(__s._M_data());
__s._M_data(__s._M_local_buf);
_M_capacity(__tmp_capacity);
if (__s._M_is_local())
{
traits_type::copy(_M_local_buf, __s._M_local_buf,
- _S_local_capacity + 1);
+ __s.length() + 1);
__s._M_data(_M_data());
_M_data(_M_local_buf);
}
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::pointer
basic_string<_CharT, _Traits, _Alloc>::
_M_create(size_type& __capacity, size_type __old_capacity)
// pointers, calling for a different coding style.
template<typename _CharT, typename _Traits, typename _Alloc>
template<typename _InIterator>
+ _GLIBCXX20_CONSTEXPR
void
basic_string<_CharT, _Traits, _Alloc>::
_M_construct(_InIterator __beg, _InIterator __end,
template<typename _CharT, typename _Traits, typename _Alloc>
template<typename _InIterator>
+ _GLIBCXX20_CONSTEXPR
void
basic_string<_CharT, _Traits, _Alloc>::
_M_construct(_InIterator __beg, _InIterator __end,
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
void
basic_string<_CharT, _Traits, _Alloc>::
_M_construct(size_type __n, _CharT __c)
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
void
basic_string<_CharT, _Traits, _Alloc>::
_M_assign(const basic_string& __str)
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
void
basic_string<_CharT, _Traits, _Alloc>::
reserve(size_type __res)
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
void
basic_string<_CharT, _Traits, _Alloc>::
_M_mutate(size_type __pos, size_type __len1, const _CharT* __s,
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
void
basic_string<_CharT, _Traits, _Alloc>::
_M_erase(size_type __pos, size_type __n)
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
void
basic_string<_CharT, _Traits, _Alloc>::
reserve()
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
void
basic_string<_CharT, _Traits, _Alloc>::
resize(size_type __n, _CharT __c)
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
basic_string<_CharT, _Traits, _Alloc>&
basic_string<_CharT, _Traits, _Alloc>::
_M_append(const _CharT* __s, size_type __n)
template<typename _CharT, typename _Traits, typename _Alloc>
template<typename _InputIterator>
+ _GLIBCXX20_CONSTEXPR
basic_string<_CharT, _Traits, _Alloc>&
basic_string<_CharT, _Traits, _Alloc>::
_M_replace_dispatch(const_iterator __i1, const_iterator __i2,
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
basic_string<_CharT, _Traits, _Alloc>&
basic_string<_CharT, _Traits, _Alloc>::
_M_replace_aux(size_type __pos1, size_type __n1, size_type __n2,
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
basic_string<_CharT, _Traits, _Alloc>&
basic_string<_CharT, _Traits, _Alloc>::
_M_replace(size_type __pos, size_type __len1, const _CharT* __s,
pointer __p = this->_M_data() + __pos;
const size_type __how_much = __old_size - __pos - __len1;
+#if __cpp_lib_is_constant_evaluated
+ if (__builtin_is_constant_evaluated())
+ {
+ auto __newp = this->_M_get_allocator().allocate(__new_size);
+ _S_copy(__newp, this->_M_data(), __pos);
+ _S_copy(__newp + __pos, __s, __len2);
+ _S_copy(__newp + __pos + __len2, __p + __len1, __how_much);
+ _S_copy(this->_M_data(), __newp, __new_size);
+ this->_M_get_allocator().deallocate(__newp, __new_size);
+ }
+ else
+#endif
if (_M_disjunct(__s))
{
if (__how_much && __len1 != __len2)
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
copy(_CharT* __s, size_type __n, size_type __pos) const
else
__p = _M_data();
struct _Terminator {
- ~_Terminator() { _M_this->_M_set_length(_M_r); }
+ constexpr ~_Terminator() { _M_this->_M_set_length(_M_r); }
basic_string* _M_this;
size_type _M_r;
};
#endif // _GLIBCXX_USE_CXX11_ABI
+#if __cpp_lib_constexpr_string >= 201907L
+# define _GLIBCXX_STRING_CONSTEXPR constexpr
+#else
+# define _GLIBCXX_STRING_CONSTEXPR
+#endif
+
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
basic_string<_CharT, _Traits, _Alloc>
operator+(const _CharT* __lhs,
const basic_string<_CharT, _Traits, _Alloc>& __rhs)
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX20_CONSTEXPR
basic_string<_CharT, _Traits, _Alloc>
operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs)
{
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find(const _CharT* __s, size_type __pos, size_type __n) const
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
rfind(const _CharT* __s, size_type __pos, size_type __n) const
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
rfind(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find_first_not_of(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
typename basic_string<_CharT, _Traits, _Alloc>::size_type
basic_string<_CharT, _Traits, _Alloc>::
find_last_not_of(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
int
basic_string<_CharT, _Traits, _Alloc>::
compare(size_type __pos, size_type __n, const basic_string& __str) const
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
int
basic_string<_CharT, _Traits, _Alloc>::
compare(size_type __pos1, size_type __n1, const basic_string& __str,
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
int
basic_string<_CharT, _Traits, _Alloc>::
compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
int
basic_string <_CharT, _Traits, _Alloc>::
compare(size_type __pos, size_type __n1, const _CharT* __s) const
}
template<typename _CharT, typename _Traits, typename _Alloc>
+ _GLIBCXX_STRING_CONSTEXPR
int
basic_string <_CharT, _Traits, _Alloc>::
compare(size_type __pos, size_type __n1, const _CharT* __s,
return __r;
}
+#undef _GLIBCXX_STRING_CONSTEXPR
+
// 21.3.7.9 basic_string::getline and operators
template<typename _CharT, typename _Traits, typename _Alloc>
basic_istream<_CharT, _Traits>&