1 // Copyright (C) 2003, Fernando Luis Cacciola Carballal.
2 // Copyright (C) 2007, Tobias Schwinger.
4 // Use, modification, and distribution is subject to the Boost Software
5 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
8 // See http://www.boost.org/lib/optional for documentation.
10 // You are welcome to contact the author at:
11 // fernando_cacciola@hotmail.com
13 #ifndef BOOST_UTILITY_INPLACE_FACTORY_04APR2007_HPP
14 #ifndef BOOST_PP_IS_ITERATING
16 #include <boost/utility/detail/in_place_factory_prefix.hpp>
20 class in_place_factory_base
{} ;
22 #define BOOST_PP_ITERATION_LIMITS (0, BOOST_MAX_INPLACE_FACTORY_ARITY)
23 #define BOOST_PP_FILENAME_1 <boost/utility/in_place_factory.hpp>
24 #include BOOST_PP_ITERATE()
28 #include <boost/utility/detail/in_place_factory_suffix.hpp>
30 #define BOOST_UTILITY_INPLACE_FACTORY_04APR2007_HPP
32 #define N BOOST_PP_ITERATION()
35 template< BOOST_PP_ENUM_PARAMS(N
, class A
) >
37 class BOOST_PP_CAT(in_place_factory
,N
)
39 public in_place_factory_base
43 explicit BOOST_PP_CAT(in_place_factory
,N
)
44 ( BOOST_PP_ENUM_BINARY_PARAMS(N
,A
,const& a
) )
46 : BOOST_PP_ENUM(N
, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT
, _
)
51 void* apply(void* address
52 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T
)) const
54 return new(address
) T( BOOST_PP_ENUM_PARAMS(N
, m_a
) );
58 void* apply(void* address
, std::size_t n
59 BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T
)) const
61 for(char* next
= address
= this->BOOST_NESTED_TEMPLATE apply
<T
>(address
);
63 this->BOOST_NESTED_TEMPLATE apply
<T
>(next
= next
+sizeof(T
));
67 BOOST_PP_REPEAT(N
, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL
, _
)
71 template< BOOST_PP_ENUM_PARAMS(N
, class A
) >
72 inline BOOST_PP_CAT(in_place_factory
,N
)< BOOST_PP_ENUM_PARAMS(N
, A
) >
73 in_place( BOOST_PP_ENUM_BINARY_PARAMS(N
, A
, const& a
) )
75 return BOOST_PP_CAT(in_place_factory
,N
)< BOOST_PP_ENUM_PARAMS(N
, A
) >
76 ( BOOST_PP_ENUM_PARAMS(N
, a
) );
79 inline in_place_factory0
in_place()
81 return in_place_factory0();