1 // Boost.TypeErasure library 2 // 3 // Copyright 2011 Steven Watanabe 4 // 5 // Distributed under the Boost Software License Version 1.0. (See 6 // accompanying file LICENSE_1_0.txt or copy at 7 // http://www.boost.org/LICENSE_1_0.txt) 8 // 9 // $Id$ 10 11 #if !defined(BOOST_PP_IS_ITERATING) 12 13 #ifndef BOOST_TYPE_ERASURE_DETAIL_CONSTRUCT_HPP_INCLUDED 14 #define BOOST_TYPE_ERASURE_DETAIL_CONSTRUCT_HPP_INCLUDED 15 16 #define BOOST_PP_FILENAME_1 <boost/type_erasure/detail/construct.hpp> 17 #define BOOST_PP_ITERATION_LIMITS (1, BOOST_TYPE_ERASURE_MAX_ARITY) 18 #include BOOST_PP_ITERATE() 19 20 #endif 21 22 #else 23 24 #define N BOOST_PP_ITERATION() 25 26 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES 27 28 #define BOOST_TYPE_ERASURE_FORWARD_I(z, n, data) ::std::forward<BOOST_PP_CAT(U, n)>(BOOST_PP_CAT(u, n)) 29 #define BOOST_TYPE_ERASURE_FORWARD(n) BOOST_PP_ENUM(n, BOOST_TYPE_ERASURE_FORWARD_I, ~) 30 31 #if N > 1 32 33 template< 34 class R 35 BOOST_PP_ENUM_TRAILING_PARAMS(N, class A) 36 BOOST_PP_ENUM_TRAILING_PARAMS(N, class U) 37 > _boost_type_erasure_extract_table(::boost::type_erasure::constructible<R (BOOST_PP_ENUM_PARAMS (N,A))> * BOOST_PP_ENUM_TRAILING_BINARY_PARAMS (N,U,& u))38 const table_type& _boost_type_erasure_extract_table( 39 ::boost::type_erasure::constructible<R(BOOST_PP_ENUM_PARAMS(N, A))>* 40 BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, &u)) 41 { 42 return *::boost::type_erasure::detail::BOOST_PP_CAT(extract_table, N)( 43 (R(*)(BOOST_PP_ENUM_PARAMS(N, A)))0, 44 BOOST_PP_ENUM_PARAMS(N, u)); 45 } 46 47 template<BOOST_PP_ENUM_PARAMS(N, class U)> 48 any(BOOST_PP_ENUM_BINARY_PARAMS(N, U, &&u)) 49 : table( 50 _boost_type_erasure_extract_table( 51 false? this->_boost_type_erasure_deduce_constructor(BOOST_TYPE_ERASURE_FORWARD(N)) : 0 52 BOOST_PP_ENUM_TRAILING_PARAMS(N, u) 53 ) 54 ), 55 data(::boost::type_erasure::call( 56 ::boost::type_erasure::detail::make( 57 false? this->_boost_type_erasure_deduce_constructor(BOOST_TYPE_ERASURE_FORWARD(N)) : 0 58 ), BOOST_TYPE_ERASURE_FORWARD(N)) 59 ) 60 {} 61 62 #endif 63 64 template<BOOST_PP_ENUM_PARAMS(N, class U)> 65 any(const binding<Concept>& binding_arg BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, &&u)) 66 : table(binding_arg), 67 data( 68 ::boost::type_erasure::call( 69 binding_arg, 70 ::boost::type_erasure::detail::make( 71 false? this->_boost_type_erasure_deduce_constructor(BOOST_TYPE_ERASURE_FORWARD(N)) : 0 72 ) 73 BOOST_PP_COMMA_IF(N) 74 BOOST_TYPE_ERASURE_FORWARD(N) 75 ) 76 ) 77 {} 78 79 // disambiguate 80 template<BOOST_PP_ENUM_PARAMS(N, class U)> 81 any(binding<Concept>& binding_arg BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, &&u)) 82 : table(binding_arg), 83 data( 84 ::boost::type_erasure::call( 85 binding_arg, 86 ::boost::type_erasure::detail::make( 87 false? this->_boost_type_erasure_deduce_constructor(BOOST_TYPE_ERASURE_FORWARD(N)) : 0 88 ) 89 BOOST_PP_COMMA_IF(N) 90 BOOST_TYPE_ERASURE_FORWARD(N) 91 ) 92 ) 93 {} 94 95 // disambiguate 96 template<BOOST_PP_ENUM_PARAMS(N, class U)> 97 any(binding<Concept>&& binding_arg BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, &&u)) 98 : table(binding_arg), 99 data( 100 ::boost::type_erasure::call( 101 binding_arg, 102 ::boost::type_erasure::detail::make( 103 false? this->_boost_type_erasure_deduce_constructor(BOOST_TYPE_ERASURE_FORWARD(N)) : 0 104 ) 105 BOOST_PP_COMMA_IF(N) 106 BOOST_TYPE_ERASURE_FORWARD(N) 107 ) 108 ) 109 {} 110 111 #undef BOOST_TYPE_ERASURE_FORWARD 112 #undef BOOST_TYPE_ERASURE_FORWARD_I 113 114 #else 115 116 #if N > 1 117 118 template< 119 class R 120 BOOST_PP_ENUM_TRAILING_PARAMS(N, class A) 121 BOOST_PP_ENUM_TRAILING_PARAMS(N, class U) 122 > _boost_type_erasure_extract_table(::boost::type_erasure::constructible<R (BOOST_PP_ENUM_PARAMS (N,A))> * BOOST_PP_ENUM_TRAILING_BINARY_PARAMS (N,U,& u))123 const table_type& _boost_type_erasure_extract_table( 124 ::boost::type_erasure::constructible<R(BOOST_PP_ENUM_PARAMS(N, A))>* 125 BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, &u)) 126 { 127 return *::boost::type_erasure::detail::BOOST_PP_CAT(extract_table, N)( 128 (R(*)(BOOST_PP_ENUM_PARAMS(N, A)))0, 129 BOOST_PP_ENUM_PARAMS(N, u)); 130 } 131 132 template<BOOST_PP_ENUM_PARAMS(N, class U)> any(BOOST_PP_ENUM_BINARY_PARAMS (N,const U,& u))133 any(BOOST_PP_ENUM_BINARY_PARAMS(N, const U, &u)) 134 : table( 135 _boost_type_erasure_extract_table( 136 false? this->_boost_type_erasure_deduce_constructor(BOOST_PP_ENUM_PARAMS(N, u)) : 0 137 BOOST_PP_ENUM_TRAILING_PARAMS(N, u) 138 ) 139 ), 140 data(::boost::type_erasure::call( 141 ::boost::type_erasure::detail::make( 142 false? this->_boost_type_erasure_deduce_constructor(BOOST_PP_ENUM_PARAMS(N, u)) : 0 143 ), BOOST_PP_ENUM_PARAMS(N, u)) 144 ) 145 {} 146 147 template<BOOST_PP_ENUM_PARAMS(N, class U)> any(BOOST_PP_ENUM_BINARY_PARAMS (N,U,& u))148 any(BOOST_PP_ENUM_BINARY_PARAMS(N, U, &u)) 149 : table( 150 _boost_type_erasure_extract_table( 151 false? this->_boost_type_erasure_deduce_constructor(BOOST_PP_ENUM_PARAMS(N, u)) : 0 152 BOOST_PP_ENUM_TRAILING_PARAMS(N, u) 153 ) 154 ), 155 data(::boost::type_erasure::call( 156 ::boost::type_erasure::detail::make( 157 false? this->_boost_type_erasure_deduce_constructor(BOOST_PP_ENUM_PARAMS(N, u)) : 0 158 ), BOOST_PP_ENUM_PARAMS(N, u)) 159 ) 160 {} 161 162 #endif 163 164 template<BOOST_PP_ENUM_PARAMS(N, class U)> any(const binding<Concept> & binding_arg BOOST_PP_ENUM_TRAILING_BINARY_PARAMS (N,const U,& u))165 any(const binding<Concept>& binding_arg BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, const U, &u)) 166 : table(binding_arg), 167 data( 168 ::boost::type_erasure::call( 169 binding_arg, 170 ::boost::type_erasure::detail::make( 171 false? this->_boost_type_erasure_deduce_constructor(BOOST_PP_ENUM_PARAMS(N, u)) : 0 172 ) 173 BOOST_PP_ENUM_TRAILING_PARAMS(N, u) 174 ) 175 ) 176 {} 177 178 template<BOOST_PP_ENUM_PARAMS(N, class U)> any(const binding<Concept> & binding_arg BOOST_PP_ENUM_TRAILING_BINARY_PARAMS (N,U,& u))179 any(const binding<Concept>& binding_arg BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, &u)) 180 : table(binding_arg), 181 data( 182 ::boost::type_erasure::call( 183 binding_arg, 184 ::boost::type_erasure::detail::make( 185 false? this->_boost_type_erasure_deduce_constructor(BOOST_PP_ENUM_PARAMS(N, u)) : 0 186 ) 187 BOOST_PP_ENUM_TRAILING_PARAMS(N, u) 188 ) 189 ) 190 {} 191 192 // disambiguate 193 template<BOOST_PP_ENUM_PARAMS(N, class U)> any(binding<Concept> & binding_arg BOOST_PP_ENUM_TRAILING_BINARY_PARAMS (N,U,& u))194 any(binding<Concept>& binding_arg BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(N, U, &u)) 195 : table(binding_arg), 196 data( 197 ::boost::type_erasure::call( 198 binding_arg, 199 ::boost::type_erasure::detail::make( 200 false? this->_boost_type_erasure_deduce_constructor(BOOST_PP_ENUM_PARAMS(N, u)) : 0 201 ) 202 BOOST_PP_ENUM_TRAILING_PARAMS(N, u) 203 ) 204 ) 205 {} 206 207 #endif 208 209 #undef N 210 211 #endif 212