mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
- overloads apply for array construction
- adds support for zero arguments - lets apply return the result of the new-expression - revises the preprocessing code [SVN r38101]
This commit is contained in:
parent
66ca84a45d
commit
c950825ef4
@ -1,4 +1,5 @@
|
|||||||
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||||
|
// Copyright (C) 2007, Tobias Schwinger.
|
||||||
//
|
//
|
||||||
// Use, modification, and distribution is subject to the Boost Software
|
// Use, modification, and distribution is subject to the Boost Software
|
||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -9,25 +10,27 @@
|
|||||||
// You are welcome to contact the author at:
|
// You are welcome to contact the author at:
|
||||||
// fernando_cacciola@hotmail.com
|
// fernando_cacciola@hotmail.com
|
||||||
//
|
//
|
||||||
#ifndef BOOST_UTILITY_DETAIL_INPLACE_FACTORY_PREFIX_25AGO2003_HPP
|
#ifndef BOOST_UTILITY_DETAIL_INPLACE_FACTORY_PREFIX_04APR2007_HPP
|
||||||
#define BOOST_UTILITY_DETAIL_INPLACE_FACTORY_PREFIX_25AGO2003_HPP
|
#define BOOST_UTILITY_DETAIL_INPLACE_FACTORY_PREFIX_04APR2007_HPP
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
#include <cstddef>
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
|
#include <boost/preprocessor/cat.hpp>
|
||||||
|
#include <boost/preprocessor/punctuation/paren.hpp>
|
||||||
|
#include <boost/preprocessor/iteration/iterate.hpp>
|
||||||
|
#include <boost/preprocessor/repetition/repeat.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum.hpp>
|
#include <boost/preprocessor/repetition/enum.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum_params.hpp>
|
#include <boost/preprocessor/repetition/enum_params.hpp>
|
||||||
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
|
||||||
#include <boost/preprocessor/cat.hpp>
|
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
|
||||||
#include <boost/preprocessor/arithmetic/inc.hpp>
|
|
||||||
#include <boost/preprocessor/punctuation/paren.hpp>
|
|
||||||
#include <boost/preprocessor/facilities/empty.hpp>
|
|
||||||
|
|
||||||
#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_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_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
|
#define BOOST_MAX_INPLACE_FACTORY_ARITY 10
|
||||||
|
|
||||||
#undef BOOST_UTILITY_DETAIL_INPLACE_FACTORY_SUFFIX_25AGO2003_HPP
|
#undef BOOST_UTILITY_DETAIL_INPLACE_FACTORY_SUFFIX_04APR2007_HPP
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||||
|
// Copyright (C) 2007, Tobias Schwinger.
|
||||||
//
|
//
|
||||||
// Use, modification, and distribution is subject to the Boost Software
|
// Use, modification, and distribution is subject to the Boost Software
|
||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -9,15 +10,14 @@
|
|||||||
// You are welcome to contact the author at:
|
// You are welcome to contact the author at:
|
||||||
// fernando_cacciola@hotmail.com
|
// fernando_cacciola@hotmail.com
|
||||||
//
|
//
|
||||||
#ifndef BOOST_UTILITY_DETAIL_INPLACE_FACTORY_SUFFIX_25AGO2003_HPP
|
#ifndef BOOST_UTILITY_DETAIL_INPLACE_FACTORY_SUFFIX_04APR2007_HPP
|
||||||
#define BOOST_UTILITY_DETAIL_INPLACE_FACTORY_SUFFIX_25AGO2003_HPP
|
#define BOOST_UTILITY_DETAIL_INPLACE_FACTORY_SUFFIX_04APR2007_HPP
|
||||||
|
|
||||||
#undef BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT
|
#undef BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT
|
||||||
#undef BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL
|
#undef BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL
|
||||||
#undef BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_ARG
|
|
||||||
#undef BOOST_MAX_INPLACE_FACTORY_ARITY
|
#undef BOOST_MAX_INPLACE_FACTORY_ARITY
|
||||||
|
|
||||||
#undef BOOST_UTILITY_DETAIL_INPLACE_FACTORY_PREFIX_25AGO2003_HPP
|
#undef BOOST_UTILITY_DETAIL_INPLACE_FACTORY_PREFIX_04APR2007_HPP
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||||
|
// Copyright (C) 2007, Tobias Schwinger.
|
||||||
//
|
//
|
||||||
// Use, modification, and distribution is subject to the Boost Software
|
// Use, modification, and distribution is subject to the Boost Software
|
||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -9,50 +10,79 @@
|
|||||||
// You are welcome to contact the author at:
|
// You are welcome to contact the author at:
|
||||||
// fernando_cacciola@hotmail.com
|
// fernando_cacciola@hotmail.com
|
||||||
//
|
//
|
||||||
#ifndef BOOST_UTILITY_INPLACE_FACTORY_25AGO2003_HPP
|
#ifndef BOOST_UTILITY_INPLACE_FACTORY_04APR2007_HPP
|
||||||
#define BOOST_UTILITY_INPLACE_FACTORY_25AGO2003_HPP
|
#ifndef BOOST_PP_IS_ITERATING
|
||||||
|
|
||||||
#include <boost/utility/detail/in_place_factory_prefix.hpp>
|
#include <boost/utility/detail/in_place_factory_prefix.hpp>
|
||||||
|
|
||||||
#include <boost/type.hpp>
|
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
class in_place_factory_base {} ;
|
class in_place_factory_base {} ;
|
||||||
|
|
||||||
#define BOOST_DEFINE_INPLACE_FACTORY_CLASS(z,n,_) \
|
#define BOOST_PP_ITERATION_LIMITS (0, BOOST_MAX_INPLACE_FACTORY_ARITY)
|
||||||
template< BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),class A) > \
|
#define BOOST_PP_FILENAME_1 <boost/utility/in_place_factory.hpp>
|
||||||
class BOOST_PP_CAT(in_place_factory, BOOST_PP_INC(n) ) : public in_place_factory_base \
|
#include BOOST_PP_ITERATE()
|
||||||
{ \
|
|
||||||
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<class T> \
|
|
||||||
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
|
} // namespace boost
|
||||||
|
|
||||||
#include <boost/utility/detail/in_place_factory_suffix.hpp>
|
#include <boost/utility/detail/in_place_factory_suffix.hpp>
|
||||||
|
|
||||||
|
#define BOOST_UTILITY_INPLACE_FACTORY_04APR2007_HPP
|
||||||
|
#else
|
||||||
|
#define N BOOST_PP_ITERATION()
|
||||||
|
|
||||||
|
#if N
|
||||||
|
template< BOOST_PP_ENUM_PARAMS(N, class A) >
|
||||||
|
#endif
|
||||||
|
class BOOST_PP_CAT(in_place_factory,N)
|
||||||
|
:
|
||||||
|
public in_place_factory_base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
explicit BOOST_PP_CAT(in_place_factory,N)
|
||||||
|
( BOOST_PP_ENUM_BINARY_PARAMS(N,A,const& a) )
|
||||||
|
#if N > 0
|
||||||
|
: BOOST_PP_ENUM(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT, _)
|
||||||
|
#endif
|
||||||
|
{}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void* apply(void* address
|
||||||
|
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) const
|
||||||
|
{
|
||||||
|
return new(address) T( BOOST_PP_ENUM_PARAMS(N, m_a) );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
void* apply(void* address, std::size_t n
|
||||||
|
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) const
|
||||||
|
{
|
||||||
|
for(char* next = address = this->BOOST_NESTED_TEMPLATE apply<T>(address);
|
||||||
|
!! --n;)
|
||||||
|
this->BOOST_NESTED_TEMPLATE apply<T>(next = next+sizeof(T));
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_PP_REPEAT(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL, _)
|
||||||
|
};
|
||||||
|
|
||||||
|
#if N > 0
|
||||||
|
template< BOOST_PP_ENUM_PARAMS(N, class A) >
|
||||||
|
inline BOOST_PP_CAT(in_place_factory,N)< BOOST_PP_ENUM_PARAMS(N, A) >
|
||||||
|
in_place( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) )
|
||||||
|
{
|
||||||
|
return BOOST_PP_CAT(in_place_factory,N)< BOOST_PP_ENUM_PARAMS(N, A) >
|
||||||
|
( BOOST_PP_ENUM_PARAMS(N, a) );
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
inline in_place_factory0 in_place()
|
||||||
|
{
|
||||||
|
return in_place_factory0();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef N
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
// Copyright (C) 2003, Fernando Luis Cacciola Carballal.
|
||||||
|
// Copyright (C) 2007, Tobias Schwinger.
|
||||||
//
|
//
|
||||||
// Use, modification, and distribution is subject to the Boost Software
|
// Use, modification, and distribution is subject to the Boost Software
|
||||||
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@ -9,8 +10,8 @@
|
|||||||
// You are welcome to contact the author at:
|
// You are welcome to contact the author at:
|
||||||
// fernando_cacciola@hotmail.com
|
// fernando_cacciola@hotmail.com
|
||||||
//
|
//
|
||||||
#ifndef BOOST_UTILITY_TYPED_INPLACE_FACTORY_25AGO2003_HPP
|
#ifndef BOOST_UTILITY_TYPED_INPLACE_FACTORY_04APR2007_HPP
|
||||||
#define BOOST_UTILITY_TYPED_INPLACE_FACTORY_25AGO2003_HPP
|
#ifndef BOOST_PP_IS_ITERATING
|
||||||
|
|
||||||
#include <boost/utility/detail/in_place_factory_prefix.hpp>
|
#include <boost/utility/detail/in_place_factory_prefix.hpp>
|
||||||
|
|
||||||
@ -18,40 +19,59 @@ namespace boost {
|
|||||||
|
|
||||||
class typed_in_place_factory_base {} ;
|
class typed_in_place_factory_base {} ;
|
||||||
|
|
||||||
#define BOOST_DEFINE_TYPED_INPLACE_FACTORY_CLASS(z,n,_) \
|
#define BOOST_PP_ITERATION_LIMITS (0, BOOST_MAX_INPLACE_FACTORY_ARITY)
|
||||||
template< class T, BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),class A) > \
|
#define BOOST_PP_FILENAME_1 <boost/utility/typed_in_place_factory.hpp>
|
||||||
class BOOST_PP_CAT(typed_in_place_factory, BOOST_PP_INC(n) ) : public typed_in_place_factory_base \
|
#include BOOST_PP_ITERATE()
|
||||||
{ \
|
|
||||||
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
|
} // namespace boost
|
||||||
|
|
||||||
#include <boost/utility/detail/in_place_factory_suffix.hpp>
|
#include <boost/utility/detail/in_place_factory_suffix.hpp>
|
||||||
|
|
||||||
|
#define BOOST_UTILITY_TYPED_INPLACE_FACTORY_04APR2007_HPP
|
||||||
|
#else
|
||||||
|
#define N BOOST_PP_ITERATION()
|
||||||
|
|
||||||
|
template< class T BOOST_PP_ENUM_TRAILING_PARAMS(N,class A) >
|
||||||
|
class BOOST_PP_CAT(typed_in_place_factory,N)
|
||||||
|
:
|
||||||
|
public typed_in_place_factory_base
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef T value_type;
|
||||||
|
|
||||||
|
explicit BOOST_PP_CAT(typed_in_place_factory,N)
|
||||||
|
( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) )
|
||||||
|
#if N > 0
|
||||||
|
: BOOST_PP_ENUM(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT, _)
|
||||||
|
#endif
|
||||||
|
{}
|
||||||
|
|
||||||
|
void* apply (void* address) const
|
||||||
|
{
|
||||||
|
return new(address) T( BOOST_PP_ENUM_PARAMS(N, m_a) );
|
||||||
|
}
|
||||||
|
|
||||||
|
void* apply (void* address, std::size_t n) const
|
||||||
|
{
|
||||||
|
for(char* next = address = this->apply(address); !! --n;)
|
||||||
|
this->apply(next = next+sizeof(T));
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_PP_REPEAT(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL, _)
|
||||||
|
};
|
||||||
|
|
||||||
|
template< class T BOOST_PP_ENUM_TRAILING_PARAMS(N, class A) >
|
||||||
|
inline BOOST_PP_CAT(typed_in_place_factory,N)<
|
||||||
|
T BOOST_PP_ENUM_TRAILING_PARAMS(N, A) >
|
||||||
|
in_place( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) )
|
||||||
|
{
|
||||||
|
return BOOST_PP_CAT(typed_in_place_factory,N)<
|
||||||
|
T BOOST_PP_ENUM_TRAILING_PARAMS(N, A) >( BOOST_PP_ENUM_PARAMS(N, a) );
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef N
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user