aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/cxxsupp/libcxx/include/string
diff options
context:
space:
mode:
authorAndrey Khalyavin <halyavin@gmail.com>2022-05-26 20:37:34 +0300
committerAndrey Khalyavin <halyavin@gmail.com>2022-05-26 20:37:34 +0300
commita983ee268a191f2757454e98e94d36615ee1339b (patch)
tree055e74fe7ae499ccc794ebd2b7bdef9004414850 /contrib/libs/cxxsupp/libcxx/include/string
parenta5bc0482bae2efd3f9a770e96967a317b5c26632 (diff)
downloadydb-a983ee268a191f2757454e98e94d36615ee1339b.tar.gz
Update libc++ to revision ab0554b2 (31 Jan 2022).
Notable changes: * allow using thread safety annotation in MinGW mode * implement compare_{strong,weak,partial}_fallback * omit atomic_{,un}signed_lock_free on platforms that doesn't support lock free atomics * set enable_borrowed_range template variable for ref_view and empty_view * fix bug in reverse_iterator::operator= * move some function from directory_iterator.cpp to a header so that they can be reused * fix bug in ranges::advance when try to advance by 0 * fix missing constraint which affects common_iterator for output iterators * correctly handle move-only iterators in move_iterator * make base() method in counted_iterator and transform_view::iterator noexcept * remove C++03 workarounds in reference_wrapper, since clang supports necessary features in C++03 mode * simplify convertible_to concept implementation * fix issue with __convertible_to_non_slicing rejecting correct case * remove excessive wrapping in std::ref and std::cref * fix std::seed_seq constructors * remove std::basic_string base class when using ABI v2 * std::basic_string::reserve now never shrinks in all C++ modes ref:b62ec6bac0283b075dd2348bad7e8a271155b378
Diffstat (limited to 'contrib/libs/cxxsupp/libcxx/include/string')
-rw-r--r--contrib/libs/cxxsupp/libcxx/include/string96
1 files changed, 47 insertions, 49 deletions
diff --git a/contrib/libs/cxxsupp/libcxx/include/string b/contrib/libs/cxxsupp/libcxx/include/string
index 50578ef989..457a393804 100644
--- a/contrib/libs/cxxsupp/libcxx/include/string
+++ b/contrib/libs/cxxsupp/libcxx/include/string
@@ -622,6 +622,7 @@ operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
+#ifndef _LIBCPP_ABI_NO_BASIC_STRING_BASE_CLASS
template <bool>
struct __basic_string_common;
@@ -631,6 +632,7 @@ struct __basic_string_common<true> {
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_length_error() const;
_LIBCPP_NORETURN _LIBCPP_EXPORTED_FROM_ABI void __throw_out_of_range() const;
};
+#endif
template <class _Iter>
struct __string_is_trivial_iterator : public false_type {};
@@ -684,7 +686,9 @@ class
_LIBCPP_PREFERRED_NAME(u32string)
#endif
basic_string
+#ifndef _LIBCPP_ABI_NO_BASIC_STRING_BASE_CLASS
: private __basic_string_common<true> // This base class is historical, but it needs to remain for ABI compatibility
+#endif
{
static_assert(sizeof(_CharT) <= 4, "libc++ implementation of std::basic_string does not support extra-wide character types");
public:
@@ -1761,20 +1765,12 @@ private:
_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
void __throw_length_error() const {
-#ifndef _LIBCPP_NO_EXCEPTIONS
- __basic_string_common<true>::__throw_length_error();
-#else
- _VSTD::abort();
-#endif
+ _VSTD::__throw_length_error("basic_string");
}
_LIBCPP_NORETURN _LIBCPP_HIDE_FROM_ABI
void __throw_out_of_range() const {
-#ifndef _LIBCPP_NO_EXCEPTIONS
- __basic_string_common<true>::__throw_out_of_range();
-#else
- _VSTD::abort();
-#endif
+ _VSTD::__throw_out_of_range("basic_string");
}
friend basic_string operator+<>(const basic_string&, const basic_string&);
@@ -1898,7 +1894,7 @@ void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
size_type __reserve)
{
if (__reserve > max_size())
- this->__throw_length_error();
+ __throw_length_error();
pointer __p;
if (__fits_in_sso(__reserve))
{
@@ -1922,7 +1918,7 @@ void
basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
{
if (__sz > max_size())
- this->__throw_length_error();
+ __throw_length_error();
pointer __p;
if (__fits_in_sso(__sz))
{
@@ -2005,7 +2001,7 @@ void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external(
__set_short_size(__sz);
} else {
if (__sz > max_size())
- this->__throw_length_error();
+ __throw_length_error();
size_t __cap = __recommend(__sz);
__p = __alloc_traits::allocate(__alloc(), __cap + 1);
__set_long_pointer(__p);
@@ -2061,7 +2057,7 @@ void
basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
{
if (__n > max_size())
- this->__throw_length_error();
+ __throw_length_error();
pointer __p;
if (__fits_in_sso(__n))
{
@@ -2106,7 +2102,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
{
size_type __str_sz = __str.size();
if (__pos > __str_sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
__init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
_VSTD::__debug_db_insert_c(this);
}
@@ -2119,7 +2115,7 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __st
{
size_type __str_sz = __str.size();
if (__pos > __str_sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
__init(__str.data() + __pos, __str_sz - __pos);
_VSTD::__debug_db_insert_c(this);
}
@@ -2192,7 +2188,7 @@ basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _For
{
size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__sz > max_size())
- this->__throw_length_error();
+ __throw_length_error();
pointer __p;
if (__fits_in_sso(__sz))
{
@@ -2291,7 +2287,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
{
size_type __ms = max_size();
if (__delta_cap > __ms - __old_cap - 1)
- this->__throw_length_error();
+ __throw_length_error();
pointer __old_p = __get_pointer();
size_type __cap = __old_cap < __ms / 2 - __alignment ?
__recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
@@ -2323,7 +2319,7 @@ basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_t
{
size_type __ms = max_size();
if (__delta_cap > __ms - __old_cap)
- this->__throw_length_error();
+ __throw_length_error();
pointer __old_p = __get_pointer();
size_type __cap = __old_cap < __ms / 2 - __alignment ?
__recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
@@ -2555,7 +2551,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, siz
{
size_type __sz = __str.size();
if (__pos > __sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
}
@@ -2572,7 +2568,7 @@ basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __p
__self_view __sv = __t;
size_type __sz = __sv.size();
if (__pos > __sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
}
@@ -2741,7 +2737,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, siz
{
size_type __sz = __str.size();
if (__pos > __sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
}
@@ -2757,7 +2753,7 @@ basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __p
__self_view __sv = __t;
size_type __sz = __sv.size();
if (__pos > __sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
}
@@ -2778,7 +2774,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_t
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
size_type __sz = size();
if (__pos > __sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
size_type __cap = capacity();
if (__cap - __sz >= __n)
{
@@ -2809,7 +2805,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n
{
size_type __sz = size();
if (__pos > __sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
if (__n)
{
size_type __cap = capacity();
@@ -2915,7 +2911,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_
{
size_type __str_sz = __str.size();
if (__pos2 > __str_sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
}
@@ -2932,7 +2928,7 @@ basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& _
__self_view __sv = __t;
size_type __str_sz = __sv.size();
if (__pos2 > __str_sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
}
@@ -2993,7 +2989,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
_LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
size_type __sz = size();
if (__pos > __sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
__n1 = _VSTD::min(__n1, __sz - __pos);
size_type __cap = capacity();
if (__cap - __sz + __n1 >= __n2)
@@ -3040,7 +3036,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __
{
size_type __sz = size();
if (__pos > __sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
__n1 = _VSTD::min(__n1, __sz - __pos);
size_type __cap = capacity();
value_type* __p;
@@ -3074,7 +3070,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_it
_InputIterator __j1, _InputIterator __j2)
{
const basic_string __temp(__j1, __j2, __alloc());
- return this->replace(__i1, __i2, __temp);
+ return replace(__i1, __i2, __temp);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -3092,7 +3088,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type _
{
size_type __str_sz = __str.size();
if (__pos2 > __str_sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
}
@@ -3109,7 +3105,7 @@ basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type _
__self_view __sv = __t;
size_type __str_sz = __sv.size();
if (__pos2 > __str_sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
}
@@ -3179,7 +3175,8 @@ template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos,
size_type __n) {
- if (__pos > size()) this->__throw_out_of_range();
+ if (__pos > size())
+ __throw_out_of_range();
if (__n == npos) {
__erase_to_end(__pos);
} else {
@@ -3295,12 +3292,13 @@ void
basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __requested_capacity)
{
if (__requested_capacity > max_size())
- this->__throw_length_error();
+ __throw_length_error();
-#if _LIBCPP_STD_VER > 17
- // Reserve never shrinks as of C++20.
- if (__requested_capacity <= capacity()) return;
-#endif
+ // Make sure reserve(n) never shrinks. This is technically only required in C++20
+ // and later (since P0966R1), however we provide consistent behavior in all Standard
+ // modes because this function is instantiated in the shared library.
+ if (__requested_capacity <= capacity())
+ return;
size_type __target_capacity = _VSTD::max(__requested_capacity, size());
__target_capacity = __recommend(__target_capacity);
@@ -3401,7 +3399,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::const_reference
basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
{
if (__n >= size())
- this->__throw_out_of_range();
+ __throw_out_of_range();
return (*this)[__n];
}
@@ -3410,7 +3408,7 @@ typename basic_string<_CharT, _Traits, _Allocator>::reference
basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
{
if (__n >= size())
- this->__throw_out_of_range();
+ __throw_out_of_range();
return (*this)[__n];
}
@@ -3456,7 +3454,7 @@ basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n,
{
size_type __sz = size();
if (__pos > __sz)
- this->__throw_out_of_range();
+ __throw_out_of_range();
size_type __rlen = _VSTD::min(__n, __sz - __pos);
traits_type::copy(__s, data() + __pos, __rlen);
return __rlen;
@@ -3900,7 +3898,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
_LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
size_type __sz = size();
if (__pos1 > __sz || __n2 == npos)
- this->__throw_out_of_range();
+ __throw_out_of_range();
size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
if (__r == 0)
@@ -3964,7 +3962,7 @@ basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
size_type __pos2,
size_type __n2) const
{
- return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
+ return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
}
template <class _CharT, class _Traits, class _Allocator>
@@ -4478,16 +4476,16 @@ template<class _CharT, class _Traits, class _Allocator>
bool
basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
{
- return this->data() <= _VSTD::__to_address(__i->base()) &&
- _VSTD::__to_address(__i->base()) < this->data() + this->size();
+ return data() <= _VSTD::__to_address(__i->base()) &&
+ _VSTD::__to_address(__i->base()) < data() + size();
}
template<class _CharT, class _Traits, class _Allocator>
bool
basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
{
- return this->data() < _VSTD::__to_address(__i->base()) &&
- _VSTD::__to_address(__i->base()) <= this->data() + this->size();
+ return data() < _VSTD::__to_address(__i->base()) &&
+ _VSTD::__to_address(__i->base()) <= data() + size();
}
template<class _CharT, class _Traits, class _Allocator>
@@ -4495,7 +4493,7 @@ bool
basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
{
const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
- return this->data() <= __p && __p <= this->data() + this->size();
+ return data() <= __p && __p <= data() + size();
}
template<class _CharT, class _Traits, class _Allocator>
@@ -4503,7 +4501,7 @@ bool
basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
{
const value_type* __p = _VSTD::__to_address(__i->base()) + __n;
- return this->data() <= __p && __p < this->data() + this->size();
+ return data() <= __p && __p < data() + size();
}
#endif // _LIBCPP_DEBUG_LEVEL == 2