diff --git a/include/boost/utility/detail/in_place_factory_prefix.hpp b/include/boost/utility/detail/in_place_factory_prefix.hpp new file mode 100644 index 0000000..092083e --- /dev/null +++ b/include/boost/utility/detail/in_place_factory_prefix.hpp @@ -0,0 +1,33 @@ +// Copyright (C) 2003, Fernando Luis Cacciola Carballal. +// +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/lib/optional for documentation. +// +// You are welcome to contact the author at: +// fernando_cacciola@hotmail.com +// +#ifndef BOOST_UTILITY_DETAIL_INPLACE_FACTORY_PREFIX_25AGO2003_HPP +#define BOOST_UTILITY_DETAIL_INPLACE_FACTORY_PREFIX_25AGO2003_HPP + +#include +#include +#include +#include +#include +#include +#include +#include + +#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_MAX_INPLACE_FACTORY_ARITY 10 + +#undef BOOST_UTILITY_DETAIL_INPLACE_FACTORY_SUFFIX_25AGO2003_HPP + +#endif + diff --git a/include/boost/utility/detail/in_place_factory_suffix.hpp b/include/boost/utility/detail/in_place_factory_suffix.hpp new file mode 100644 index 0000000..3efe221 --- /dev/null +++ b/include/boost/utility/detail/in_place_factory_suffix.hpp @@ -0,0 +1,23 @@ +// Copyright (C) 2003, Fernando Luis Cacciola Carballal. +// +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/lib/optional for documentation. +// +// You are welcome to contact the author at: +// fernando_cacciola@hotmail.com +// +#ifndef BOOST_UTILITY_DETAIL_INPLACE_FACTORY_SUFFIX_25AGO2003_HPP +#define BOOST_UTILITY_DETAIL_INPLACE_FACTORY_SUFFIX_25AGO2003_HPP + +#undef BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT +#undef BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL +#undef BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_ARG +#undef BOOST_MAX_INPLACE_FACTORY_ARITY + +#undef BOOST_UTILITY_DETAIL_INPLACE_FACTORY_PREFIX_25AGO2003_HPP + +#endif + diff --git a/include/boost/utility/in_place_factory.hpp b/include/boost/utility/in_place_factory.hpp new file mode 100644 index 0000000..c737b25 --- /dev/null +++ b/include/boost/utility/in_place_factory.hpp @@ -0,0 +1,56 @@ +// Copyright (C) 2003, Fernando Luis Cacciola Carballal. +// +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/lib/optional for documentation. +// +// You are welcome to contact the author at: +// fernando_cacciola@hotmail.com +// +#ifndef BOOST_UTILITY_INPLACE_FACTORY_25AGO2003_HPP +#define BOOST_UTILITY_INPLACE_FACTORY_25AGO2003_HPP + +#include + +#include + +namespace boost { + +class in_place_factory_base {} ; + +#define BOOST_DEFINE_INPLACE_FACTORY_CLASS(z,n,_) \ +template< BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),class A) > \ +class BOOST_PP_CAT(in_place_factory, BOOST_PP_INC(n) ) : public in_place_factory_base \ +{ \ +public: \ +\ + BOOST_PP_CAT(in_place_factory, 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, _ ) \ + {} \ +\ + template \ + void apply ( void* address BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T) ) 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< BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),class A) > \ +BOOST_PP_CAT(in_place_factory, BOOST_PP_INC(n) ) < 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(in_place_factory, BOOST_PP_INC(n) ) < 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_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..49b1348 --- /dev/null +++ b/include/boost/utility/typed_in_place_factory.hpp @@ -0,0 +1,57 @@ +// Copyright (C) 2003, Fernando Luis Cacciola Carballal. +// +// Use, modification, and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/lib/optional for documentation. +// +// 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 typed_in_place_factory_base {} ; + +#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(typed_in_place_factory, BOOST_PP_INC(n) ) : public typed_in_place_factory_base \ +{ \ +public: \ +\ + typedef T value_type ; \ +\ + BOOST_PP_CAT(typed_in_place_factory, 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(typed_in_place_factory, 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(typed_in_place_factory, 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 + diff --git a/test/Jamfile b/test/Jamfile index f284bc5..6d23821 100755 --- a/test/Jamfile +++ b/test/Jamfile @@ -18,7 +18,7 @@ local test_monitor = @boost/libs/test/build/boost_test_exec_monitor ; # Please keep the tests ordered by filename test-suite utility - : + : [ run ../addressof_test.cpp $(test_monitor) ] [ run ../assert_test.cpp ] [ run ../base_from_member_test.cpp ] @@ -37,13 +37,16 @@ test-suite utility [ run ../enable_if_partial_specializations.cpp $(test_monitor) ] [ run ../iterator_traits_test.cpp ] [ run ../iterators_test.cpp $(test_monitor) ] - [ run next_prior_test.cpp $(test_monitor) ] + [ run next_prior_test.cpp $(test_monitor) ] [ compile-fail ../noncopyable_test.cpp ] [ run ../numeric_traits_test.cpp ] [ run ../operators_test.cpp $(test_monitor) ] [ compile ../ref_ct_test.cpp ] [ run ../ref_test.cpp $(test_monitor) ] - [ compile result_of_test.cpp ] + [ compile result_of_test.cpp ] [ run ../shared_iterator_test.cpp ] [ run ../value_init_test.cpp ] + [ compile-fail ../value_init_test_fail1.cpp ] + [ compile-fail ../value_init_test_fail2.cpp ] + [ compile-fail ../value_init_test_fail3.cpp ] ; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 308ed4e..9eb3bad 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -11,7 +11,7 @@ import testing ; # Please keep the tests ordered by filename test-suite utility - : + : [ run ../addressof_test.cpp ../../test/build//boost_test_exec_monitor ] [ run ../assert_test.cpp ] [ run ../base_from_member_test.cpp ] @@ -39,4 +39,7 @@ test-suite utility [ compile result_of_test.cpp ] [ run ../shared_iterator_test.cpp ] [ run ../value_init_test.cpp ] + [ compile-fail ../value_init_test_fail1.cpp ] + [ compile-fail ../value_init_test_fail2.cpp ] + [ compile-fail ../value_init_test_fail3.cpp ] ;