]> git.lyx.org Git - lyx.git/blob - boost/boost/utility/in_place_factory.hpp
boost: update to version 1.40
[lyx.git] / boost / boost / utility / in_place_factory.hpp
1 // Copyright (C) 2003, Fernando Luis Cacciola Carballal.\r
2 // Copyright (C) 2007, Tobias Schwinger.\r
3 //\r
4 // Use, modification, and distribution is subject to the Boost Software\r
5 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at\r
6 // http://www.boost.org/LICENSE_1_0.txt)\r
7 //\r
8 // See http://www.boost.org/lib/optional for documentation.\r
9 //\r
10 // You are welcome to contact the author at:\r
11 //  fernando_cacciola@hotmail.com\r
12 //\r
13 #ifndef BOOST_UTILITY_INPLACE_FACTORY_04APR2007_HPP\r
14 #ifndef BOOST_PP_IS_ITERATING\r
15 \r
16 #include <boost/utility/detail/in_place_factory_prefix.hpp>\r
17 \r
18 namespace boost {\r
19 \r
20 class in_place_factory_base {} ;\r
21 \r
22 #define  BOOST_PP_ITERATION_LIMITS (0, BOOST_MAX_INPLACE_FACTORY_ARITY)\r
23 #define  BOOST_PP_FILENAME_1 <boost/utility/in_place_factory.hpp>\r
24 #include BOOST_PP_ITERATE()\r
25 \r
26 } // namespace boost\r
27 \r
28 #include <boost/utility/detail/in_place_factory_suffix.hpp>\r
29 \r
30 #define BOOST_UTILITY_INPLACE_FACTORY_04APR2007_HPP\r
31 #else\r
32 #define N BOOST_PP_ITERATION()\r
33 \r
34 #if N\r
35 template< BOOST_PP_ENUM_PARAMS(N, class A) >\r
36 #endif\r
37 class BOOST_PP_CAT(in_place_factory,N)\r
38   : \r
39   public in_place_factory_base\r
40 {\r
41 public:\r
42 \r
43   explicit BOOST_PP_CAT(in_place_factory,N)\r
44       ( BOOST_PP_ENUM_BINARY_PARAMS(N,A,const& a) )\r
45 #if N > 0\r
46     : BOOST_PP_ENUM(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT, _)\r
47 #endif\r
48   {}\r
49 \r
50   template<class T>\r
51   void* apply(void* address\r
52       BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) const\r
53   {\r
54     return new(address) T( BOOST_PP_ENUM_PARAMS(N, m_a) );\r
55   }\r
56 \r
57   template<class T>\r
58   void* apply(void* address, std::size_t n\r
59       BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) const\r
60   {\r
61     for(char* next = address = this->BOOST_NESTED_TEMPLATE apply<T>(address);\r
62         !! --n;)\r
63       this->BOOST_NESTED_TEMPLATE apply<T>(next = next+sizeof(T));\r
64     return address; \r
65   }\r
66 \r
67   BOOST_PP_REPEAT(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL, _)\r
68 };\r
69 \r
70 #if N > 0\r
71 template< BOOST_PP_ENUM_PARAMS(N, class A) >\r
72 inline BOOST_PP_CAT(in_place_factory,N)< BOOST_PP_ENUM_PARAMS(N, A) >\r
73 in_place( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) )\r
74 {\r
75   return BOOST_PP_CAT(in_place_factory,N)< BOOST_PP_ENUM_PARAMS(N, A) >\r
76       ( BOOST_PP_ENUM_PARAMS(N, a) );\r
77 }\r
78 #else\r
79 inline in_place_factory0 in_place()\r
80 {\r
81   return in_place_factory0();\r
82 }\r
83 #endif\r
84 \r
85 #undef N\r
86 #endif\r
87 #endif\r
88 \r