Support types with std::allocator_arg_at with boost::container::scoped_allocator_adaptor

This commit is contained in:
Ion Gaztañaga
2015-01-11 23:50:58 +01:00
parent a322203a89
commit 69324174c7
8 changed files with 373 additions and 24 deletions
+60 -18
View File
@@ -31,6 +31,7 @@
#include <boost/container/detail/mpl.hpp>
#include <boost/container/detail/pair.hpp>
#include <boost/container/detail/type_traits.hpp>
#include <boost/container/detail/std_allocator_arg.hpp>
#include <boost/move/adl_move_swap.hpp>
#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
@@ -135,6 +136,10 @@ template <class T>
struct constructible_with_allocator_prefix
{ static const bool value = false; };
template <class T>
struct constructible_with_std_allocator_prefix
{ static const bool value = false; };
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
namespace container_detail {
@@ -269,7 +274,7 @@ namespace container_detail {
//With variadic templates, we need a single class to implement the trait
template<class T, class ...Args>
struct is_constructible_impl
struct is_constructible
{
typedef char yes_type;
struct no_type
@@ -287,16 +292,16 @@ namespace container_detail {
static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
};
template<class T, class ...Args>
struct is_constructible
: is_constructible_impl<T, Args...>
{};
template <class T, class InnerAlloc, class ...Args>
struct is_constructible_with_allocator_prefix
: is_constructible<T, allocator_arg_t, InnerAlloc, Args...>
{};
template <class T, class InnerAlloc, class ...Args>
struct is_constructible_with_std_allocator_prefix
: is_constructible<T, const std::allocator_arg_t&, InnerAlloc, Args...>
{};
#else // #if !defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
//Without advanced SFINAE expressions, we can't use is_constructible
@@ -304,24 +309,34 @@ namespace container_detail {
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template < class T, class InnerAlloc, class ...Args>
template <class T, class InnerAlloc, class ...Args>
struct is_constructible_with_allocator_prefix
: constructible_with_allocator_prefix<T>
{};
template < class T, class InnerAlloc, class ...Args>
template <class T, class InnerAlloc, class ...Args>
struct is_constructible_with_std_allocator_prefix
: constructible_with_std_allocator_prefix<T>
{};
template <class T, class InnerAlloc, class ...Args>
struct is_constructible_with_allocator_suffix
: constructible_with_allocator_suffix<T>
{};
#else // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template < class T, class InnerAlloc, BOOST_MOVE_CLASSDFLT9>
template <class T, class InnerAlloc, BOOST_MOVE_CLASSDFLT9>
struct is_constructible_with_allocator_prefix
: constructible_with_allocator_prefix<T>
{};
template < class T, class InnerAlloc, BOOST_MOVE_CLASSDFLT9>
template <class T, class InnerAlloc, BOOST_MOVE_CLASSDFLT9>
struct is_constructible_with_std_allocator_prefix
: constructible_with_std_allocator_prefix<T>
{};
template <class T, class InnerAlloc, BOOST_MOVE_CLASSDFLT9>
struct is_constructible_with_allocator_suffix
: constructible_with_allocator_suffix<T>
{};
@@ -332,27 +347,42 @@ namespace container_detail {
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
// allocator_arg_t
template < typename OutermostAlloc
, typename InnerAlloc
, typename T
, class ...Args
>
inline void dispatch_allocator_prefix_suffix
( true_type use_alloc_prefix, OutermostAlloc& outermost_alloc
( unsigned_<1> use_alloc_prefix, OutermostAlloc& outermost_alloc
, InnerAlloc& inner_alloc, T* p, BOOST_FWD_REF(Args) ...args)
{
(void)use_alloc_prefix;
allocator_traits<OutermostAlloc>::construct
( outermost_alloc, p, allocator_arg, inner_alloc, ::boost::forward<Args>(args)...);
}
// std::allocator_arg_t
template < typename OutermostAlloc
, typename InnerAlloc
, typename T
, class ...Args
>
inline void dispatch_allocator_prefix_suffix
( false_type use_alloc_prefix, OutermostAlloc& outermost_alloc
( unsigned_<2> use_alloc_prefix, OutermostAlloc& outermost_alloc
, InnerAlloc &inner_alloc, T* p, BOOST_FWD_REF(Args)...args)
{
(void)use_alloc_prefix;
allocator_traits<OutermostAlloc>::construct
( outermost_alloc, p, alloc_arg<>::get(), inner_alloc, ::boost::forward<Args>(args)...);
}
// allocator suffix
template < typename OutermostAlloc
, typename InnerAlloc
, typename T
, class ...Args
>
inline void dispatch_allocator_prefix_suffix
( unsigned_<0> use_alloc_prefix, OutermostAlloc& outermost_alloc
, InnerAlloc &inner_alloc, T* p, BOOST_FWD_REF(Args)...args)
{
(void)use_alloc_prefix;
@@ -373,7 +403,8 @@ inline void dispatch_uses_allocator
//BOOST_STATIC_ASSERT((is_constructible_with_allocator_prefix<T, InnerAlloc, Args...>::value ||
// is_constructible_with_allocator_suffix<T, InnerAlloc, Args...>::value ));
dispatch_allocator_prefix_suffix
( bool_<is_constructible_with_allocator_prefix<T, InnerAlloc, Args...>::value >()
( unsigned_< is_constructible_with_allocator_prefix<T, InnerAlloc, Args...>::value ? 1u :
(is_constructible_with_std_allocator_prefix<T, InnerAlloc, Args...>::value ? 2u : 0u) >()
, outermost_alloc, inner_alloc, p, ::boost::forward<Args>(args)...);
}
@@ -398,7 +429,7 @@ inline void dispatch_uses_allocator
template < typename OutermostAlloc, typename InnerAlloc, typename T\
BOOST_MOVE_I##N BOOST_MOVE_CLASS##N > \
inline void dispatch_allocator_prefix_suffix\
(true_type use_alloc_prefix, OutermostAlloc& outermost_alloc,\
(unsigned_<1u> use_alloc_prefix, OutermostAlloc& outermost_alloc,\
InnerAlloc& inner_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
{\
(void)use_alloc_prefix,\
@@ -406,10 +437,21 @@ inline void dispatch_allocator_prefix_suffix\
(outermost_alloc, p, allocator_arg, inner_alloc BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
}\
\
template < typename OutermostAlloc, typename InnerAlloc, typename T\
BOOST_MOVE_I##N BOOST_MOVE_CLASS##N > \
inline void dispatch_allocator_prefix_suffix\
(unsigned_<2u> use_alloc_prefix, OutermostAlloc& outermost_alloc,\
InnerAlloc& inner_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
{\
(void)use_alloc_prefix,\
allocator_traits<OutermostAlloc>::construct\
(outermost_alloc, p, alloc_arg<>::get(), inner_alloc BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
}\
\
template < typename OutermostAlloc, typename InnerAlloc, typename T\
BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
inline void dispatch_allocator_prefix_suffix\
(false_type use_alloc_prefix, OutermostAlloc& outermost_alloc,\
(unsigned_<0u> use_alloc_prefix, OutermostAlloc& outermost_alloc,\
InnerAlloc& inner_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
{\
(void)use_alloc_prefix;\
@@ -425,8 +467,8 @@ inline void dispatch_uses_allocator\
{\
(void)uses_allocator;\
dispatch_allocator_prefix_suffix\
(bool_< is_constructible_with_allocator_prefix\
< T, InnerAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N>::value>()\
( unsigned_< is_constructible_with_allocator_prefix<T, InnerAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N>::value ? 1u :\
(is_constructible_with_std_allocator_prefix<T, InnerAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N>::value ? 2u : 0u) >()\
, outermost_alloc, inner_alloc, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
}\
\