]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
1e59de90 | 22 | #ifndef BOOST_UTILITY_DOCS |
7c673cae FG |
23 | #define BOOST_PP_ITERATION_LIMITS (0, BOOST_MAX_INPLACE_FACTORY_ARITY) |
24 | #define BOOST_PP_FILENAME_1 <boost/utility/typed_in_place_factory.hpp> | |
1e59de90 | 25 | #endif // BOOST_UTILITY_DOCS |
7c673cae | 26 | |
1e59de90 | 27 | #include BOOST_PP_ITERATE() |
7c673cae FG |
28 | } // namespace boost |
29 | ||
30 | #include <boost/utility/detail/in_place_factory_suffix.hpp> | |
31 | ||
1e59de90 | 32 | #ifndef BOOST_UTILITY_DOCS |
7c673cae | 33 | #define BOOST_UTILITY_TYPED_INPLACE_FACTORY_04APR2007_HPP |
1e59de90 TL |
34 | #endif // BOOST_UTILITY_DOCS |
35 | ||
7c673cae FG |
36 | #else |
37 | #define N BOOST_PP_ITERATION() | |
38 | ||
39 | template< class T BOOST_PP_ENUM_TRAILING_PARAMS(N,class A) > | |
40 | class BOOST_PP_CAT(typed_in_place_factory,N) | |
41 | : | |
42 | public typed_in_place_factory_base | |
43 | { | |
44 | public: | |
45 | ||
46 | typedef T value_type; | |
47 | ||
48 | explicit BOOST_PP_CAT(typed_in_place_factory,N) | |
49 | ( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) ) | |
50 | #if N > 0 | |
51 | : BOOST_PP_ENUM(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT, _) | |
52 | #endif | |
53 | {} | |
54 | ||
55 | void* apply (void* address) const | |
56 | { | |
57 | return new(address) T( BOOST_PP_ENUM_PARAMS(N, m_a) ); | |
58 | } | |
59 | ||
60 | void* apply (void* address, std::size_t n) const | |
61 | { | |
62 | for(void* next = address = this->apply(address); !! --n;) | |
63 | this->apply(next = static_cast<char *>(next) + sizeof(T)); | |
64 | return address; | |
65 | } | |
66 | ||
67 | BOOST_PP_REPEAT(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL, _) | |
68 | }; | |
69 | ||
70 | template< class T BOOST_PP_ENUM_TRAILING_PARAMS(N, class A) > | |
71 | inline BOOST_PP_CAT(typed_in_place_factory,N)< | |
72 | T BOOST_PP_ENUM_TRAILING_PARAMS(N, A) > | |
73 | in_place( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) ) | |
74 | { | |
75 | return BOOST_PP_CAT(typed_in_place_factory,N)< | |
76 | T BOOST_PP_ENUM_TRAILING_PARAMS(N, A) >( BOOST_PP_ENUM_PARAMS(N, a) ); | |
77 | } | |
78 | ||
79 | #undef N | |
80 | #endif | |
81 | #endif | |
82 |