diff options
Diffstat (limited to 'include/string')
| -rw-r--r-- | include/string | 113 |
1 files changed, 76 insertions, 37 deletions
diff --git a/include/string b/include/string index 6be21955b146..ee5db1aab63b 100644 --- a/include/string +++ b/include/string @@ -115,8 +115,8 @@ public: basic_string& operator=(const basic_string& str); basic_string& operator=(basic_string&& str) noexcept( - allocator_type::propagate_on_container_move_assignment::value && - is_nothrow_move_assignable<allocator_type>::value); + allocator_type::propagate_on_container_move_assignment::value || + allocator_type::is_always_equal::value ); // C++17 basic_string& operator=(const value_type* s); basic_string& operator=(value_type c); basic_string& operator=(initializer_list<value_type>); @@ -517,10 +517,14 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits {return __c1 < __c2;} static int compare(const char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY static size_t length(const char_type* __s); + _LIBCPP_INLINE_VISIBILITY static const char_type* find(const char_type* __s, size_t __n, const char_type& __a); static char_type* move(char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY static char_type* assign(char_type* __s, size_t __n, char_type __a); static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT @@ -550,7 +554,7 @@ char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_ } template <class _CharT> -inline _LIBCPP_INLINE_VISIBILITY +inline size_t char_traits<_CharT>::length(const char_type* __s) { @@ -561,7 +565,7 @@ char_traits<_CharT>::length(const char_type* __s) } template <class _CharT> -inline _LIBCPP_INLINE_VISIBILITY +inline const _CharT* char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a) { @@ -595,7 +599,7 @@ char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n) } template <class _CharT> -inline _LIBCPP_INLINE_VISIBILITY +inline _CharT* char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n) { @@ -607,7 +611,7 @@ char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n) } template <class _CharT> -inline _LIBCPP_INLINE_VISIBILITY +inline _CharT* char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a) { @@ -726,11 +730,17 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t> static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 < __c2;} + _LIBCPP_INLINE_VISIBILITY static int compare(const char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY static size_t length(const char_type* __s); + _LIBCPP_INLINE_VISIBILITY static const char_type* find(const char_type* __s, size_t __n, const char_type& __a); + _LIBCPP_INLINE_VISIBILITY static char_type* move(char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY static char_type* assign(char_type* __s, size_t __n, char_type __a); static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT @@ -742,10 +752,10 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char16_t> static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT {return __c1 == __c2;} static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT - {return int_type(0xDFFF);} + {return int_type(0xFFFF);} }; -inline _LIBCPP_INLINE_VISIBILITY +inline int char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) { @@ -759,7 +769,7 @@ char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, siz return 0; } -inline _LIBCPP_INLINE_VISIBILITY +inline size_t char_traits<char16_t>::length(const char_type* __s) { @@ -769,7 +779,7 @@ char_traits<char16_t>::length(const char_type* __s) return __len; } -inline _LIBCPP_INLINE_VISIBILITY +inline const char16_t* char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a) { @@ -782,7 +792,7 @@ char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& _ return 0; } -inline _LIBCPP_INLINE_VISIBILITY +inline char16_t* char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n) { @@ -802,7 +812,7 @@ char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n) return __r; } -inline _LIBCPP_INLINE_VISIBILITY +inline char16_t* char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) { @@ -813,7 +823,7 @@ char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) return __r; } -inline _LIBCPP_INLINE_VISIBILITY +inline char16_t* char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a) { @@ -839,11 +849,17 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t> static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 < __c2;} + _LIBCPP_INLINE_VISIBILITY static int compare(const char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY static size_t length(const char_type* __s); + _LIBCPP_INLINE_VISIBILITY static const char_type* find(const char_type* __s, size_t __n, const char_type& __a); + _LIBCPP_INLINE_VISIBILITY static char_type* move(char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); + _LIBCPP_INLINE_VISIBILITY static char_type* assign(char_type* __s, size_t __n, char_type __a); static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT @@ -858,7 +874,7 @@ struct _LIBCPP_TYPE_VIS_ONLY char_traits<char32_t> {return int_type(0xFFFFFFFF);} }; -inline _LIBCPP_INLINE_VISIBILITY +inline int char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) { @@ -872,7 +888,7 @@ char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, siz return 0; } -inline _LIBCPP_INLINE_VISIBILITY +inline size_t char_traits<char32_t>::length(const char_type* __s) { @@ -882,7 +898,7 @@ char_traits<char32_t>::length(const char_type* __s) return __len; } -inline _LIBCPP_INLINE_VISIBILITY +inline const char32_t* char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a) { @@ -895,7 +911,7 @@ char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& _ return 0; } -inline _LIBCPP_INLINE_VISIBILITY +inline char32_t* char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n) { @@ -915,7 +931,7 @@ char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n) return __r; } -inline _LIBCPP_INLINE_VISIBILITY +inline char32_t* char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) { @@ -926,7 +942,7 @@ char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) return __r; } -inline _LIBCPP_INLINE_VISIBILITY +inline char32_t* char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a) { @@ -1185,7 +1201,7 @@ _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_TYPE_VIS __basic_string_common<true>) #pragma warning( pop ) #endif // _LIBCPP_MSVC -#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT +#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT template <class _CharT, size_t = sizeof(_CharT)> struct __padding @@ -1198,7 +1214,7 @@ struct __padding<_CharT, 1> { }; -#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT +#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT template<class _CharT, class _Traits, class _Allocator> class _LIBCPP_TYPE_VIS_ONLY basic_string @@ -1234,7 +1250,7 @@ public: private: -#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT +#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT struct __long { @@ -1294,7 +1310,7 @@ private: value_type __data_[__min_cap]; }; -#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT +#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT union __ulx{__long __lx; __short __lxx;}; @@ -1377,8 +1393,7 @@ public: #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY basic_string& operator=(basic_string&& __str) - _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && - is_nothrow_move_assignable<allocator_type>::value); + _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)); #endif _LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);} basic_string& operator=(value_type __c); @@ -1445,7 +1460,8 @@ public: _LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();} _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT - {return (__is_long() ? __get_long_cap() : __min_cap) - 1;} + {return (__is_long() ? __get_long_cap() + : static_cast<size_type>(__min_cap)) - 1;} void resize(size_type __n, value_type __c); _LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());} @@ -1509,6 +1525,7 @@ public: #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY basic_string& assign(basic_string&& str) + _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) {*this = _VSTD::move(str); return *this;} #endif basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos); @@ -1697,7 +1714,7 @@ private: const allocator_type& __alloc() const _NOEXCEPT {return __r_.second();} -#ifdef _LIBCPP_ALTERNATE_STRING_LAYOUT +#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT _LIBCPP_INLINE_VISIBILITY void __set_short_size(size_type __s) _NOEXCEPT @@ -1715,7 +1732,7 @@ private: {return __r_.first().__s.__size_;} # endif -#else // _LIBCPP_ALTERNATE_STRING_LAYOUT +#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT _LIBCPP_INLINE_VISIBILITY void __set_short_size(size_type __s) _NOEXCEPT @@ -1733,7 +1750,7 @@ private: {return __r_.first().__s.__size_ >> 1;} # endif -#endif // _LIBCPP_ALTERNATE_STRING_LAYOUT +#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT _LIBCPP_INLINE_VISIBILITY void __set_long_size(size_type __s) _NOEXCEPT @@ -1785,11 +1802,11 @@ private: template <size_type __a> static _LIBCPP_INLINE_VISIBILITY size_type __align_it(size_type __s) _NOEXCEPT - {return __s + (__a-1) & ~(__a-1);} + {return (__s + (__a-1)) & ~(__a-1);} enum {__alignment = 16}; static _LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __s) _NOEXCEPT - {return (__s < __min_cap ? __min_cap : + {return (__s < __min_cap ? static_cast<size_type>(__min_cap) : __align_it<sizeof(value_type) < __alignment ? __alignment/sizeof(value_type) : 1 > (__s+1)) - 1;} @@ -1845,11 +1862,16 @@ private: #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_INLINE_VISIBILITY - void __move_assign(basic_string& __str, false_type); + void __move_assign(basic_string& __str, false_type) + _NOEXCEPT_(__alloc_traits::is_always_equal::value); _LIBCPP_INLINE_VISIBILITY void __move_assign(basic_string& __str, true_type) +#if _LIBCPP_STD_VER > 14 + _NOEXCEPT; +#else _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value); #endif +#endif _LIBCPP_INLINE_VISIBILITY void @@ -1936,7 +1958,12 @@ basic_string<_CharT, _Traits, _Allocator>::basic_string() template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a) - : __r_(__a) +#if _LIBCPP_STD_VER <= 14 + _NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value) +#else + _NOEXCEPT +#endif +: __r_(__a) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_c(this); @@ -2425,6 +2452,7 @@ template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY void basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type) + _NOEXCEPT_(__alloc_traits::is_always_equal::value) { if (__alloc() != __str.__alloc()) assign(__str); @@ -2436,7 +2464,11 @@ template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY void basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type) +#if _LIBCPP_STD_VER > 14 + _NOEXCEPT +#else _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) +#endif { clear(); shrink_to_fit(); @@ -2449,8 +2481,7 @@ template <class _CharT, class _Traits, class _Allocator> inline _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, _Allocator>& basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str) - _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && - is_nothrow_move_assignable<allocator_type>::value) + _NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value)) { __move_assign(__str, integral_constant<bool, __alloc_traits::propagate_on_container_move_assignment::value>()); @@ -3782,7 +3813,11 @@ bool operator==(const _CharT* __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT { - return __rhs.compare(__lhs) == 0; + typedef basic_string<_CharT, _Traits, _Allocator> _String; + _LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr"); + size_t __lhs_len = _Traits::length(__lhs); + if (__lhs_len != __rhs.size()) return false; + return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0; } template<class _CharT, class _Traits, class _Allocator> @@ -3791,7 +3826,11 @@ bool operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs, const _CharT* __rhs) _NOEXCEPT { - return __lhs.compare(__rhs) == 0; + typedef basic_string<_CharT, _Traits, _Allocator> _String; + _LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr"); + size_t __rhs_len = _Traits::length(__rhs); + if (__rhs_len != __lhs.size()) return false; + return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0; } // operator!= |
