]>
Commit | Line | Data |
---|---|---|
1 | // Copyright (C) 2003, Fernando Luis Cacciola Carballal. | |
2 | // Copyright (C) 2007, Tobias Schwinger. | |
3 | // | |
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) | |
7 | // | |
8 | // See http://www.boost.org/libs/optional for documentation. | |
9 | // | |
10 | // You are welcome to contact the author at: | |
11 | // fernando_cacciola@hotmail.com | |
12 | // | |
13 | #ifndef BOOST_UTILITY_TYPED_INPLACE_FACTORY_04APR2007_HPP | |
14 | #ifndef BOOST_PP_IS_ITERATING | |
15 | ||
16 | #include <boost/utility/detail/in_place_factory_prefix.hpp> | |
17 | ||
18 | namespace boost { | |
19 | ||
20 | class typed_in_place_factory_base {} ; | |
21 | ||
22 | #define BOOST_PP_ITERATION_LIMITS (0, BOOST_MAX_INPLACE_FACTORY_ARITY) | |
23 | #define BOOST_PP_FILENAME_1 <boost/utility/typed_in_place_factory.hpp> | |
24 | #include BOOST_PP_ITERATE() | |
25 | ||
26 | } // namespace boost | |
27 | ||
28 | #include <boost/utility/detail/in_place_factory_suffix.hpp> | |
29 | ||
30 | #define BOOST_UTILITY_TYPED_INPLACE_FACTORY_04APR2007_HPP | |
31 | #else | |
32 | #define N BOOST_PP_ITERATION() | |
33 | ||
34 | template< class T BOOST_PP_ENUM_TRAILING_PARAMS(N,class A) > | |
35 | class BOOST_PP_CAT(typed_in_place_factory,N) | |
36 | : | |
37 | public typed_in_place_factory_base | |
38 | { | |
39 | public: | |
40 | ||
41 | typedef T value_type; | |
42 | ||
43 | explicit BOOST_PP_CAT(typed_in_place_factory,N) | |
44 | ( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) ) | |
45 | #if N > 0 | |
46 | : BOOST_PP_ENUM(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT, _) | |
47 | #endif | |
48 | {} | |
49 | ||
50 | void* apply (void* address) const | |
51 | { | |
52 | return new(address) T( BOOST_PP_ENUM_PARAMS(N, m_a) ); | |
53 | } | |
54 | ||
55 | void* apply (void* address, std::size_t n) const | |
56 | { | |
57 | for(void* next = address = this->apply(address); !! --n;) | |
58 | this->apply(next = static_cast<char *>(next) + sizeof(T)); | |
59 | return address; | |
60 | } | |
61 | ||
62 | BOOST_PP_REPEAT(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL, _) | |
63 | }; | |
64 | ||
65 | template< class T BOOST_PP_ENUM_TRAILING_PARAMS(N, class A) > | |
66 | inline BOOST_PP_CAT(typed_in_place_factory,N)< | |
67 | T BOOST_PP_ENUM_TRAILING_PARAMS(N, A) > | |
68 | in_place( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) ) | |
69 | { | |
70 | return BOOST_PP_CAT(typed_in_place_factory,N)< | |
71 | T BOOST_PP_ENUM_TRAILING_PARAMS(N, A) >( BOOST_PP_ENUM_PARAMS(N, a) ); | |
72 | } | |
73 | ||
74 | #undef N | |
75 | #endif | |
76 | #endif | |
77 |