From patchwork Tue Nov 8 00:34:34 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 124226 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E63CE1007D5 for ; Tue, 8 Nov 2011 11:34:59 +1100 (EST) Received: (qmail 13646 invoked by alias); 8 Nov 2011 00:34:55 -0000 Received: (qmail 13390 invoked by uid 22791); 8 Nov 2011 00:34:52 -0000 X-SWARE-Spam-Status: No, hits=-2.5 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-wy0-f175.google.com (HELO mail-wy0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 08 Nov 2011 00:34:36 +0000 Received: by wyh5 with SMTP id 5so5667312wyh.20 for ; Mon, 07 Nov 2011 16:34:35 -0800 (PST) MIME-Version: 1.0 Received: by 10.216.15.14 with SMTP id e14mr4141243wee.21.1320712475283; Mon, 07 Nov 2011 16:34:35 -0800 (PST) Received: by 10.216.63.83 with HTTP; Mon, 7 Nov 2011 16:34:34 -0800 (PST) Date: Tue, 8 Nov 2011 00:34:34 +0000 Message-ID: Subject: [v3] use alias-declaration to complete allocator and pointer traits From: Jonathan Wakely To: "libstdc++" , gcc-patches Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The new alias-declaration support in trunk allows the std::pointer_traits and std::allocator_traits implementations to be finished, by replacing the __rebind::__type workarounds with the required alias-declarations. * include/bits/ptr_traits.h (__rebind): Replace with... (rebind): Implement using alias-declaration. * include/ext/pointer.h (__rebind): Replace with... (rebind): Implement using alias-declaration. * include/bits/alloc_traits.h (__rebind_alloc, __rebind_traits): Replace with... (rebind_alloc, rebind_traits): Implement using alias-declaration. * include/ext/alloc_traits.h (rebind): Use rebind_alloc instead of __rebind_alloc. * include/std/scoped_allocator (rebind): Likewise. Tested x86_64-linux and x86_64-netbsd, committed to trunk. Index: include/bits/ptr_traits.h =================================================================== --- include/bits/ptr_traits.h (revision 181128) +++ include/bits/ptr_traits.h (working copy) @@ -86,46 +86,19 @@ static const bool __value = _S_chk<_Ptr, _Up>(nullptr); }; - // hack to use _Tp::__rebind<_Up>::__type instead if that exists - template - class __ptrtr_rebind_helper2 - { - template - static constexpr bool - _S_chk(typename _Ptr2::template __rebind<_Up2>::__type*) - { return true; } - - template - static constexpr bool - _S_chk(...) - { return false; } - - public: - static const bool __value = _S_chk<_Ptr, _Up>(nullptr); - }; - - /* TODO: remove second bool when alias templates are supported */ template::__value, - bool = __ptrtr_rebind_helper2<_Tp, _Up>::__value> + bool = __ptrtr_rebind_helper<_Tp, _Up>::__value> struct __ptrtr_rebind; - template - struct __ptrtr_rebind<_Tp, _Up, true, _B2> + template + struct __ptrtr_rebind<_Tp, _Up, true> { typedef typename _Tp::template rebind<_Up> __type; }; - /* TODO: remove this when alias templates are supported */ - template - struct __ptrtr_rebind<_Tp, _Up, false, true> - { - typedef typename _Tp::template __rebind<_Up>::__type __type; - }; - template class _SomePtr, typename _Up, typename _Tp, typename... _Args> - struct __ptrtr_rebind<_SomePtr<_Tp, _Args...>, _Up, false, false> + struct __ptrtr_rebind<_SomePtr<_Tp, _Args...>, _Up, false> { typedef _SomePtr<_Up, _Args...> __type; }; @@ -168,14 +141,8 @@ typedef typename __ptrtr_diff_type<_Ptr>::__type difference_type; private: - /* TODO: replace __rebind with alias template rebind */ - /* template - using rebind<_Up> = typename __ptrtr_rebind<_Ptr, _Up>::__type; - */ - template - struct __rebind - { typedef typename __ptrtr_rebind<_Ptr, _Up>::__type __type; }; + using rebind = typename __ptrtr_rebind<_Ptr, _Up>::__type; // allocator_traits needs to use __rebind template friend struct allocator_traits; @@ -197,13 +164,8 @@ /// Type used to represent the difference between two pointers typedef ptrdiff_t difference_type; - /* TODO: replace __rebind with alias template rebind */ - /* template - using rebind<_Up> = U*; - */ - template - struct __rebind { typedef U* __type; }; + using rebind = _Up*; /** * @brief Obtain a pointer to an object Index: include/bits/alloc_traits.h =================================================================== --- include/bits/alloc_traits.h (revision 181128) +++ include/bits/alloc_traits.h (working copy) @@ -102,10 +102,8 @@ */ typedef __pointer pointer; -// TODO: Use pointer_traits::rebind alias template. - _GLIBCXX_ALLOC_TR_NESTED_TYPE(const_pointer, - typename pointer_traits::template __rebind::__type) + typename pointer_traits::template rebind) /** * @brief The allocator's const pointer type. @@ -116,7 +114,7 @@ typedef __const_pointer const_pointer; _GLIBCXX_ALLOC_TR_NESTED_TYPE(void_pointer, - typename pointer_traits::template __rebind::__type) + typename pointer_traits::template rebind) /** * @brief The allocator's void pointer type. @@ -127,7 +125,7 @@ typedef __void_pointer void_pointer; _GLIBCXX_ALLOC_TR_NESTED_TYPE(const_void_pointer, - typename pointer_traits::template __rebind::__type) + typename pointer_traits::template rebind) /** * @brief The allocator's const void pointer type. @@ -196,24 +194,11 @@ #undef _GLIBCXX_ALLOC_TR_NESTED_TYPE - /* TODO: use template alias template - using rebind_alloc = __alloctr_rebind<_Alloc, _Tp>::__type; + using rebind_alloc = typename __alloctr_rebind<_Alloc, _Tp>::__type; template using rebind_traits = allocator_traits>; - */ - template - struct __rebind_alloc - { - typedef typename __alloctr_rebind<_Alloc, _Tp>::__type __type; - }; - template - struct __rebind_traits - { - typedef allocator_traits::__type> __type; - }; - private: template struct __allocate_helper Index: include/ext/alloc_traits.h =================================================================== --- include/ext/alloc_traits.h (revision 181128) +++ include/ext/alloc_traits.h (working copy) @@ -161,7 +161,7 @@ template struct rebind - { typedef typename _Base_type::template __rebind_alloc<_Tp>::__type other; }; + { typedef typename _Base_type::template rebind_alloc<_Tp> other; }; #else typedef typename _Alloc::pointer pointer; Index: include/std/scoped_allocator =================================================================== --- include/std/scoped_allocator (revision 181128) +++ include/std/scoped_allocator (working copy) @@ -267,9 +267,8 @@ template struct rebind { - // TODO: use rebind_alloc instead of __rebind_alloc::__type typedef scoped_allocator_adaptor< - typename __traits::template __rebind_alloc<_Tp>::__type, + typename __traits::template rebind_alloc<_Tp>, _InnerAllocs...> other; }; Index: include/ext/pointer.h =================================================================== --- include/ext/pointer.h (revision 181128) +++ include/ext/pointer.h (working copy) @@ -577,21 +577,9 @@ /// Type used to represent the difference between two pointers typedef typename pointer::difference_type difference_type; - /* TODO: replace __rebind with alias template rebind */ - /* template - using rebind<_Up> = typename __gnu_cxx::_Pointer_adapter< + using rebind = typename __gnu_cxx::_Pointer_adapter< typename pointer_traits<_Storage_policy>::rebind<_Up>> - */ - template - class __rebind - { - typedef pointer_traits<_Storage_policy> _Policy_traits; - typedef typename _Policy_traits::template __rebind<_Up>::__type - _Rebound_policy; - public: - typedef typename __gnu_cxx::_Pointer_adapter<_Rebound_policy> __type; - }; static pointer pointer_to(typename pointer::reference __r) noexcept { return pointer(std::addressof(__r)); }