From 24e817d22383879994baa0a8ac61624f282f8f75 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sun, 23 Aug 2015 02:34:18 +0000 Subject: [PATCH] Cleanup fancy pointer rebinding in list using __rebind_pointer. Currently we need an #ifdef branch every time we use pointer traits to rebind a pointer because it is done differently in C++11 and C++03. This patch introduces the __rebind_pointer utility to clean this up. llvm-svn: 245802 --- libcxx/include/list | 47 ++++++++----------------------------------- libcxx/include/memory | 9 +++++++++ 2 files changed, 17 insertions(+), 39 deletions(-) diff --git a/libcxx/include/list b/libcxx/include/list index 14201a80e348..0af65ab343c8 100644 --- a/libcxx/include/list +++ b/libcxx/include/list @@ -191,19 +191,10 @@ template struct __list_node; template struct __list_node_base { - typedef typename pointer_traits<_VoidPtr>::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind<__list_node<_Tp, _VoidPtr> > pointer; -#else - rebind<__list_node<_Tp, _VoidPtr> >::other pointer; -#endif - - typedef typename pointer_traits<_VoidPtr>::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind<__list_node_base> __base_pointer; -#else - rebind<__list_node_base>::other __base_pointer; -#endif + typedef typename __rebind_pointer<_VoidPtr, __list_node<_Tp, _VoidPtr> >::type + pointer; + typedef typename __rebind_pointer<_VoidPtr, __list_node_base>::type + __base_pointer; pointer __prev_; pointer __next_; @@ -232,12 +223,7 @@ template class _LIBCPP_TYPE_VIS_ONLY __list_const_it template class _LIBCPP_TYPE_VIS_ONLY __list_iterator { - typedef typename pointer_traits<_VoidPtr>::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind<__list_node<_Tp, _VoidPtr> > __node_pointer; -#else - rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer; -#endif + typedef typename __list_node<_Tp, _VoidPtr>::pointer __node_pointer; __node_pointer __ptr_; @@ -262,13 +248,7 @@ public: typedef bidirectional_iterator_tag iterator_category; typedef _Tp value_type; typedef value_type& reference; - typedef typename pointer_traits<_VoidPtr>::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind -#else - rebind::other -#endif - pointer; + typedef typename __rebind_pointer<_VoidPtr, value_type>::type pointer; typedef typename pointer_traits::difference_type difference_type; _LIBCPP_INLINE_VISIBILITY @@ -365,12 +345,7 @@ public: template class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator { - typedef typename pointer_traits<_VoidPtr>::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind<__list_node<_Tp, _VoidPtr> > __node_pointer; -#else - rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer; -#endif + typedef typename __list_node<_Tp, _VoidPtr>::pointer __node_pointer; __node_pointer __ptr_; @@ -392,13 +367,7 @@ public: typedef bidirectional_iterator_tag iterator_category; typedef _Tp value_type; typedef const value_type& reference; - typedef typename pointer_traits<_VoidPtr>::template -#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind -#else - rebind::other -#endif - pointer; + typedef typename __rebind_pointer<_VoidPtr, const value_type>::type pointer; typedef typename pointer_traits::difference_type difference_type; _LIBCPP_INLINE_VISIBILITY diff --git a/libcxx/include/memory b/libcxx/include/memory index 38ce433b2f2a..9d214beb68f6 100644 --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -932,6 +932,15 @@ public: {return _VSTD::addressof(__r);} }; +template +struct __rebind_pointer { +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + typedef typename pointer_traits<_From>::template rebind<_To> type; +#else + typedef typename pointer_traits<_From>::template rebind<_To>::other type; +#endif +}; + // allocator_traits namespace __has_pointer_type_imp