diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -816,94 +816,156 @@ } public: - _LIBCPP_TEMPLATE_DATA_VIS - static const size_type npos = -1; + _LIBCPP_TEMPLATE_DATA_VIS static const size_type npos = -1; - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string() - _NOEXCEPT_(is_nothrow_default_constructible::value); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string() + _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_SINCE_CXX20 explicit basic_string(const allocator_type& __a) + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string(const allocator_type& __a) #if _LIBCPP_STD_VER <= 14 - _NOEXCEPT_(is_nothrow_copy_constructible::value); + _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_SINCE_CXX20 basic_string(const basic_string& __str); - _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str, const allocator_type& __a); + _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str); + _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const basic_string& __str, const allocator_type& __a); #ifndef _LIBCPP_CXX03_LANG - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - basic_string(basic_string&& __str) -#if _LIBCPP_STD_VER <= 14 - _NOEXCEPT_(is_nothrow_move_constructible::value); -#else - _NOEXCEPT; -#endif + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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); + } - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - basic_string(basic_string&& __str, const allocator_type& __a); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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()) + __r_.first() = __rep(); + __r_.first() = __str.__r_.first(); + __str.__default_init(); + } + std::__debug_db_insert_c(this); + if (__is_long()) + std::__debug_db_swap(this, &__str); + } #endif // _LIBCPP_CXX03_LANG - template ::value, nullptr_t> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - 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_SINCE_CXX20 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_SINCE_CXX20 - basic_string(const _CharT* __s, const _Allocator& __a); + template ::value, nullptr_t> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 basic_string(const _CharT* __s, const _Allocator& __a); #if _LIBCPP_STD_VER > 20 - basic_string(nullptr_t) = delete; + basic_string(nullptr_t) = delete; #endif - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - basic_string(const _CharT* __s, size_type __n); - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - basic_string(const _CharT* __s, size_type __n, const _Allocator& __a); - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - basic_string(size_type __n, _CharT __c); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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_SINCE_CXX20 - basic_string(size_type __n, _CharT __c, const _Allocator& __a); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 + 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_SINCE_CXX20 - basic_string(const basic_string& __str, size_type __pos, size_type __n, - const _Allocator& __a = _Allocator()); - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - basic_string(const basic_string& __str, size_type __pos, - const _Allocator& __a = _Allocator()); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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_SINCE_CXX20 - 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_SINCE_CXX20 basic_string(size_type __n, _CharT __c, const _Allocator& __a); - template::value && - !__is_same_uncvref<_Tp, basic_string>::value> > - _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 - explicit basic_string(const _Tp& __t); + _LIBCPP_CONSTEXPR_SINCE_CXX20 + basic_string(const basic_string& __str, size_type __pos, size_type __n, const _Allocator& __a = _Allocator()); - template::value && !__is_same_uncvref<_Tp, basic_string>::value> > - _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 - explicit basic_string(const _Tp& __t, const allocator_type& __a); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 + 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_SINCE_CXX20 + basic_string(const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a = allocator_type()); + + template ::value && + !__is_same_uncvref<_Tp, basic_string>::value> > + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( + const _Tp& __t); + + template ::value && + !__is_same_uncvref<_Tp, basic_string>::value> > + _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS _LIBCPP_CONSTEXPR_SINCE_CXX20 explicit basic_string( + const _Tp& __t, const allocator_type& __a); + + template ::value> > + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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_SINCE_CXX20 + 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_SINCE_CXX20 - basic_string(_InputIterator __first, _InputIterator __last); - template::value> > - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a); #ifndef _LIBCPP_CXX03_LANG - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - basic_string(initializer_list<_CharT> __il); - _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 - basic_string(initializer_list<_CharT> __il, const _Allocator& __a); + _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 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_SINCE_CXX20 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_SINCE_CXX20 ~basic_string(); @@ -1896,30 +1958,6 @@ #endif // _LIBCPP_ENABLE_DEBUG_MODE } -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX20 -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_SINCE_CXX20 -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_SINCE_CXX20 void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, @@ -1988,26 +2026,6 @@ std::__debug_db_insert_c(this); } -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX20 -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_SINCE_CXX20 -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_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str) @@ -2059,45 +2077,6 @@ traits_type::copy(std::__to_address(__p), __s, __sz + 1); } -#ifndef _LIBCPP_CXX03_LANG - -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX20 -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_SINCE_CXX20 -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()) - __r_.first() = __rep(); - __r_.first() = __str.__r_.first(); - __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_SINCE_CXX20 void @@ -2127,15 +2106,6 @@ traits_type::assign(__p[__n], value_type()); } -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX20 -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_SINCE_CXX20 @@ -2160,19 +2130,6 @@ std::__debug_db_insert_c(this); } -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX20 -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_SINCE_CXX20 @@ -2283,51 +2240,6 @@ #endif // _LIBCPP_NO_EXCEPTIONS } -template -template -inline _LIBCPP_CONSTEXPR_SINCE_CXX20 -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_SINCE_CXX20 -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_SINCE_CXX20 -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_SINCE_CXX20 -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_SINCE_CXX20 basic_string<_CharT, _Traits, _Allocator>::~basic_string()