diff --git a/include/boost/utility/in_place_factory.hpp b/include/boost/utility/in_place_factory.hpp index 8909956..c361bc8 100644 --- a/include/boost/utility/in_place_factory.hpp +++ b/include/boost/utility/in_place_factory.hpp @@ -15,13 +15,7 @@ #ifndef BOOST_UTILITY_INPLACE_FACTORY_25AGO2003_HPP #define BOOST_UTILITY_INPLACE_FACTORY_25AGO2003_HPP -#include -#include -#include -#include -#include -#include -#include +#include #include @@ -29,10 +23,6 @@ namespace boost { class InPlaceFactoryBase {} ; -#define BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT(z,n,_) BOOST_PP_CAT(m_a,n) BOOST_PP_LPAREN() BOOST_PP_CAT(a,n) BOOST_PP_RPAREN() -#define BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL(z,n,_) BOOST_PP_CAT(A,n) const& BOOST_PP_CAT(m_a,n); -#define BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_ARG(z,n,_) BOOST_PP_CAT(m_a,n) - #define BOOST_DEFINE_INPLACE_FACTORY_CLASS(z,n,_) \ template< BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),class A) > \ class BOOST_PP_CAT(InPlaceFactory, BOOST_PP_INC(n) ) : public InPlaceFactoryBase \ @@ -45,7 +35,7 @@ public: \ {} \ \ template \ - void operator() ( boost::type, void* address ) const \ + void apply ( void* address BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T) ) const \ { \ new ( address ) T ( BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), m_a ) ) ; \ } \ @@ -61,13 +51,9 @@ in_place ( BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n),A, const& a) ) \ ( BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), a ) ) ; \ } ; \ -#define BOOST_MAX_INPLACE_FACTORY_ARITY 10 - BOOST_PP_REPEAT( BOOST_MAX_INPLACE_FACTORY_ARITY, BOOST_DEFINE_INPLACE_FACTORY_CLASS, BOOST_PP_EMPTY() ) } // namespace boost - - #endif diff --git a/include/boost/utility/typed_in_place_factory.hpp b/include/boost/utility/typed_in_place_factory.hpp new file mode 100644 index 0000000..12d8c52 --- /dev/null +++ b/include/boost/utility/typed_in_place_factory.hpp @@ -0,0 +1,60 @@ +// (C) 2002, Fernando Luis Cacciola Carballal. +// +// This material is provided "as is", with absolutely no warranty expressed +// or implied. Any use is at your own risk. +// +// Permission to use or copy this software for any purpose is hereby granted +// without fee, provided the above notices are retained on all copies. +// Permission to modify the code and to distribute modified code is granted, +// provided the above notices are retained, and a notice that the code was +// modified is included with the above copyright notice. +// +// You are welcome to contact the author at: +// fernando_cacciola@hotmail.com +// +#ifndef BOOST_UTILITY_TYPED_INPLACE_FACTORY_25AGO2003_HPP +#define BOOST_UTILITY_TYPED_INPLACE_FACTORY_25AGO2003_HPP + +#include + +namespace boost { + +class TypedInPlaceFactoryBase {} ; + +#define BOOST_DEFINE_TYPED_INPLACE_FACTORY_CLASS(z,n,_) \ +template< class T, BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),class A) > \ +class BOOST_PP_CAT(TypedInPlaceFactory, BOOST_PP_INC(n) ) : public TypedInPlaceFactoryBase \ +{ \ +public: \ +\ + typedef T value_type ; \ +\ + BOOST_PP_CAT(TypedInPlaceFactory, BOOST_PP_INC(n) ) ( BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n),A,const& a) ) \ + : \ + BOOST_PP_ENUM( BOOST_PP_INC(n), BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT, _ ) \ + {} \ +\ + void apply ( void* address ) const \ + { \ + new ( address ) T ( BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), m_a ) ) ; \ + } \ +\ + BOOST_PP_REPEAT( BOOST_PP_INC(n), BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL, _) \ +} ; \ +\ +template< class T, BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),class A) > \ +BOOST_PP_CAT(TypedInPlaceFactory, BOOST_PP_INC(n) ) < T , BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), A ) > \ +in_place ( BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n),A, const& a) ) \ +{ \ + return BOOST_PP_CAT(TypedInPlaceFactory, BOOST_PP_INC(n) ) < T, BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), A ) > \ + ( BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), a ) ) ; \ +} ; \ + +BOOST_PP_REPEAT( BOOST_MAX_INPLACE_FACTORY_ARITY, BOOST_DEFINE_TYPED_INPLACE_FACTORY_CLASS, BOOST_PP_EMPTY() ) + +} // namespace boost + +#include + +#endif +