mirror of
https://github.com/boostorg/container.git
synced 2026-01-19 04:02:17 +00:00
Implemented C++20's uninitialized_construct_using_allocator and make_obj_using_allocator.
This commit is contained in:
@@ -1438,7 +1438,8 @@ use [*Boost.Container]? There are several reasons for that:
|
||||
|
||||
* Implemented heterogeneous overloads from C++23 ([@http://wg21.link/p2077r3 P2077]) and C++26 ([@http://wg21.link/P2363 P2363]).
|
||||
* In C++20 compilers, `static_vector<T>`'s destructor is now trivial if `T` is trivial.
|
||||
* Implemented C++20's [classref boost::container::uninitialized_construct_using_allocator uninitialized_construct_using_allocator].
|
||||
* Implemented C++20's [funcref boost::container::uninitialized_construct_using_allocator uninitialized_construct_using_allocator]
|
||||
and [funcref boost::container::make_obj_using_allocator make_obj_using_allocator].
|
||||
* Fixed bugs/issues:
|
||||
* [@https://github.com/boostorg/container/issues/323 GitHub #323: ['"flat_tree::try_emplace UB"]].
|
||||
|
||||
|
||||
@@ -92,16 +92,16 @@ namespace dtl {
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, typename AllocArg
|
||||
, typename T
|
||||
, class ...Args
|
||||
>
|
||||
inline typename dtl::enable_if_and
|
||||
< void
|
||||
, dtl::is_not_pair<T>
|
||||
, dtl::not_< uses_allocator<T, typename remove_cvref<ArgAlloc>::type > >
|
||||
, dtl::not_< uses_allocator<T, typename remove_cvref<AllocArg>::type > >
|
||||
>::type dispatch_uses_allocator
|
||||
( ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc), T* p, BOOST_FWD_REF(Args)...args)
|
||||
( ConstructAlloc & construct_alloc, BOOST_FWD_REF(AllocArg), T* p, BOOST_FWD_REF(Args)...args)
|
||||
{
|
||||
allocator_traits<ConstructAlloc>::construct(construct_alloc, p, ::boost::forward<Args>(args)...);
|
||||
}
|
||||
@@ -112,21 +112,21 @@ inline typename dtl::enable_if_and
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, typename AllocArg
|
||||
, typename T
|
||||
, class ...Args
|
||||
>
|
||||
inline typename dtl::enable_if_and
|
||||
< void
|
||||
, dtl::is_not_pair<T>
|
||||
, uses_allocator<T, typename remove_cvref<ArgAlloc>::type>
|
||||
, is_constructible_with_allocator_prefix<T, ArgAlloc, Args...>
|
||||
, uses_allocator<T, typename remove_cvref<AllocArg>::type>
|
||||
, is_constructible_with_allocator_prefix<T, AllocArg, Args...>
|
||||
>::type dispatch_uses_allocator
|
||||
( ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p, BOOST_FWD_REF(Args) ...args)
|
||||
( ConstructAlloc& construct_alloc, BOOST_FWD_REF(AllocArg) arg_alloc, T* p, BOOST_FWD_REF(Args) ...args)
|
||||
{
|
||||
allocator_traits<ConstructAlloc>::construct
|
||||
( construct_alloc, p, allocator_arg
|
||||
, ::boost::forward<ArgAlloc>(arg_alloc), ::boost::forward<Args>(args)...);
|
||||
, ::boost::forward<AllocArg>(arg_alloc), ::boost::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
@@ -135,22 +135,22 @@ inline typename dtl::enable_if_and
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, typename AllocArg
|
||||
, typename T
|
||||
, class ...Args
|
||||
>
|
||||
inline typename dtl::enable_if_and
|
||||
< void
|
||||
, dtl::is_not_pair<T>
|
||||
, uses_allocator<T, typename remove_cvref<ArgAlloc>::type>
|
||||
, dtl::not_<is_constructible_with_allocator_prefix<T, ArgAlloc, Args...> >
|
||||
, is_constructible_with_allocator_suffix<T, ArgAlloc, Args...>
|
||||
, uses_allocator<T, typename remove_cvref<AllocArg>::type>
|
||||
, dtl::not_<is_constructible_with_allocator_prefix<T, AllocArg, Args...> >
|
||||
, is_constructible_with_allocator_suffix<T, AllocArg, Args...>
|
||||
>::type dispatch_uses_allocator
|
||||
( ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p, BOOST_FWD_REF(Args)...args)
|
||||
( ConstructAlloc& construct_alloc, BOOST_FWD_REF(AllocArg) arg_alloc, T* p, BOOST_FWD_REF(Args)...args)
|
||||
{
|
||||
allocator_traits<ConstructAlloc>::construct
|
||||
( construct_alloc, p, ::boost::forward<Args>(args)...
|
||||
, ::boost::forward<ArgAlloc>(arg_alloc));
|
||||
, ::boost::forward<AllocArg>(arg_alloc));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
@@ -159,18 +159,18 @@ inline typename dtl::enable_if_and
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, typename AllocArg
|
||||
, typename T
|
||||
, class ...Args
|
||||
>
|
||||
inline typename dtl::enable_if_and
|
||||
< void
|
||||
, dtl::is_not_pair<T>
|
||||
, uses_allocator<T, typename remove_cvref<ArgAlloc>::type>
|
||||
, dtl::not_<is_constructible_with_allocator_prefix<T, ArgAlloc, Args...> >
|
||||
, dtl::not_<is_constructible_with_allocator_suffix<T, ArgAlloc, Args...> >
|
||||
, uses_allocator<T, typename remove_cvref<AllocArg>::type>
|
||||
, dtl::not_<is_constructible_with_allocator_prefix<T, AllocArg, Args...> >
|
||||
, dtl::not_<is_constructible_with_allocator_suffix<T, AllocArg, Args...> >
|
||||
>::type dispatch_uses_allocator
|
||||
( ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc), T* p, BOOST_FWD_REF(Args)...args)
|
||||
( ConstructAlloc& construct_alloc, BOOST_FWD_REF(AllocArg), T* p, BOOST_FWD_REF(Args)...args)
|
||||
{
|
||||
allocator_traits<ConstructAlloc>::construct(construct_alloc, p, ::boost::forward<Args>(args)...);
|
||||
}
|
||||
@@ -183,14 +183,14 @@ inline typename dtl::enable_if_and
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
#define BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE(N) \
|
||||
template <typename ConstructAlloc, typename ArgAlloc, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
template <typename ConstructAlloc, typename AllocArg, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
inline typename dtl::enable_if_and\
|
||||
< void\
|
||||
, dtl::is_not_pair<T>\
|
||||
, dtl::not_<uses_allocator<T, typename remove_cvref<ArgAlloc>::type> >\
|
||||
, dtl::not_<uses_allocator<T, typename remove_cvref<AllocArg>::type> >\
|
||||
>::type\
|
||||
dispatch_uses_allocator\
|
||||
(ConstructAlloc &construct_alloc, BOOST_FWD_REF(ArgAlloc), T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
(ConstructAlloc &construct_alloc, BOOST_FWD_REF(AllocArg), T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
{\
|
||||
allocator_traits<ConstructAlloc>::construct(construct_alloc, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
|
||||
}\
|
||||
@@ -204,18 +204,18 @@ BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
#define BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE(N) \
|
||||
template < typename ConstructAlloc, typename ArgAlloc, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
template < typename ConstructAlloc, typename AllocArg, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
inline typename dtl::enable_if_and\
|
||||
< void\
|
||||
, dtl::is_not_pair<T>\
|
||||
, uses_allocator<T, typename remove_cvref<ArgAlloc>::type>\
|
||||
, is_constructible_with_allocator_prefix<T, ArgAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N>\
|
||||
, uses_allocator<T, typename remove_cvref<AllocArg>::type>\
|
||||
, is_constructible_with_allocator_prefix<T, AllocArg BOOST_MOVE_I##N BOOST_MOVE_TARG##N>\
|
||||
>::type\
|
||||
dispatch_uses_allocator\
|
||||
(ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
(ConstructAlloc& construct_alloc, BOOST_FWD_REF(AllocArg) arg_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
{\
|
||||
allocator_traits<ConstructAlloc>::construct\
|
||||
(construct_alloc, p, allocator_arg, ::boost::forward<ArgAlloc>(arg_alloc) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
|
||||
(construct_alloc, p, allocator_arg, ::boost::forward<AllocArg>(arg_alloc) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
|
||||
}\
|
||||
//
|
||||
BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE)
|
||||
@@ -227,19 +227,19 @@ BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
#define BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE(N) \
|
||||
template < typename ConstructAlloc, typename ArgAlloc, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
template < typename ConstructAlloc, typename AllocArg, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
inline typename dtl::enable_if_and\
|
||||
< void\
|
||||
, dtl::is_not_pair<T>\
|
||||
, uses_allocator<T, typename remove_cvref<ArgAlloc>::type>\
|
||||
, dtl::not_<is_constructible_with_allocator_prefix<T, ArgAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N> >\
|
||||
, is_constructible_with_allocator_suffix<T, ArgAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N>\
|
||||
, uses_allocator<T, typename remove_cvref<AllocArg>::type>\
|
||||
, dtl::not_<is_constructible_with_allocator_prefix<T, AllocArg BOOST_MOVE_I##N BOOST_MOVE_TARG##N> >\
|
||||
, is_constructible_with_allocator_suffix<T, AllocArg BOOST_MOVE_I##N BOOST_MOVE_TARG##N>\
|
||||
>::type\
|
||||
dispatch_uses_allocator\
|
||||
(ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
(ConstructAlloc& construct_alloc, BOOST_FWD_REF(AllocArg) arg_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
{\
|
||||
allocator_traits<ConstructAlloc>::construct\
|
||||
(construct_alloc, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N, ::boost::forward<ArgAlloc>(arg_alloc));\
|
||||
(construct_alloc, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N, ::boost::forward<AllocArg>(arg_alloc));\
|
||||
}\
|
||||
//
|
||||
BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE)
|
||||
@@ -251,16 +251,16 @@ BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
#define BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE(N) \
|
||||
template < typename ConstructAlloc, typename ArgAlloc, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
template < typename ConstructAlloc, typename AllocArg, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
inline typename dtl::enable_if_and\
|
||||
< void\
|
||||
, dtl::is_not_pair<T>\
|
||||
, uses_allocator<T, typename remove_cvref<ArgAlloc>::type>\
|
||||
, dtl::not_<is_constructible_with_allocator_prefix<T, ArgAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N> >\
|
||||
, dtl::not_<is_constructible_with_allocator_suffix<T, ArgAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N> >\
|
||||
, uses_allocator<T, typename remove_cvref<AllocArg>::type>\
|
||||
, dtl::not_<is_constructible_with_allocator_prefix<T, AllocArg BOOST_MOVE_I##N BOOST_MOVE_TARG##N> >\
|
||||
, dtl::not_<is_constructible_with_allocator_suffix<T, AllocArg BOOST_MOVE_I##N BOOST_MOVE_TARG##N> >\
|
||||
>::type\
|
||||
dispatch_uses_allocator\
|
||||
(ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc), T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
(ConstructAlloc& construct_alloc, BOOST_FWD_REF(AllocArg), T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
{\
|
||||
allocator_traits<ConstructAlloc>::construct(construct_alloc, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
|
||||
}\
|
||||
@@ -271,13 +271,13 @@ BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR
|
||||
#endif //#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, typename AllocArg
|
||||
, typename Pair
|
||||
> inline
|
||||
BOOST_CONTAINER_DOC1ST(void, typename dtl::enable_if<dtl::is_pair<Pair> BOOST_MOVE_I void >::type)
|
||||
dispatch_uses_allocator
|
||||
( ConstructAlloc & construct_alloc
|
||||
, BOOST_FWD_REF(ArgAlloc) arg_alloc
|
||||
, BOOST_FWD_REF(AllocArg) arg_alloc
|
||||
, Pair* p)
|
||||
{
|
||||
dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(p->first));
|
||||
@@ -293,12 +293,12 @@ BOOST_CONTAINER_DOC1ST(void, typename dtl::enable_if<dtl::is_pair<Pair> BOOST_MO
|
||||
|
||||
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, typename AllocArg
|
||||
, class Pair, class U, class V>
|
||||
BOOST_CONTAINER_DOC1ST(void, typename dtl::enable_if<dtl::is_pair<Pair> BOOST_MOVE_I void>::type)
|
||||
dispatch_uses_allocator
|
||||
( ConstructAlloc & construct_alloc
|
||||
, BOOST_FWD_REF(ArgAlloc) arg_alloc
|
||||
, BOOST_FWD_REF(AllocArg) arg_alloc
|
||||
, Pair* p, BOOST_FWD_REF(U) x, BOOST_FWD_REF(V) y)
|
||||
{
|
||||
dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(p->first), ::boost::forward<U>(x));
|
||||
@@ -313,17 +313,17 @@ BOOST_CONTAINER_DOC1ST(void, typename dtl::enable_if<dtl::is_pair<Pair> BOOST_MO
|
||||
}
|
||||
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, typename AllocArg
|
||||
, class Pair, class Pair2>
|
||||
BOOST_CONTAINER_DOC1ST(void, typename dtl::enable_if< dtl::is_pair<Pair> BOOST_MOVE_I void >::type)
|
||||
dispatch_uses_allocator
|
||||
(ConstructAlloc & construct_alloc
|
||||
, BOOST_FWD_REF(ArgAlloc) arg_alloc
|
||||
, BOOST_FWD_REF(AllocArg) arg_alloc
|
||||
, Pair* p, Pair2& x)
|
||||
{ dispatch_uses_allocator(construct_alloc, arg_alloc, p, x.first, x.second); }
|
||||
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, typename AllocArg
|
||||
, class Pair, class Pair2>
|
||||
typename dtl::enable_if_and
|
||||
< void
|
||||
@@ -331,18 +331,18 @@ typename dtl::enable_if_and
|
||||
, dtl::not_<boost::move_detail::is_reference<Pair2> > >::type //This is needed for MSVC10 and ambiguous overloads
|
||||
dispatch_uses_allocator
|
||||
(ConstructAlloc & construct_alloc
|
||||
, BOOST_FWD_REF(ArgAlloc) arg_alloc
|
||||
, BOOST_FWD_REF(AllocArg) arg_alloc
|
||||
, Pair* p, BOOST_RV_REF_BEG Pair2 BOOST_RV_REF_END x)
|
||||
{ dispatch_uses_allocator(construct_alloc, arg_alloc, p, ::boost::move(x.first), ::boost::move(x.second)); }
|
||||
|
||||
|
||||
//piecewise construction from boost::tuple
|
||||
#define BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_BOOST_TUPLE_CODE(N,M)\
|
||||
template< typename ConstructAlloc, typename ArgAlloc, class Pair \
|
||||
template< typename ConstructAlloc, typename AllocArg, class Pair \
|
||||
, template<class, class, class, class, class, class, class, class, class, class> class BoostTuple \
|
||||
BOOST_MOVE_I_IF(BOOST_MOVE_OR(N,M)) BOOST_MOVE_CLASS##N BOOST_MOVE_I_IF(BOOST_MOVE_AND(N,M)) BOOST_MOVE_CLASSQ##M > \
|
||||
typename dtl::enable_if< dtl::is_pair<Pair> BOOST_MOVE_I void>::type\
|
||||
dispatch_uses_allocator( ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* pair, piecewise_construct_t\
|
||||
dispatch_uses_allocator( ConstructAlloc & construct_alloc, BOOST_FWD_REF(AllocArg) arg_alloc, Pair* pair, piecewise_construct_t\
|
||||
, BoostTuple<BOOST_MOVE_TARG##N BOOST_MOVE_I##N BOOST_MOVE_REPEAT(BOOST_MOVE_SUB(10,N),::boost::tuples::null_type)> p\
|
||||
, BoostTuple<BOOST_MOVE_TARGQ##M BOOST_MOVE_I##M BOOST_MOVE_REPEAT(BOOST_MOVE_SUB(10,M),::boost::tuples::null_type)> q)\
|
||||
{\
|
||||
@@ -366,9 +366,9 @@ BOOST_MOVE_ITER2D_0TOMAX(9, BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_BO
|
||||
//piecewise construction from Std Tuple
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
template< typename ConstructAlloc, typename ArgAlloc, class Pair
|
||||
template< typename ConstructAlloc, typename AllocArg, class Pair
|
||||
, template<class ...> class Tuple, class... Args1, class... Args2, size_t... Indexes1, size_t... Indexes2>
|
||||
void dispatch_uses_allocator_index( ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* pair
|
||||
void dispatch_uses_allocator_index( ConstructAlloc & construct_alloc, BOOST_FWD_REF(AllocArg) arg_alloc, Pair* pair
|
||||
, Tuple<Args1...>& t1, Tuple<Args2...>& t2, index_tuple<Indexes1...>, index_tuple<Indexes2...>)
|
||||
{
|
||||
(void)t1; (void)t2;
|
||||
@@ -383,10 +383,10 @@ BOOST_MOVE_ITER2D_0TOMAX(9, BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_BO
|
||||
BOOST_CONTAINER_CATCH_END
|
||||
}
|
||||
|
||||
template< typename ConstructAlloc, typename ArgAlloc, class Pair
|
||||
template< typename ConstructAlloc, typename AllocArg, class Pair
|
||||
, template<class ...> class Tuple, class... Args1, class... Args2>
|
||||
typename dtl::enable_if< dtl::is_pair<Pair>, void >::type
|
||||
dispatch_uses_allocator( ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* pair, piecewise_construct_t
|
||||
dispatch_uses_allocator( ConstructAlloc & construct_alloc, BOOST_FWD_REF(AllocArg) arg_alloc, Pair* pair, piecewise_construct_t
|
||||
, Tuple<Args1...> t1, Tuple<Args2...> t2)
|
||||
{
|
||||
(dispatch_uses_allocator_index)( construct_alloc, arg_alloc, pair, t1, t2
|
||||
@@ -398,11 +398,11 @@ BOOST_MOVE_ITER2D_0TOMAX(9, BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_BO
|
||||
|
||||
//MSVC 2010 tuple implementation
|
||||
#define BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_MSVC2010_TUPLE_CODE(N,M)\
|
||||
template< typename ConstructAlloc, typename ArgAlloc, class Pair\
|
||||
template< typename ConstructAlloc, typename AllocArg, class Pair\
|
||||
, template<class, class, class, class, class, class, class, class, class, class> class StdTuple\
|
||||
BOOST_MOVE_I_IF(BOOST_MOVE_OR(N,M)) BOOST_MOVE_CLASS##N BOOST_MOVE_I_IF(BOOST_MOVE_AND(N,M)) BOOST_MOVE_CLASSQ##M > \
|
||||
typename dtl::enable_if< dtl::is_pair<Pair> BOOST_MOVE_I void>::type\
|
||||
dispatch_uses_allocator(ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* pair, piecewise_construct_t\
|
||||
dispatch_uses_allocator(ConstructAlloc & construct_alloc, BOOST_FWD_REF(AllocArg) arg_alloc, Pair* pair, piecewise_construct_t\
|
||||
, StdTuple<BOOST_MOVE_TARG##N BOOST_MOVE_I##N BOOST_MOVE_REPEAT(BOOST_MOVE_SUB(10,N),::std::tr1::_Nil)> p\
|
||||
, StdTuple<BOOST_MOVE_TARGQ##M BOOST_MOVE_I##M BOOST_MOVE_REPEAT(BOOST_MOVE_SUB(10,M),::std::tr1::_Nil)> q)\
|
||||
{\
|
||||
@@ -432,12 +432,12 @@ BOOST_MOVE_ITER2D_0TOMAX(9, BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_BO
|
||||
|
||||
//MSVC 2012 tuple implementation
|
||||
#define BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_MSVC2012_TUPLE_CODE(N,M)\
|
||||
template< typename ConstructAlloc, typename ArgAlloc, class Pair\
|
||||
template< typename ConstructAlloc, typename AllocArg, class Pair\
|
||||
, template<BOOST_MOVE_REPEAT(_VARIADIC_MAX, class), class, class, class> class StdTuple \
|
||||
BOOST_MOVE_I_IF(BOOST_MOVE_OR(N,M)) BOOST_MOVE_CLASS##N BOOST_MOVE_I_IF(BOOST_MOVE_AND(N,M)) BOOST_MOVE_CLASSQ##M > \
|
||||
typename dtl::enable_if< dtl::is_pair<Pair> BOOST_MOVE_I void>::type\
|
||||
dispatch_uses_allocator\
|
||||
( ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* pair, piecewise_construct_t\
|
||||
( ConstructAlloc & construct_alloc, BOOST_FWD_REF(AllocArg) arg_alloc, Pair* pair, piecewise_construct_t\
|
||||
, StdTuple<BOOST_MOVE_TARG##N BOOST_MOVE_I##N BOOST_MOVE_REPEAT(BOOST_MOVE_SUB(BOOST_MOVE_ADD(_VARIADIC_MAX, 3),N),::std::_Nil) > p\
|
||||
, StdTuple<BOOST_MOVE_TARGQ##M BOOST_MOVE_I##M BOOST_MOVE_REPEAT(BOOST_MOVE_SUB(BOOST_MOVE_ADD(_VARIADIC_MAX, 3),M),::std::_Nil) > q)\
|
||||
{\
|
||||
@@ -461,14 +461,26 @@ BOOST_MOVE_ITER2D_0TOMAX(9, BOOST_DISPATCH_USES_ALLOCATOR_PIECEWISE_CONSTRUCT_BO
|
||||
|
||||
#endif //!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
template<class T>
|
||||
struct uses_allocator_destroy
|
||||
{
|
||||
T &t_;
|
||||
uses_allocator_destroy(T&t)
|
||||
: t_(t)
|
||||
{}
|
||||
|
||||
~uses_allocator_destroy()
|
||||
{ t_.~T(); }
|
||||
};
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, typename AllocArg
|
||||
, class Pair, class KeyType, class ... Args>
|
||||
typename dtl::enable_if< dtl::is_pair<Pair>, void >::type
|
||||
dispatch_uses_allocator
|
||||
(ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* p, try_emplace_t, BOOST_FWD_REF(KeyType) k, BOOST_FWD_REF(Args) ...args)
|
||||
(ConstructAlloc & construct_alloc, BOOST_FWD_REF(AllocArg) arg_alloc, Pair* p, try_emplace_t, BOOST_FWD_REF(KeyType) k, BOOST_FWD_REF(Args) ...args)
|
||||
{
|
||||
dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(p->first), ::boost::forward<KeyType>(k));
|
||||
BOOST_CONTAINER_TRY{
|
||||
@@ -481,14 +493,28 @@ typename dtl::enable_if< dtl::is_pair<Pair>, void >::type
|
||||
BOOST_CONTAINER_CATCH_END
|
||||
}
|
||||
|
||||
template <typename T, typename AllocArg, class ...Args>
|
||||
inline T construct_dispatch_uses_allocator
|
||||
(BOOST_FWD_REF(AllocArg) arg_alloc, BOOST_FWD_REF(Args)...args)
|
||||
{
|
||||
typename dtl::aligned_storage<sizeof(T), alignment_of<T>::value>::type storage;
|
||||
T * const addr = reinterpret_cast<T*>(&storage);
|
||||
|
||||
boost::container::dtl::allocator_traits_dummy<T> atd;
|
||||
(dispatch_uses_allocator)
|
||||
(atd, boost::forward<AllocArg>(arg_alloc), addr, boost::forward<Args>(args)...);
|
||||
uses_allocator_destroy<T> d(*addr);
|
||||
return d.t_;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#define BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_PAIR_TRY_EMPLACE_CODE(N) \
|
||||
template <typename ConstructAlloc, typename ArgAlloc, class Pair, class KeyType BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
template <typename ConstructAlloc, typename AllocArg, class Pair, class KeyType BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
inline typename dtl::enable_if\
|
||||
< dtl::is_pair<Pair> BOOST_MOVE_I void >::type\
|
||||
dispatch_uses_allocator\
|
||||
(ConstructAlloc &construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, Pair* p, try_emplace_t, \
|
||||
(ConstructAlloc &construct_alloc, BOOST_FWD_REF(AllocArg) arg_alloc, Pair* p, try_emplace_t, \
|
||||
BOOST_FWD_REF(KeyType) k BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
{\
|
||||
dispatch_uses_allocator(construct_alloc, arg_alloc, dtl::addressof(p->first), ::boost::forward<KeyType>(k));\
|
||||
@@ -505,6 +531,23 @@ typename dtl::enable_if< dtl::is_pair<Pair>, void >::type
|
||||
BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_PAIR_TRY_EMPLACE_CODE)
|
||||
#undef BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_PAIR_TRY_EMPLACE_CODE
|
||||
|
||||
#define BOOST_CONTAINER_CONSTRUCT_DISPATCH_USES_ALLOCATOR_CODE(N) \
|
||||
template <class T, class AllocArg BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
inline T construct_dispatch_uses_allocator\
|
||||
(BOOST_FWD_REF(AllocArg) arg_alloc BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
{\
|
||||
typename dtl::aligned_storage<sizeof(T), alignment_of<T>::value>::type storage;\
|
||||
T * const addr = reinterpret_cast<T*>(&storage);\
|
||||
boost::container::dtl::allocator_traits_dummy<T> atd;\
|
||||
(dispatch_uses_allocator)\
|
||||
(atd, boost::forward<AllocArg>(arg_alloc), addr BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
|
||||
uses_allocator_destroy<T> d(*addr);\
|
||||
return d.t_;\
|
||||
}\
|
||||
//
|
||||
BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_CONSTRUCT_DISPATCH_USES_ALLOCATOR_CODE)
|
||||
#undef BOOST_CONTAINER_CONSTRUCT_DISPATCH_USES_ALLOCATOR_CODE
|
||||
|
||||
#endif //!defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
} //namespace dtl
|
||||
|
||||
@@ -51,6 +51,22 @@ T* uninitialized_construct_using_allocator(T* p, BOOST_FWD_REF(AllocArg) alloc_a
|
||||
return p;
|
||||
}
|
||||
|
||||
//! <b>Effects</b>: eates an object of the given type T by means of uses-allocator construction
|
||||
//! (see `uses_allocator`), where:
|
||||
//!
|
||||
//! * `alloc_arg` is the allocator argument whose type AllocArg will be used to evaluate uses_allocator<T, AllocArg>::value
|
||||
//! * `args` are the arguments to pass to T's constructor.
|
||||
//!
|
||||
//! <b>Returns</b>: The newsly created object of type T
|
||||
//!
|
||||
//! <b>Throws</b>: Any exception thrown by the constructor of T.
|
||||
template< class T, class AllocArg, class... Args >
|
||||
T make_obj_using_allocator(BOOST_FWD_REF(AllocArg) alloc_arg, BOOST_FWD_REF(Args)... args)
|
||||
{
|
||||
return boost::container::dtl::construct_dispatch_uses_allocator<T>
|
||||
(boost::forward<AllocArg>(alloc_arg), boost::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
#else //BOOST_NO_CXX11_VARIADIC_TEMPLATES
|
||||
|
||||
#define BOOST_CONTAINER_USES_ALLOCATOR_CONSTRUCTION_CODE(N) \
|
||||
@@ -63,6 +79,14 @@ T* uninitialized_construct_using_allocator(T* p, BOOST_FWD_REF(AllocArg) alloc_a
|
||||
(atd, boost::forward<AllocArg>(alloc_arg), p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
|
||||
return p;\
|
||||
}\
|
||||
\
|
||||
template <class T, class AllocArg BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
inline T make_obj_using_allocator\
|
||||
(BOOST_FWD_REF(AllocArg) alloc_arg BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
{\
|
||||
return boost::container::dtl::construct_dispatch_uses_allocator<T>\
|
||||
(boost::forward<AllocArg>(alloc_arg) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
|
||||
}\
|
||||
//
|
||||
BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_USES_ALLOCATOR_CONSTRUCTION_CODE)
|
||||
#undef BOOST_CONTAINER_USES_ALLOCATOR_CONSTRUCTION_CODE
|
||||
|
||||
@@ -90,7 +90,7 @@ struct uses_erased_type_allocator
|
||||
bool allocator_called;
|
||||
unsigned args_called;
|
||||
|
||||
typedef boost::container::erased_type allocator_type;
|
||||
typedef erased_type allocator_type;
|
||||
typedef long constructible_from_int_t;
|
||||
|
||||
uses_erased_type_allocator()
|
||||
@@ -118,32 +118,45 @@ struct uses_erased_type_allocator
|
||||
{}
|
||||
};
|
||||
|
||||
typedef boost::container::dtl::aligned_storage<sizeof(uses_allocator_and_not_convertible_arg)>::type storage_t;
|
||||
|
||||
//Make sure aligned_storage will be big enough
|
||||
BOOST_CONTAINER_STATIC_ASSERT( sizeof(storage_t) >= sizeof(uses_allocator_and_not_convertible_arg) );
|
||||
BOOST_CONTAINER_STATIC_ASSERT( sizeof(storage_t) >= sizeof(not_uses_allocator) );
|
||||
BOOST_CONTAINER_STATIC_ASSERT( sizeof(storage_t) >= sizeof(uses_allocator_and_convertible_arg) );
|
||||
BOOST_CONTAINER_STATIC_ASSERT( sizeof(storage_t) >= sizeof(uses_erased_type_allocator) );
|
||||
|
||||
int main()
|
||||
void test_uninitialized_construct()
|
||||
{
|
||||
typedef dtl::aligned_storage<sizeof(uses_allocator_and_not_convertible_arg)>::type storage_t;
|
||||
|
||||
//Make sure aligned_storage will be big enough
|
||||
BOOST_CONTAINER_STATIC_ASSERT( sizeof(storage_t) >= sizeof(uses_allocator_and_not_convertible_arg) );
|
||||
BOOST_CONTAINER_STATIC_ASSERT( sizeof(storage_t) >= sizeof(not_uses_allocator) );
|
||||
BOOST_CONTAINER_STATIC_ASSERT( sizeof(storage_t) >= sizeof(uses_allocator_and_convertible_arg) );
|
||||
BOOST_CONTAINER_STATIC_ASSERT( sizeof(storage_t) >= sizeof(uses_erased_type_allocator) );
|
||||
|
||||
storage_t storage;
|
||||
void *const st_ptr = static_cast<void*>(storage.data);
|
||||
|
||||
not_uses_allocator *nua_ptr = reinterpret_cast<not_uses_allocator*>(st_ptr);
|
||||
uses_allocator_and_not_convertible_arg *uanci_ptr = reinterpret_cast<uses_allocator_and_not_convertible_arg*>(st_ptr);
|
||||
uses_allocator_and_convertible_arg *uaci_ptr = reinterpret_cast<uses_allocator_and_convertible_arg*>(st_ptr);
|
||||
uses_erased_type_allocator *ueta_ptr = reinterpret_cast<uses_erased_type_allocator*>(st_ptr);
|
||||
|
||||
////////////////////////////////////
|
||||
//not_uses_allocator
|
||||
////////////////////////////////////
|
||||
not_uses_allocator *nua_ptr = reinterpret_cast<not_uses_allocator*>(st_ptr);
|
||||
nua_ptr = uninitialized_construct_using_allocator(nua_ptr, alloc_arg_t());
|
||||
|
||||
////////////////////////////////////
|
||||
//uses_allocator_and_convertible_arg
|
||||
uanci_ptr = uninitialized_construct_using_allocator(uanci_ptr, alloc_arg_t());
|
||||
BOOST_TEST(uanci_ptr->allocator_called == false);
|
||||
BOOST_TEST(uanci_ptr->args_called == 0u);
|
||||
////////////////////////////////////
|
||||
uses_allocator_and_convertible_arg *uaci_ptr = reinterpret_cast<uses_allocator_and_convertible_arg*>(st_ptr);
|
||||
uaci_ptr = uninitialized_construct_using_allocator(uaci_ptr, alloc_arg_t());
|
||||
BOOST_TEST(uaci_ptr->allocator_called == true);
|
||||
BOOST_TEST(uaci_ptr->args_called == 0u);
|
||||
|
||||
uaci_ptr = uninitialized_construct_using_allocator(uaci_ptr, alloc_arg_t(), arg1_t(), arg2_t(), arg3_t());
|
||||
BOOST_TEST(uaci_ptr->allocator_called == true);
|
||||
BOOST_TEST(uaci_ptr->args_called == 3u);
|
||||
|
||||
uaci_ptr = uninitialized_construct_using_allocator(uaci_ptr, alloc_arg_t(), arg1_t(), arg2_t());
|
||||
BOOST_TEST(uaci_ptr->allocator_called == true);
|
||||
BOOST_TEST(uaci_ptr->args_called == 2u);
|
||||
|
||||
////////////////////////////////////
|
||||
//uses_allocator_and_not_convertible_arg
|
||||
////////////////////////////////////
|
||||
uses_allocator_and_not_convertible_arg *uanci_ptr = reinterpret_cast<uses_allocator_and_not_convertible_arg*>(st_ptr);
|
||||
uanci_ptr = uninitialized_construct_using_allocator(uanci_ptr, alloc_arg_t());
|
||||
BOOST_TEST(uanci_ptr->allocator_called == false);
|
||||
BOOST_TEST(uanci_ptr->args_called == 0u);
|
||||
@@ -164,20 +177,10 @@ int main()
|
||||
BOOST_TEST(uanci_ptr->allocator_called == false);
|
||||
BOOST_TEST(uanci_ptr->args_called == 2u);
|
||||
|
||||
//uses_allocator_and_not_convertible_arg
|
||||
uaci_ptr = uninitialized_construct_using_allocator(uaci_ptr, alloc_arg_t());
|
||||
BOOST_TEST(uaci_ptr->allocator_called == true);
|
||||
BOOST_TEST(uaci_ptr->args_called == 0u);
|
||||
|
||||
uaci_ptr = uninitialized_construct_using_allocator(uaci_ptr, alloc_arg_t(), arg1_t(), arg2_t(), arg3_t());
|
||||
BOOST_TEST(uaci_ptr->allocator_called == true);
|
||||
BOOST_TEST(uaci_ptr->args_called == 3u);
|
||||
|
||||
uaci_ptr = uninitialized_construct_using_allocator(uaci_ptr, alloc_arg_t(), arg1_t(), arg2_t());
|
||||
BOOST_TEST(uaci_ptr->allocator_called == true);
|
||||
BOOST_TEST(uaci_ptr->args_called == 2u);
|
||||
|
||||
////////////////////////////////////
|
||||
//uses_erased_type_allocator
|
||||
////////////////////////////////////
|
||||
uses_erased_type_allocator *ueta_ptr = reinterpret_cast<uses_erased_type_allocator*>(st_ptr);
|
||||
ueta_ptr = uninitialized_construct_using_allocator(ueta_ptr, alloc_arg_t());
|
||||
BOOST_TEST(ueta_ptr->allocator_called == true);
|
||||
BOOST_TEST(ueta_ptr->args_called == 0u);
|
||||
@@ -197,6 +200,80 @@ int main()
|
||||
ueta_ptr = uninitialized_construct_using_allocator(ueta_ptr, non_alloc_arg_t(), arg1_t(), arg2_t(), arg3_t());
|
||||
BOOST_TEST(ueta_ptr->allocator_called == false);
|
||||
BOOST_TEST(ueta_ptr->args_called == 3u);
|
||||
}
|
||||
|
||||
void test_make_obj()
|
||||
{
|
||||
////////////////////////////////////
|
||||
//not_uses_allocator
|
||||
////////////////////////////////////
|
||||
not_uses_allocator d = make_obj_using_allocator<not_uses_allocator>(alloc_arg_t()); (void)d;
|
||||
|
||||
////////////////////////////////////
|
||||
//uses_allocator_and_convertible_arg
|
||||
////////////////////////////////////
|
||||
uses_allocator_and_convertible_arg uaci = make_obj_using_allocator<uses_allocator_and_convertible_arg>(alloc_arg_t());
|
||||
BOOST_TEST(uaci.allocator_called == true);
|
||||
BOOST_TEST(uaci.args_called == 0u);
|
||||
|
||||
uaci = make_obj_using_allocator<uses_allocator_and_convertible_arg>(alloc_arg_t(), arg1_t(), arg2_t(), arg3_t());
|
||||
BOOST_TEST(uaci.allocator_called == true);
|
||||
BOOST_TEST(uaci.args_called == 3u);
|
||||
|
||||
uaci = make_obj_using_allocator<uses_allocator_and_convertible_arg>(alloc_arg_t(), arg1_t(), arg2_t());
|
||||
BOOST_TEST(uaci.allocator_called == true);
|
||||
BOOST_TEST(uaci.args_called == 2u);
|
||||
|
||||
////////////////////////////////////
|
||||
//uses_allocator_and_not_convertible_arg
|
||||
////////////////////////////////////
|
||||
uses_allocator_and_not_convertible_arg uanci = make_obj_using_allocator<uses_allocator_and_not_convertible_arg>(alloc_arg_t());
|
||||
BOOST_TEST(uanci.allocator_called == false);
|
||||
BOOST_TEST(uanci.args_called == 0u);
|
||||
|
||||
uanci = make_obj_using_allocator<uses_allocator_and_not_convertible_arg>(alloc_arg_t(), arg1_t(), arg2_t(), arg3_t());
|
||||
BOOST_TEST(uanci.allocator_called == false);
|
||||
BOOST_TEST(uanci.args_called == 3u);
|
||||
|
||||
uanci = make_obj_using_allocator<uses_allocator_and_not_convertible_arg>(alloc_arg_t(), arg1_t(), arg2_t());
|
||||
BOOST_TEST(uanci.allocator_called == false);
|
||||
BOOST_TEST(uanci.args_called == 2u);
|
||||
|
||||
uanci = make_obj_using_allocator<uses_allocator_and_not_convertible_arg>(non_alloc_arg_t(), arg1_t(), arg2_t(), arg3_t());
|
||||
BOOST_TEST(uanci.allocator_called == false);
|
||||
BOOST_TEST(uanci.args_called == 3u);
|
||||
|
||||
uanci = make_obj_using_allocator<uses_allocator_and_not_convertible_arg>(non_alloc_arg_t(), arg1_t(), arg2_t());
|
||||
BOOST_TEST(uanci.allocator_called == false);
|
||||
BOOST_TEST(uanci.args_called == 2u);
|
||||
|
||||
////////////////////////////////////
|
||||
//uses_erased_type_allocator
|
||||
////////////////////////////////////
|
||||
uses_erased_type_allocator ueta = make_obj_using_allocator<uses_erased_type_allocator>(alloc_arg_t());
|
||||
BOOST_TEST(ueta.allocator_called == true);
|
||||
BOOST_TEST(ueta.args_called == 0u);
|
||||
|
||||
ueta = make_obj_using_allocator<uses_erased_type_allocator>(alloc_arg_t(), arg1_t(), arg2_t(), arg3_t());
|
||||
BOOST_TEST(ueta.allocator_called == true);
|
||||
BOOST_TEST(ueta.args_called == 3u);
|
||||
|
||||
ueta = make_obj_using_allocator<uses_erased_type_allocator>(alloc_arg_t(), arg1_t(), arg2_t());
|
||||
BOOST_TEST(ueta.allocator_called == true);
|
||||
BOOST_TEST(ueta.args_called == 2u);
|
||||
|
||||
ueta = make_obj_using_allocator<uses_erased_type_allocator>(non_alloc_arg_t(), arg1_t(), arg2_t());
|
||||
BOOST_TEST(ueta.allocator_called == false);
|
||||
BOOST_TEST(ueta.args_called == 2u);
|
||||
|
||||
ueta = make_obj_using_allocator<uses_erased_type_allocator>(non_alloc_arg_t(), arg1_t(), arg2_t(), arg3_t());
|
||||
BOOST_TEST(ueta.allocator_called == false);
|
||||
BOOST_TEST(ueta.args_called == 3u);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
//test_uninitialized_construct();
|
||||
test_make_obj();
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user