diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -790,93 +790,207 @@ static const size_type npos = -1; _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string() - _NOEXCEPT_(is_nothrow_default_constructible::value); + _NOEXCEPT_(is_nothrow_default_constructible::value) + : __r_(__default_init_tag(), __default_init_tag()) { + std::__debug_db_insert_c(this); + __default_init(); + } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit basic_string(const allocator_type& __a) #if _LIBCPP_STD_VER <= 14 _NOEXCEPT_(is_nothrow_copy_constructible::value); #else - _NOEXCEPT; + _NOEXCEPT #endif + : __r_(__default_init_tag(), __a) { + std::__debug_db_insert_c(this); + __default_init(); + } - _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const basic_string& __str); - _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const basic_string& __str, const allocator_type& __a); + _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const basic_string& __str) + : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) { + if (!__str.__is_long()) + __r_.first().__r = __str.__r_.first().__r; + else + __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); + std::__debug_db_insert_c(this); + } + + _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const basic_string& __str, const allocator_type& __a) + : __r_(__default_init_tag(), __a) { + if (!__str.__is_long()) + __r_.first().__r = __str.__r_.first().__r; + else + __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); + std::__debug_db_insert_c(this); + } #ifndef _LIBCPP_CXX03_LANG - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(basic_string&& __str) -#if _LIBCPP_STD_VER <= 14 + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(basic_string&& __str) +# if _LIBCPP_STD_VER <= 14 _NOEXCEPT_(is_nothrow_move_constructible::value); -#else - _NOEXCEPT; -#endif +# else + _NOEXCEPT +# endif + : __r_(std::move(__str.__r_)) { + __str.__default_init(); + std::__debug_db_insert_c(this); + if (__is_long()) + std::__debug_db_swap(this, &__str); + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(basic_string&& __str, const allocator_type& __a) + : __r_(__default_init_tag(), __a) { + if (__str.__is_long() && __a != __str.__alloc()) // copy, not move + __init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); + else { + if (__libcpp_is_constant_evaluated()) { + __zero(); + __r_.first().__l = __str.__r_.first().__l; + } else { + __r_.first().__r = __str.__r_.first().__r; + } + __str.__default_init(); + } + std::__debug_db_insert_c(this); + if (__is_long()) + std::__debug_db_swap(this, &__str); + } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(basic_string&& __str, const allocator_type& __a); #endif // _LIBCPP_CXX03_LANG - template ::value, nullptr_t> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(const _CharT* __s) : __r_(__default_init_tag(), __default_init_tag()) { - _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); - __init(__s, traits_type::length(__s)); - std::__debug_db_insert_c(this); - } + template ::value, nullptr_t> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const _CharT* __s) + : __r_(__default_init_tag(), __default_init_tag()) { + _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr"); + __init(__s, traits_type::length(__s)); + std::__debug_db_insert_c(this); + } - template ::value, nullptr_t> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(const _CharT* __s, const _Allocator& __a); + template ::value, nullptr_t> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const _CharT* __s, const _Allocator& __a) + : __r_(__default_init_tag(), __a) { + _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); + __init(__s, traits_type::length(__s)); + std::__debug_db_insert_c(this); + } #if _LIBCPP_STD_VER > 20 - basic_string(nullptr_t) = delete; + basic_string(nullptr_t) = delete; #endif - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(const _CharT* __s, size_type __n); - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(const _CharT* __s, size_type __n, const _Allocator& __a); - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(size_type __n, _CharT __c); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const _CharT* __s, size_type __n) + : __r_(__default_init_tag(), __default_init_tag()) { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); + __init(__s, __n); + std::__debug_db_insert_c(this); + } - template ::value, nullptr_t> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(size_type __n, _CharT __c, const _Allocator& __a); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const _CharT* __s, size_type __n, + const _Allocator& __a) + : __r_(__default_init_tag(), __a) { + _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); + __init(__s, __n); + std::__debug_db_insert_c(this); + } - _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(const basic_string& __str, size_type __pos, size_type __n, - const _Allocator& __a = _Allocator()); - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(const basic_string& __str, size_type __pos, - const _Allocator& __a = _Allocator()); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(size_type __n, _CharT __c) + : __r_(__default_init_tag(), __default_init_tag()) { + __init(__n, __c); + std::__debug_db_insert_c(this); + } - template::value && !__is_same_uncvref<_Tp, basic_string>::value> > - _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(const _Tp& __t, size_type __pos, size_type __n, - const allocator_type& __a = allocator_type()); + template ::value, nullptr_t> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(size_type __n, _CharT __c, const _Allocator& __a) + : __r_(__default_init_tag(), __a) { + __init(__n, __c); + std::__debug_db_insert_c(this); + } - template::value && - !__is_same_uncvref<_Tp, basic_string>::value> > - _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 - explicit basic_string(const _Tp& __t); + _LIBCPP_CONSTEXPR_AFTER_CXX17 + basic_string(const basic_string& __str, size_type __pos, size_type __n, const _Allocator& __a = _Allocator()) + : __r_(__default_init_tag(), __a) { + size_type __str_sz = __str.size(); + if (__pos > __str_sz) + __throw_out_of_range(); + __init(__str.data() + __pos, std::min(__n, __str_sz - __pos)); + std::__debug_db_insert_c(this); + } - template::value && !__is_same_uncvref<_Tp, basic_string>::value> > - _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 - explicit basic_string(const _Tp& __t, const allocator_type& __a); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(const basic_string& __str, size_type __pos, + const _Allocator& __a = _Allocator()) + : __r_(__default_init_tag(), __a) { + size_type __str_sz = __str.size(); + if (__pos > __str_sz) + __throw_out_of_range(); + __init(__str.data() + __pos, __str_sz - __pos); + std::__debug_db_insert_c(this); + } + + template ::value && + !__is_same_uncvref<_Tp, basic_string>::value> > + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 + basic_string(const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a = allocator_type()) + : __r_(__default_init_tag(), __a) { + __self_view __sv0 = __t; + __self_view __sv = __sv0.substr(__pos, __n); + __init(__sv.data(), __sv.size()); + std::__debug_db_insert_c(this); + } + + template ::value && + !__is_same_uncvref<_Tp, basic_string>::value> > + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit basic_string(const _Tp& __t) + : __r_(__default_init_tag(), __default_init_tag()) { + __self_view __sv = __t; + __init(__sv.data(), __sv.size()); + std::__debug_db_insert_c(this); + } + + template ::value && + !__is_same_uncvref<_Tp, basic_string>::value> > + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS + _LIBCPP_CONSTEXPR_AFTER_CXX17 explicit basic_string(const _Tp& __t, const allocator_type& __a) + : __r_(__default_init_tag(), __a) { + __self_view __sv = __t; + __init(__sv.data(), __sv.size()); + std::__debug_db_insert_c(this); + } + + template ::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(_InputIterator __first, _InputIterator __last) + : __r_(__default_init_tag(), __default_init_tag()) { + __init(__first, __last); + std::__debug_db_insert_c(this); + } + + template ::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(_InputIterator __first, _InputIterator __last, + const allocator_type& __a) + : __r_(__default_init_tag(), __a) { + __init(__first, __last); + std::__debug_db_insert_c(this); + } - template::value> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(_InputIterator __first, _InputIterator __last); - template::value> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a); #ifndef _LIBCPP_CXX03_LANG - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(initializer_list<_CharT> __il); - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 - basic_string(initializer_list<_CharT> __il, const _Allocator& __a); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(initializer_list<_CharT> __il) + : __r_(__default_init_tag(), __default_init_tag()) { + __init(__il.begin(), __il.end()); + std::__debug_db_insert_c(this); + } + + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string(initializer_list<_CharT> __il, const _Allocator& __a) + : __r_(__default_init_tag(), __a) { + __init(__il.begin(), __il.end()); + std::__debug_db_insert_c(this); + } #endif // _LIBCPP_CXX03_LANG - inline _LIBCPP_CONSTEXPR_AFTER_CXX17 ~basic_string(); + inline _LIBCPP_CONSTEXPR_AFTER_CXX17 ~basic_string() { + std::__debug_db_erase_c(this); + if (__is_long()) + __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); + } _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_AFTER_CXX17 operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); } @@ -884,10 +998,10 @@ _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(const basic_string& __str); template ::value && - !__is_same_uncvref<_Tp, basic_string>::value> > + !__is_same_uncvref<_Tp, basic_string>::value> > _LIBCPP_CONSTEXPR_AFTER_CXX17 basic_string& operator=(const _Tp& __t) { - __self_view __sv = __t; - return assign(__sv); + __self_view __sv = __t; + return assign(__sv); } #ifndef _LIBCPP_CXX03_LANG @@ -1871,30 +1985,6 @@ #endif // _LIBCPP_ENABLE_DEBUG_MODE } -template -inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string() - _NOEXCEPT_(is_nothrow_default_constructible::value) - : __r_(__default_init_tag(), __default_init_tag()) -{ - std::__debug_db_insert_c(this); - __default_init(); -} - -template -inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a) -#if _LIBCPP_STD_VER <= 14 - _NOEXCEPT_(is_nothrow_copy_constructible::value) -#else - _NOEXCEPT -#endif -: __r_(__default_init_tag(), __a) -{ - std::__debug_db_insert_c(this); - __default_init(); -} - template _LIBCPP_CONSTEXPR_AFTER_CXX17 void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, @@ -1952,64 +2042,6 @@ traits_type::assign(__p[__sz], value_type()); } -template -template -_LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a) - : __r_(__default_init_tag(), __a) -{ - _LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr"); - __init(__s, traits_type::length(__s)); - std::__debug_db_insert_c(this); -} - -template -inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n) - : __r_(__default_init_tag(), __default_init_tag()) -{ - _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr"); - __init(__s, __n); - std::__debug_db_insert_c(this); -} - -template -inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a) - : __r_(__default_init_tag(), __a) -{ - _LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr"); - __init(__s, __n); - std::__debug_db_insert_c(this); -} - -template -_LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) - : __r_(__default_init_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc())) -{ - if (!__str.__is_long()) - __r_.first().__r = __str.__r_.first().__r; - else - __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), - __str.__get_long_size()); - std::__debug_db_insert_c(this); -} - -template -_LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string( - const basic_string& __str, const allocator_type& __a) - : __r_(__default_init_tag(), __a) -{ - if (!__str.__is_long()) - __r_.first().__r = __str.__r_.first().__r; - else - __init_copy_ctor_external(std::__to_address(__str.__get_long_pointer()), - __str.__get_long_size()); - std::__debug_db_insert_c(this); -} - template _LIBCPP_CONSTEXPR_AFTER_CXX17 void basic_string<_CharT, _Traits, _Allocator>::__init_copy_ctor_external( @@ -2033,48 +2065,6 @@ traits_type::copy(std::__to_address(__p), __s, __sz + 1); } -#ifndef _LIBCPP_CXX03_LANG - -template -inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str) -#if _LIBCPP_STD_VER <= 14 - _NOEXCEPT_(is_nothrow_move_constructible::value) -#else - _NOEXCEPT -#endif - : __r_(std::move(__str.__r_)) -{ - __str.__default_init(); - std::__debug_db_insert_c(this); - if (__is_long()) - std::__debug_db_swap(this, &__str); -} - -template -inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a) - : __r_(__default_init_tag(), __a) -{ - if (__str.__is_long() && __a != __str.__alloc()) // copy, not move - __init(std::__to_address(__str.__get_long_pointer()), __str.__get_long_size()); - else - { - if (__libcpp_is_constant_evaluated()) { - __zero(); - __r_.first().__l = __str.__r_.first().__l; - } else { - __r_.first().__r = __str.__r_.first().__r; - } - __str.__default_init(); - } - std::__debug_db_insert_c(this); - if (__is_long()) - std::__debug_db_swap(this, &__str); -} - -#endif // _LIBCPP_CXX03_LANG - template _LIBCPP_CONSTEXPR_AFTER_CXX17 void @@ -2103,87 +2093,6 @@ traits_type::assign(__p[__n], value_type()); } -template -inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c) - : __r_(__default_init_tag(), __default_init_tag()) -{ - __init(__n, __c); - std::__debug_db_insert_c(this); -} - -template -template -_LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a) - : __r_(__default_init_tag(), __a) -{ - __init(__n, __c); - std::__debug_db_insert_c(this); -} - -template -_LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, - size_type __pos, size_type __n, - const _Allocator& __a) - : __r_(__default_init_tag(), __a) -{ - size_type __str_sz = __str.size(); - if (__pos > __str_sz) - __throw_out_of_range(); - __init(__str.data() + __pos, std::min(__n, __str_sz - __pos)); - std::__debug_db_insert_c(this); -} - -template -inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos, - const _Allocator& __a) - : __r_(__default_init_tag(), __a) -{ - size_type __str_sz = __str.size(); - if (__pos > __str_sz) - __throw_out_of_range(); - __init(__str.data() + __pos, __str_sz - __pos); - std::__debug_db_insert_c(this); -} - -template -template -_LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string( - const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a) - : __r_(__default_init_tag(), __a) -{ - __self_view __sv0 = __t; - __self_view __sv = __sv0.substr(__pos, __n); - __init(__sv.data(), __sv.size()); - std::__debug_db_insert_c(this); -} - -template -template -_LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t) - : __r_(__default_init_tag(), __default_init_tag()) -{ - __self_view __sv = __t; - __init(__sv.data(), __sv.size()); - std::__debug_db_insert_c(this); -} - -template -template -_LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a) - : __r_(__default_init_tag(), __a) -{ - __self_view __sv = __t; - __init(__sv.data(), __sv.size()); - std::__debug_db_insert_c(this); -} - template template _LIBCPP_CONSTEXPR_AFTER_CXX17 @@ -2259,60 +2168,6 @@ #endif // _LIBCPP_NO_EXCEPTIONS } -template -template -inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last) - : __r_(__default_init_tag(), __default_init_tag()) -{ - __init(__first, __last); - std::__debug_db_insert_c(this); -} - -template -template -inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last, - const allocator_type& __a) - : __r_(__default_init_tag(), __a) -{ - __init(__first, __last); - std::__debug_db_insert_c(this); -} - -#ifndef _LIBCPP_CXX03_LANG - -template -inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string( - initializer_list<_CharT> __il) - : __r_(__default_init_tag(), __default_init_tag()) -{ - __init(__il.begin(), __il.end()); - std::__debug_db_insert_c(this); -} - -template -inline _LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::basic_string( - initializer_list<_CharT> __il, const _Allocator& __a) - : __r_(__default_init_tag(), __a) -{ - __init(__il.begin(), __il.end()); - std::__debug_db_insert_c(this); -} - -#endif // _LIBCPP_CXX03_LANG - -template -_LIBCPP_CONSTEXPR_AFTER_CXX17 -basic_string<_CharT, _Traits, _Allocator>::~basic_string() -{ - std::__debug_db_erase_c(this); - if (__is_long()) - __alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap()); -} - template _LIBCPP_CONSTEXPR_AFTER_CXX17 void