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.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@234296 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/__functional_03 b/include/__functional_03
index 157d6bf..785a275 100644
--- a/include/__functional_03
+++ b/include/__functional_03
@@ -798,13 +798,7 @@
}
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 @@
}
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 @@
}
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 @@
}
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/include/__hash_table b/include/__hash_table
index 71b12b3..e41ccf2 100644
--- a/include/__hash_table
+++ b/include/__hash_table
@@ -775,13 +775,7 @@
public:
// Create __node
typedef __hash_node<value_type, typename __alloc_traits::void_pointer> __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 @@
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/include/__tree b/include/__tree
index 77bf081..588f438 100644
--- a/include/__tree
+++ b/include/__tree
@@ -802,13 +802,7 @@
typedef __tree_node<value_type, __void_pointer> __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/include/deque b/include/deque
index 8d0d2a8..78ef118 100644
--- a/include/deque
+++ b/include/deque
@@ -912,22 +912,10 @@
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<pointer>
-#else
- rebind_alloc<pointer>::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<const_pointer>
-#else
- rebind_alloc<const_pointer>::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<pointer, __pointer_allocator> __map;
diff --git a/include/ext/hash_map b/include/ext/hash_map
index 36cd595..d8fc1e6 100644
--- a/include/ext/hash_map
+++ b/include/ext/hash_map
@@ -493,13 +493,7 @@
typedef pair<key_type, mapped_type> __value_type;
typedef __hash_map_hasher<__value_type, hasher> __hasher;
typedef __hash_map_equal<__value_type, key_equal> __key_equal;
- typedef typename allocator_traits<allocator_type>::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<allocator_traits<allocator_type>, __value_type>::type __allocator_type;
typedef __hash_table<__value_type, __hasher,
__key_equal, __allocator_type> __table;
@@ -772,13 +766,7 @@
typedef pair<key_type, mapped_type> __value_type;
typedef __hash_map_hasher<__value_type, hasher> __hasher;
typedef __hash_map_equal<__value_type, key_equal> __key_equal;
- typedef typename allocator_traits<allocator_type>::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<allocator_traits<allocator_type>, __value_type>::type __allocator_type;
typedef __hash_table<__value_type, __hasher,
__key_equal, __allocator_type> __table;
diff --git a/include/forward_list b/include/forward_list
index a442a9b..fbb850c 100644
--- a/include/forward_list
+++ b/include/forward_list
@@ -365,24 +365,12 @@
typedef typename allocator_traits<allocator_type>::void_pointer void_pointer;
typedef __forward_list_node<value_type, void_pointer> __node;
typedef typename __begin_node_of<value_type, void_pointer>::type __begin_node;
- typedef typename allocator_traits<allocator_type>::template
-#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
- rebind_alloc<__node>
-#else
- rebind_alloc<__node>::other
-#endif
- __node_allocator;
+ typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __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<allocator_type>::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<allocator_traits<allocator_type>, __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/include/functional b/include/functional
index 35e661b..a5a212c 100644
--- a/include/functional
+++ b/include/functional
@@ -1368,13 +1368,7 @@
__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 @@
__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 @@
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/include/list b/include/list
index c1a7a18..d39f076 100644
--- a/include/list
+++ b/include/list
@@ -515,13 +515,7 @@
typedef __list_const_iterator<value_type, __void_pointer> const_iterator;
typedef __list_node_base<value_type, __void_pointer> __node_base;
typedef __list_node<value_type, __void_pointer> __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 @@
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/include/map b/include/map
index 0b5eb20..c8e8fd1 100644
--- a/include/map
+++ b/include/map
@@ -822,13 +822,8 @@
typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
- typedef typename allocator_traits<allocator_type>::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<allocator_traits<allocator_type>,
+ __value_type>::type __allocator_type;
typedef __tree<__value_type, __vc, __allocator_type> __base;
typedef typename __base::__node_traits __node_traits;
typedef allocator_traits<allocator_type> __alloc_traits;
@@ -1568,13 +1563,8 @@
typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
- typedef typename allocator_traits<allocator_type>::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<allocator_traits<allocator_type>,
+ __value_type>::type __allocator_type;
typedef __tree<__value_type, __vc, __allocator_type> __base;
typedef typename __base::__node_traits __node_traits;
typedef allocator_traits<allocator_type> __alloc_traits;
diff --git a/include/memory b/include/memory
index 43f8dba..93e8f67 100644
--- a/include/memory
+++ b/include/memory
@@ -1635,6 +1635,16 @@
{return __a;}
};
+template <class _Traits, class _Tp>
+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 <class _Tp>
diff --git a/include/unordered_map b/include/unordered_map
index 0fa87d1..3190ddf 100644
--- a/include/unordered_map
+++ b/include/unordered_map
@@ -730,13 +730,8 @@
typedef __hash_value_type<key_type, mapped_type> __value_type;
typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
- typedef typename allocator_traits<allocator_type>::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<allocator_traits<allocator_type>,
+ __value_type>::type __allocator_type;
typedef __hash_table<__value_type, __hasher,
__key_equal, __allocator_type> __table;
@@ -1469,13 +1464,8 @@
typedef __hash_value_type<key_type, mapped_type> __value_type;
typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
- typedef typename allocator_traits<allocator_type>::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<allocator_traits<allocator_type>,
+ __value_type>::type __allocator_type;
typedef __hash_table<__value_type, __hasher,
__key_equal, __allocator_type> __table;
diff --git a/include/vector b/include/vector
index efe21e1..48e970a 100644
--- a/include/vector
+++ b/include/vector
@@ -2125,13 +2125,7 @@
typedef _VSTD::reverse_iterator<const_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;