From 1f508014df7da33d684a5c0cb3c059a675a0aacf Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Tue, 7 Apr 2015 05:21:38 +0000 Subject: [PATCH] In many places, there was an #ifdef/#else block that selected one of two implmentations of rebind_alloc based on whether or not we had template aliases. Create a helper struct to encapsulate that bit of logic, and replace all the ifdefs with uses of that struct. No functionality change intented. llvm-svn: 234296 --- libcxx/include/__functional_03 | 32 ++++---------------------------- libcxx/include/__hash_table | 16 ++-------------- libcxx/include/__tree | 8 +------- libcxx/include/deque | 16 ++-------------- libcxx/include/ext/hash_map | 16 ++-------------- libcxx/include/forward_list | 16 ++-------------- libcxx/include/functional | 24 +++--------------------- libcxx/include/list | 16 ++-------------- libcxx/include/map | 18 ++++-------------- libcxx/include/memory | 10 ++++++++++ libcxx/include/unordered_map | 18 ++++-------------- libcxx/include/vector | 8 +------- 12 files changed, 37 insertions(+), 161 deletions(-) diff --git a/libcxx/include/__functional_03 b/libcxx/include/__functional_03 index 157d6bf89325..785a2758c058 100644 --- a/libcxx/include/__functional_03 +++ b/libcxx/include/__functional_03 @@ -798,13 +798,7 @@ function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, } else { - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<_FF> -#else - rebind_alloc<_FF>::other -#endif - _Ap; + typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -1100,13 +1094,7 @@ function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, } else { - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<_FF> -#else - rebind_alloc<_FF>::other -#endif - _Ap; + typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -1402,13 +1390,7 @@ function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, } else { - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<_FF> -#else - rebind_alloc<_FF>::other -#endif - _Ap; + typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; _Ap __a(__a0); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -1704,13 +1686,7 @@ function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp } else { - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<_FF> -#else - rebind_alloc<_FF>::other -#endif - _Ap; + typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _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 index 71b12b36e540..e41ccf293eb4 100644 --- a/libcxx/include/__hash_table +++ b/libcxx/include/__hash_table @@ -775,13 +775,7 @@ public: public: // Create __node typedef __hash_node __node; - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__node> -#else - rebind_alloc<__node>::other -#endif - __node_allocator; + typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; typedef typename __node_traits::pointer __node_pointer; typedef typename __node_traits::pointer __node_const_pointer; @@ -796,13 +790,7 @@ public: private: - typedef typename __node_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__node_pointer> -#else - rebind_alloc<__node_pointer>::other -#endif - __pointer_allocator; + typedef typename __rebind_alloc_helper<__node_traits, __node_pointer>::type __pointer_allocator; typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter; typedef unique_ptr<__node_pointer[], __bucket_list_deleter> __bucket_list; typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits; diff --git a/libcxx/include/__tree b/libcxx/include/__tree index 77bf08126548..588f43807667 100644 --- a/libcxx/include/__tree +++ b/libcxx/include/__tree @@ -802,13 +802,7 @@ public: typedef __tree_node __node; typedef __tree_node_base<__void_pointer> __node_base; - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__node> -#else - rebind_alloc<__node>::other -#endif - __node_allocator; + typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; typedef typename __node_traits::pointer __node_pointer; typedef typename __node_traits::pointer __node_const_pointer; diff --git a/libcxx/include/deque b/libcxx/include/deque index 8d0d2a8f4990..78ef118c3059 100644 --- a/libcxx/include/deque +++ b/libcxx/include/deque @@ -912,22 +912,10 @@ protected: static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16; - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc -#else - rebind_alloc::other -#endif - __pointer_allocator; + typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator; typedef allocator_traits<__pointer_allocator> __map_traits; typedef typename __map_traits::pointer __map_pointer; - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc -#else - rebind_alloc::other -#endif - __const_pointer_allocator; + typedef typename __rebind_alloc_helper<__alloc_traits, const_pointer>::type __const_pointer_allocator; typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer; typedef __split_buffer __map; diff --git a/libcxx/include/ext/hash_map b/libcxx/include/ext/hash_map index 36cd595e0343..d8fc1e6c03c0 100644 --- a/libcxx/include/ext/hash_map +++ b/libcxx/include/ext/hash_map @@ -493,13 +493,7 @@ private: typedef pair __value_type; typedef __hash_map_hasher<__value_type, hasher> __hasher; typedef __hash_map_equal<__value_type, key_equal> __key_equal; - typedef typename allocator_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__value_type> -#else - rebind_alloc<__value_type>::other -#endif - __allocator_type; + typedef typename __rebind_alloc_helper, __value_type>::type __allocator_type; typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; @@ -772,13 +766,7 @@ private: typedef pair __value_type; typedef __hash_map_hasher<__value_type, hasher> __hasher; typedef __hash_map_equal<__value_type, key_equal> __key_equal; - typedef typename allocator_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__value_type> -#else - rebind_alloc<__value_type>::other -#endif - __allocator_type; + typedef typename __rebind_alloc_helper, __value_type>::type __allocator_type; typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; diff --git a/libcxx/include/forward_list b/libcxx/include/forward_list index a442a9b63867..fbb850c3b230 100644 --- a/libcxx/include/forward_list +++ b/libcxx/include/forward_list @@ -365,24 +365,12 @@ protected: typedef typename allocator_traits::void_pointer void_pointer; typedef __forward_list_node __node; typedef typename __begin_node_of::type __begin_node; - typedef typename allocator_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__node> -#else - rebind_alloc<__node>::other -#endif - __node_allocator; + typedef typename __rebind_alloc_helper, __node>::type __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; typedef typename __node_traits::pointer __node_pointer; typedef typename __node_traits::pointer __node_const_pointer; - typedef typename allocator_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__begin_node> -#else - rebind_alloc<__begin_node>::other -#endif - __begin_node_allocator; + typedef typename __rebind_alloc_helper, __begin_node>::type __begin_node_allocator; typedef typename allocator_traits<__begin_node_allocator>::pointer __begin_node_pointer; __compressed_pair<__begin_node, __node_allocator> __before_begin_; diff --git a/libcxx/include/functional b/libcxx/include/functional index 35e661b626a8..a5a212cc81ae 100644 --- a/libcxx/include/functional +++ b/libcxx/include/functional @@ -1368,13 +1368,7 @@ __base<_Rp(_ArgTypes...)>* __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__func> -#else - rebind_alloc<__func>::other -#endif - _Ap; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; _Ap __a(__f_.second()); typedef __allocator_destructor<_Ap> _Dp; unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); @@ -1401,13 +1395,7 @@ void __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT { typedef allocator_traits<_Alloc> __alloc_traits; - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__func> -#else - rebind_alloc<__func>::other -#endif - _Ap; + typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; _Ap __a(__f_.second()); __f_.~__compressed_pair<_Fp, _Alloc>(); __a.deallocate(this, 1); @@ -1668,13 +1656,7 @@ function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp _ if (__not_null(__f)) { typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF; - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<_FF> -#else - rebind_alloc<_FF>::other -#endif - _Ap; + typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap; _Ap __a(__a0); if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value) diff --git a/libcxx/include/list b/libcxx/include/list index c1a7a1821c43..d39f076711d9 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -515,13 +515,7 @@ protected: typedef __list_const_iterator const_iterator; typedef __list_node_base __node_base; typedef __list_node __node; - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__node> -#else - rebind_alloc<__node>::other -#endif - __node_allocator; + typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __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; @@ -529,13 +523,7 @@ protected: typedef typename __alloc_traits::const_pointer const_pointer; typedef typename __alloc_traits::difference_type difference_type; - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__node_base> -#else - rebind_alloc<__node_base>::other -#endif - __node_base_allocator; + typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator; typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer; __node_base __end_; diff --git a/libcxx/include/map b/libcxx/include/map index 0b5eb209490f..c8e8fd1f1dfd 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -822,13 +822,8 @@ private: typedef _VSTD::__value_type __value_type; typedef __map_value_compare __vc; - typedef typename allocator_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__value_type> -#else - rebind_alloc<__value_type>::other -#endif - __allocator_type; + typedef typename __rebind_alloc_helper, + __value_type>::type __allocator_type; typedef __tree<__value_type, __vc, __allocator_type> __base; typedef typename __base::__node_traits __node_traits; typedef allocator_traits __alloc_traits; @@ -1568,13 +1563,8 @@ private: typedef _VSTD::__value_type __value_type; typedef __map_value_compare __vc; - typedef typename allocator_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__value_type> -#else - rebind_alloc<__value_type>::other -#endif - __allocator_type; + typedef typename __rebind_alloc_helper, + __value_type>::type __allocator_type; typedef __tree<__value_type, __vc, __allocator_type> __base; typedef typename __base::__node_traits __node_traits; typedef allocator_traits __alloc_traits; diff --git a/libcxx/include/memory b/libcxx/include/memory index 43f8dbadadcd..93e8f67379bb 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -1635,6 +1635,16 @@ private: {return __a;} }; +template +struct __rebind_alloc_helper +{ +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + typedef typename _Traits::template rebind_alloc<_Tp> type; +#else + typedef typename _Traits::template rebind_alloc<_Tp>::other type; +#endif +}; + // allocator template diff --git a/libcxx/include/unordered_map b/libcxx/include/unordered_map index 0fa87d19ad03..3190ddf7fb2f 100644 --- a/libcxx/include/unordered_map +++ b/libcxx/include/unordered_map @@ -730,13 +730,8 @@ private: typedef __hash_value_type __value_type; typedef __unordered_map_hasher __hasher; typedef __unordered_map_equal __key_equal; - typedef typename allocator_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__value_type> -#else - rebind_alloc<__value_type>::other -#endif - __allocator_type; + typedef typename __rebind_alloc_helper, + __value_type>::type __allocator_type; typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; @@ -1469,13 +1464,8 @@ private: typedef __hash_value_type __value_type; typedef __unordered_map_hasher __hasher; typedef __unordered_map_equal __key_equal; - typedef typename allocator_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__value_type> -#else - rebind_alloc<__value_type>::other -#endif - __allocator_type; + typedef typename __rebind_alloc_helper, + __value_type>::type __allocator_type; typedef __hash_table<__value_type, __hasher, __key_equal, __allocator_type> __table; diff --git a/libcxx/include/vector b/libcxx/include/vector index efe21e111d0a..48e970a2f401 100644 --- a/libcxx/include/vector +++ b/libcxx/include/vector @@ -2125,13 +2125,7 @@ public: typedef _VSTD::reverse_iterator const_reverse_iterator; private: - typedef typename __alloc_traits::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind_alloc<__storage_type> -#else - rebind_alloc<__storage_type>::other -#endif - __storage_allocator; + typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::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;