diff mbox

Constrain allocator_arg_t to only work with valid Allocators

Message ID 20150630150156.GA18520@redhat.com
State New
Headers show

Commit Message

Jonathan Wakely June 30, 2015, 3:01 p.m. UTC
On 30/06/15 15:49 +0100, Jonathan Wakely wrote:
>I'm also playing with another change to make allocator_traits<A>
>SFINAE-friendly, by only defining the nested allocator_type member
>when __is_allocator<A> is true. If it works I think that might be
>worth standardising.

Something like this, although with the __alloc_arg_t helper I don't
have an immediate use for a SFINAE-friendly allocator_traits.
diff mbox

Patch

commit 79ebd1b450c77c592ec8adabbad162a4e9d7bc51
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jun 30 11:22:23 2015 +0100

    define allocator_traits::allocator_type conditionally

diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h
index bb98c1d..25ccd97 100644
--- a/libstdc++-v3/include/bits/alloc_traits.h
+++ b/libstdc++-v3/include/bits/alloc_traits.h
@@ -34,6 +34,7 @@ 
 
 #include <bits/memoryfwd.h>
 #include <bits/ptr_traits.h>
+#include <bits/uses_allocator.h>
 #include <ext/numeric_traits.h>
 
 namespace std _GLIBCXX_VISIBILITY(default)
@@ -75,15 +76,26 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
   template<typename _Alloc, typename _Tp>
     using __alloc_rebind = typename __alloctr_rebind<_Alloc, _Tp>::__type;
 
+  template<typename _Alloc, bool = __is_allocator<_Alloc>::value>
+    struct __allocator_traits_base
+    {
+      /// The allocator type
+      typedef _Alloc allocator_type;
+    };
+
+  template<typename _Alloc>
+    struct __allocator_traits_base<_Alloc, false>
+    { };
+
   /**
    * @brief  Uniform interface to all allocator types.
    * @ingroup allocators
   */
   template<typename _Alloc>
-    struct allocator_traits
+    struct allocator_traits : __allocator_traits_base<_Alloc>
     {
-      /// The allocator type
-      typedef _Alloc allocator_type;
+      // The allocator_type typedef is conditionally defined in the base class.
+
       /// The allocated type
       typedef typename _Alloc::value_type value_type;