]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/utility/in_place_factory.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / utility / in_place_factory.hpp
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_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 in_place_factory_base {} ;
21
22 #ifndef BOOST_UTILITY_DOCS
23 #define BOOST_PP_ITERATION_LIMITS (0, BOOST_MAX_INPLACE_FACTORY_ARITY)
24 #define BOOST_PP_FILENAME_1 <boost/utility/in_place_factory.hpp>
25 #endif // BOOST_UTILITY_DOCS
26
27 #include BOOST_PP_ITERATE()
28
29 } // namespace boost
30
31 #include <boost/utility/detail/in_place_factory_suffix.hpp>
32
33 #ifndef BOOST_UTILITY_DOCS
34 #define BOOST_UTILITY_INPLACE_FACTORY_04APR2007_HPP
35 #endif
36
37 #else
38 #define N BOOST_PP_ITERATION()
39
40 #if N
41 template< BOOST_PP_ENUM_PARAMS(N, class A) >
42 #endif
43 class BOOST_PP_CAT(in_place_factory,N)
44 :
45 public in_place_factory_base
46 {
47 public:
48
49 explicit BOOST_PP_CAT(in_place_factory,N)
50 ( BOOST_PP_ENUM_BINARY_PARAMS(N,A,const& a) )
51 #if N > 0
52 : BOOST_PP_ENUM(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT, _)
53 #endif
54 {}
55
56 template<class T>
57 void* apply(void* address) const
58 {
59 return new(address) T( BOOST_PP_ENUM_PARAMS(N, m_a) );
60 }
61
62 template<class T>
63 void* apply(void* address, std::size_t n) const
64 {
65 for(char* next = address = this->BOOST_NESTED_TEMPLATE apply<T>(address);
66 !! --n;)
67 this->BOOST_NESTED_TEMPLATE apply<T>(next = next+sizeof(T));
68 return address;
69 }
70
71 BOOST_PP_REPEAT(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL, _)
72 };
73
74 #if N > 0
75 template< BOOST_PP_ENUM_PARAMS(N, class A) >
76 inline BOOST_PP_CAT(in_place_factory,N)< BOOST_PP_ENUM_PARAMS(N, A) >
77 in_place( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) )
78 {
79 return BOOST_PP_CAT(in_place_factory,N)< BOOST_PP_ENUM_PARAMS(N, A) >
80 ( BOOST_PP_ENUM_PARAMS(N, a) );
81 }
82 #else
83 inline in_place_factory0 in_place()
84 {
85 return in_place_factory0();
86 }
87 #endif
88
89 #undef N
90 #endif
91 #endif
92