This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] Constrain allocator_arg_t to only work with valid Allocators
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Cc: Ville Voutilainen <ville dot voutilainen at gmail dot com>
- Date: Tue, 30 Jun 2015 16:01:56 +0100
- Subject: Re: [patch] Constrain allocator_arg_t to only work with valid Allocators
- Authentication-results: sourceware.org; auth=none
- References: <20150630144942 dot GC2856 at redhat dot com>
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.
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;