diff --git a/libcxx/include/__functional/function.h b/libcxx/include/__functional/function.h --- a/libcxx/include/__functional/function.h +++ b/libcxx/include/__functional/function.h @@ -196,9 +196,7 @@ __alloc_func* __clone() const { typedef allocator_traits<_Alloc> __alloc_traits; - typedef - typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type - _AA; + typedef __rebind_alloc<__alloc_traits, __alloc_func> _AA; _AA __a(__f_.second()); typedef __allocator_destructor<_AA> _Dp; unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -211,8 +209,7 @@ static void __destroy_and_delete(__alloc_func* __f) { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type - _FunAlloc; + typedef __rebind_alloc<__alloc_traits, __alloc_func> _FunAlloc; _FunAlloc __a(__f->__get_allocator()); __f->destroy(); __a.deallocate(__f, 1); @@ -325,7 +322,7 @@ __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + typedef __rebind_alloc<__alloc_traits, __func> _Ap; _Ap __a(__f_.__get_allocator()); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -352,7 +349,7 @@ __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + typedef __rebind_alloc<__alloc_traits, __func> _Ap; _Ap __a(__f_.__get_allocator()); __f_.destroy(); __a.deallocate(this, 1); @@ -411,8 +408,7 @@ { typedef allocator_traits<_Alloc> __alloc_traits; typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; - typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type - _FunAlloc; + typedef __rebind_alloc<__alloc_traits, _Fun> _FunAlloc; if (__function::__not_null(__f)) { @@ -753,8 +749,7 @@ { typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type - _FunAlloc; + typedef __rebind_alloc<__alloc_traits, _Fun> _FunAlloc; if (__function::__not_null(__f)) { @@ -1354,7 +1349,7 @@ __func<_Fp, _Alloc, _Rp()>::__clone() const { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + typedef __rebind_alloc<__alloc_traits, __func> _Ap; _Ap __a(__f_.second()); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -1381,7 +1376,7 @@ __func<_Fp, _Alloc, _Rp()>::destroy_deallocate() { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + typedef __rebind_alloc<__alloc_traits, __func> _Ap; _Ap __a(__f_.second()); __f_.~__compressed_pair<_Fp, _Alloc>(); __a.deallocate(this, 1); @@ -1440,7 +1435,7 @@ __func<_Fp, _Alloc, _Rp(_A0)>::__clone() const { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + typedef __rebind_alloc<__alloc_traits, __func> _Ap; _Ap __a(__f_.second()); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -1467,7 +1462,7 @@ __func<_Fp, _Alloc, _Rp(_A0)>::destroy_deallocate() { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + typedef __rebind_alloc<__alloc_traits, __func> _Ap; _Ap __a(__f_.second()); __f_.~__compressed_pair<_Fp, _Alloc>(); __a.deallocate(this, 1); @@ -1526,7 +1521,7 @@ __func<_Fp, _Alloc, _Rp(_A0, _A1)>::__clone() const { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + typedef __rebind_alloc<__alloc_traits, __func> _Ap; _Ap __a(__f_.second()); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -1553,7 +1548,7 @@ __func<_Fp, _Alloc, _Rp(_A0, _A1)>::destroy_deallocate() { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + typedef __rebind_alloc<__alloc_traits, __func> _Ap; _Ap __a(__f_.second()); __f_.~__compressed_pair<_Fp, _Alloc>(); __a.deallocate(this, 1); @@ -1612,7 +1607,7 @@ __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::__clone() const { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + typedef __rebind_alloc<__alloc_traits, __func> _Ap; _Ap __a(__f_.second()); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -1639,7 +1634,7 @@ __func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)>::destroy_deallocate() { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; + typedef __rebind_alloc<__alloc_traits, __func> _Ap; _Ap __a(__f_.second()); __f_.~__compressed_pair<_Fp, _Alloc>(); __a.deallocate(this, 1); @@ -1815,7 +1810,7 @@ } else { - typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; + typedef __rebind_alloc<__alloc_traits, _FF> _Ap; _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -2093,7 +2088,7 @@ } else { - typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; + typedef __rebind_alloc<__alloc_traits, _FF> _Ap; _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -2371,7 +2366,7 @@ } else { - typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; + typedef __rebind_alloc<__alloc_traits, _FF> _Ap; _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -2649,7 +2644,7 @@ } else { - typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; + typedef __rebind_alloc<__alloc_traits, _FF> _Ap; _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); diff --git a/libcxx/include/__hash_table b/libcxx/include/__hash_table --- a/libcxx/include/__hash_table +++ b/libcxx/include/__hash_table @@ -901,7 +901,7 @@ // Create __node typedef typename _NodeTypes::__node_type __node; - typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; + typedef __rebind_alloc<__alloc_traits, __node> __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; typedef typename _NodeTypes::__void_pointer __void_pointer; typedef typename _NodeTypes::__node_pointer __node_pointer; @@ -916,15 +916,14 @@ // the pointer using 'pointer_traits'. static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value), "Allocator does not rebind pointers in a sane manner."); - typedef typename __rebind_alloc_helper<__node_traits, __first_node>::type - __node_base_allocator; + typedef __rebind_alloc<__node_traits, __first_node> __node_base_allocator; typedef allocator_traits<__node_base_allocator> __node_base_traits; static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value), "Allocator does not rebind pointers in a sane manner."); private: - typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator; + typedef __rebind_alloc<__node_traits, __next_pointer> __pointer_allocator; typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter; typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list; typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits; diff --git a/libcxx/include/__memory/allocator_traits.h b/libcxx/include/__memory/allocator_traits.h --- a/libcxx/include/__memory/allocator_traits.h +++ b/libcxx/include/__memory/allocator_traits.h @@ -349,14 +349,13 @@ } }; -template -struct __rebind_alloc_helper { #ifndef _LIBCPP_CXX03_LANG - using type _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>; +template +using __rebind_alloc _LIBCPP_NODEBUG = typename _Traits::template rebind_alloc<_Tp>; #else - using type = typename _Traits::template rebind_alloc<_Tp>::other; +template +using __rebind_alloc = typename _Traits::template rebind_alloc<_Tp>::other; #endif -}; // __is_default_allocator template diff --git a/libcxx/include/__tree b/libcxx/include/__tree --- a/libcxx/include/__tree +++ b/libcxx/include/__tree @@ -1025,7 +1025,7 @@ typedef typename _NodeTypes::__parent_pointer __parent_pointer; typedef typename _NodeTypes::__iter_pointer __iter_pointer; - typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; + typedef __rebind_alloc<__alloc_traits, __node> __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; private: @@ -1034,8 +1034,7 @@ // the pointer using 'pointer_traits'. static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value), "Allocator does not rebind pointers in a sane manner."); - typedef typename __rebind_alloc_helper<__node_traits, __node_base>::type - __node_base_allocator; + typedef __rebind_alloc<__node_traits, __node_base> __node_base_allocator; typedef allocator_traits<__node_base_allocator> __node_base_traits; static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value), "Allocator does not rebind pointers in a sane manner."); diff --git a/libcxx/include/deque b/libcxx/include/deque --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -955,8 +955,8 @@ using pointer = typename __alloc_traits::pointer; using const_pointer = typename __alloc_traits::const_pointer; - using __pointer_allocator = typename __rebind_alloc_helper<__alloc_traits, pointer>::type; - using __const_pointer_allocator = typename __rebind_alloc_helper<__alloc_traits, const_pointer>::type; + using __pointer_allocator = __rebind_alloc<__alloc_traits, pointer>; + using __const_pointer_allocator = __rebind_alloc<__alloc_traits, const_pointer>; using __map = __split_buffer; using __map_alloc_traits = allocator_traits<__pointer_allocator>; using __map_pointer = typename __map_alloc_traits::pointer; @@ -971,8 +971,9 @@ using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; - static_assert(is_same::type>::value, - "rebinding an allocator to value_type should result in the original allocator"); + static_assert(is_same >::value, + "[allocator.requirements] states that rebinding an allocator to the same type should result in the " + "original allocator"); static_assert(is_nothrow_default_constructible::value == is_nothrow_default_constructible<__pointer_allocator>::value, "rebinding an allocator should not change excpetion guarantees"); diff --git a/libcxx/include/ext/hash_map b/libcxx/include/ext/hash_map --- a/libcxx/include/ext/hash_map +++ b/libcxx/include/ext/hash_map @@ -483,8 +483,7 @@ typedef std::pair __value_type; typedef __hash_map_hasher<__value_type, hasher> __hasher; typedef __hash_map_equal<__value_type, key_equal> __key_equal; - typedef typename std::__rebind_alloc_helper< - std::allocator_traits, __value_type>::type __allocator_type; + typedef std::__rebind_alloc, __value_type> __allocator_type; typedef std::__hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; @@ -757,7 +756,7 @@ typedef std::pair __value_type; typedef __hash_map_hasher<__value_type, hasher> __hasher; typedef __hash_map_equal<__value_type, key_equal> __key_equal; - typedef typename std::__rebind_alloc_helper, __value_type>::type __allocator_type; + typedef std::__rebind_alloc, __value_type> __allocator_type; typedef std::__hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list --- a/libcxx/include/forward_list +++ b/libcxx/include/forward_list @@ -485,13 +485,11 @@ typedef typename allocator_traits::void_pointer void_pointer; typedef __forward_list_node __node; typedef typename __begin_node_of::type __begin_node; - typedef typename __rebind_alloc_helper, __node>::type __node_allocator; + typedef __rebind_alloc, __node> __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; typedef typename __node_traits::pointer __node_pointer; - typedef typename __rebind_alloc_helper< - allocator_traits, __begin_node - >::type __begin_node_allocator; + typedef __rebind_alloc, __begin_node> __begin_node_allocator; typedef typename allocator_traits<__begin_node_allocator>::pointer __begin_node_pointer; @@ -499,6 +497,10 @@ "internal allocator type must differ from user-specified " "type; otherwise overload resolution breaks"); + static_assert(is_same >::value, + "[allocator.requirements] states that rebinding an allocator to the same type should result in the " + "original allocator"); + __compressed_pair<__begin_node, __node_allocator> __before_begin_; _LIBCPP_INLINE_VISIBILITY diff --git a/libcxx/include/list b/libcxx/include/list --- a/libcxx/include/list +++ b/libcxx/include/list @@ -557,7 +557,7 @@ typedef __list_const_iterator const_iterator; typedef __list_node_base __node_base; typedef __list_node __node; - typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; + typedef __rebind_alloc<__alloc_traits, __node> __node_allocator; typedef allocator_traits<__node_allocator> __node_alloc_traits; typedef typename __node_alloc_traits::pointer __node_pointer; typedef typename __node_alloc_traits::pointer __node_const_pointer; @@ -568,7 +568,7 @@ typedef typename __alloc_traits::const_pointer const_pointer; typedef typename __alloc_traits::difference_type difference_type; - typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator; + typedef __rebind_alloc<__alloc_traits, __node_base> __node_base_allocator; typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer; static_assert((!is_same::value), "internal allocator type must differ from user-specified " @@ -847,6 +847,10 @@ typedef void __remove_return_type; #endif + static_assert(is_same, value_type> >::value, + "[allocator.requirements] states that rebinding an allocator to the same type should result in the " + "original allocator"); + _LIBCPP_INLINE_VISIBILITY list() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) diff --git a/libcxx/include/map b/libcxx/include/map --- a/libcxx/include/map +++ b/libcxx/include/map @@ -998,12 +998,15 @@ typedef _VSTD::__value_type __value_type; typedef __map_value_compare __vc; - typedef typename __rebind_alloc_helper, - __value_type>::type __allocator_type; + typedef __rebind_alloc, __value_type> __allocator_type; typedef __tree<__value_type, __vc, __allocator_type> __base; typedef typename __base::__node_traits __node_traits; typedef allocator_traits __alloc_traits; + static_assert(is_same >::value, + "[allocator.requirements] states that rebinding an allocator to the same type should result in the " + "original allocator"); + __base __tree_; public: @@ -1775,12 +1778,15 @@ typedef _VSTD::__value_type __value_type; typedef __map_value_compare __vc; - typedef typename __rebind_alloc_helper, - __value_type>::type __allocator_type; + typedef __rebind_alloc, __value_type> __allocator_type; typedef __tree<__value_type, __vc, __allocator_type> __base; typedef typename __base::__node_traits __node_traits; typedef allocator_traits __alloc_traits; + static_assert(is_same >::value, + "[allocator.requirements] states that rebinding an allocator to the same type should result in the " + "original allocator"); + __base __tree_; public: diff --git a/libcxx/include/set b/libcxx/include/set --- a/libcxx/include/set +++ b/libcxx/include/set @@ -530,6 +530,10 @@ typedef __tree __base; typedef allocator_traits __alloc_traits; + static_assert(is_same >::value, + "[allocator.requirements] states that rebinding an allocator to the same type should result in the " + "original allocator"); + __base __tree_; public: @@ -1063,6 +1067,10 @@ typedef __tree __base; typedef allocator_traits __alloc_traits; + static_assert(is_same >::value, + "[allocator.requirements] states that rebinding an allocator to the same type should result in the " + "original allocator"); + __base __tree_; public: diff --git a/libcxx/include/string b/libcxx/include/string --- a/libcxx/include/string +++ b/libcxx/include/string @@ -685,6 +685,10 @@ static_assert(( is_same::value), "Allocator::value_type must be same type as value_type"); + static_assert(is_same >::value, + "[allocator.requirements] states that rebinding an allocator to the same type should result in the " + "original allocator"); + typedef __wrap_iter iterator; typedef __wrap_iter const_iterator; typedef std::reverse_iterator reverse_iterator; diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -1040,8 +1040,7 @@ typedef __hash_value_type __value_type; typedef __unordered_map_hasher __hasher; typedef __unordered_map_equal __key_equal; - typedef typename __rebind_alloc_helper, - __value_type>::type __allocator_type; + typedef __rebind_alloc, __value_type> __allocator_type; typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; @@ -1058,6 +1057,10 @@ typedef unique_ptr<__node, _Dp> __node_holder; typedef allocator_traits __alloc_traits; + static_assert(is_same >::value, + "[allocator.requirements] states that rebinding an allocator to the same type should result in the " + "original allocator"); + static_assert((is_same::value), ""); static_assert((is_same::value), ""); public: @@ -1930,8 +1933,7 @@ typedef __hash_value_type __value_type; typedef __unordered_map_hasher __hasher; typedef __unordered_map_equal __key_equal; - typedef typename __rebind_alloc_helper, - __value_type>::type __allocator_type; + typedef __rebind_alloc, __value_type> __allocator_type; typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; @@ -1948,7 +1950,12 @@ static_assert((is_same::value), "Allocator uses different size_type for different types"); -public: + + static_assert(is_same >::value, + "[allocator.requirements] states that rebinding an allocator to the same type should result in the " + "original allocator"); + + public: typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; typedef typename __table::size_type size_type; diff --git a/libcxx/include/unordered_set b/libcxx/include/unordered_set --- a/libcxx/include/unordered_set +++ b/libcxx/include/unordered_set @@ -514,7 +514,11 @@ static_assert((is_same::value), "Invalid allocator::value_type"); -private: + static_assert(is_same, value_type> >::value, + "[allocator.requirements] states that rebinding an allocator to the same type should result in the " + "original allocator"); + + private: typedef __hash_table __table; __table __table_; diff --git a/libcxx/include/vector b/libcxx/include/vector --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -357,6 +357,10 @@ static_assert((is_same::value), "Allocator::value_type must be same type as value_type"); + static_assert(is_same >::value, + "[allocator.requirements] states that rebinding an allocator to the same type should result in the " + "original allocator"); + _LIBCPP_CONSTEXPR_SINCE_CXX20 _LIBCPP_HIDE_FROM_ABI vector() _NOEXCEPT_(is_nothrow_default_constructible::value) { @@ -2064,7 +2068,7 @@ typedef std::reverse_iterator const_reverse_iterator; private: - typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator; + typedef __rebind_alloc<__alloc_traits, __storage_type> __storage_allocator; typedef allocator_traits<__storage_allocator> __storage_traits; typedef typename __storage_traits::pointer __storage_pointer; typedef typename __storage_traits::const_pointer __const_storage_pointer;