#ifndef BOOST_PP_IS_ITERATING /////////////////////////////////////////////////////////////////////////////// /// \file construct.hpp /// For constructing an arbitrary type from a bunch of transforms. // // Copyright 2007 Eric Niebler. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_PROTO_TRANSFORM_CONSTRUCT_HPP_EAN_12_26_2006 #define BOOST_PROTO_TRANSFORM_CONSTRUCT_HPP_EAN_12_26_2006 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace proto { namespace transform { namespace detail { template struct is_aggregate : is_pod {}; template struct is_aggregate > : mpl::true_ {}; template::value> struct nested_type { typedef typename T::type type; }; template struct nested_type { typedef T type; }; template struct nested_type_if : nested_type { typedef yes_type proto_transform_applied; }; template struct nested_type_if { typedef T type; typedef no_type proto_transform_applied; }; template::type>::value> struct as_transform { typedef Arg type; }; template struct as_transform { typedef construct<_, typename remove_pointer::type> type; }; template::type>::value> struct as_pod_transform { typedef Arg type; }; template struct as_pod_transform { typedef pod_construct<_, typename remove_pointer::type> type; }; template::value) > struct apply_aux_ { typedef R type; typedef no_type proto_transform_applied; }; template::value> struct apply_ : apply_aux_ {}; template struct apply_ : nested_type::type> { typedef yes_type proto_transform_applied; }; // work around GCC bug template struct apply_, Expr, State, Visitor, false> { typedef expr type; typedef no_type proto_transform_applied; }; template void ignore_unused(T const &) {} } template struct construct : Grammar { template struct apply : ConstructorFun::template apply::type, State, Visitor> {}; template static typename apply::type call(Expr const &expr, State const &state, Visitor &visitor) { return ConstructorFun::call(Grammar::call(expr, state, visitor), state, visitor); } }; #define BOOST_PROTO_APPLY_(Z, N, DATA) \ typename apply_::type \ /**/ #define BOOST_PROTO_IS_APPLIED_(Z, N, DATA) \ typename apply_::proto_transform_applied \ /**/ #define BOOST_PP_ITERATION_PARAMS_1 (3, (0, BOOST_PROTO_MAX_ARITY, )) #include BOOST_PP_ITERATE() #undef BOOST_PROTO_APPLY_ #undef BOOST_PROTO_IS_APPLIED_ }}} namespace boost { namespace proto { template struct is_transform > : mpl::true_ {}; template struct is_transform > : mpl::true_ {}; }} #endif #else #define N BOOST_PP_ITERATION() #if N > 0 namespace detail { template< template class T BOOST_PP_ENUM_TRAILING_PARAMS(N, typename G), typename Expr, typename State, typename Visitor > struct apply_aux_, Expr, State, Visitor BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(N)> : nested_type_if< T BOOST_PP_ENUM_TRAILING(N, BOOST_PROTO_IS_APPLIED_, G) > {}; } #endif template struct construct : Grammar { template struct apply : detail::apply_::type, State, Visitor> {}; template static typename apply::type call(Expr const &expr, State const &state, Visitor &visitor) { typedef typename apply::type result_type; return construct::call_(expr, state, visitor, detail::is_aggregate()); } private: /// INTERNAL ONLY /// template static typename apply::type call_(Expr const &expr, State const &state, Visitor &visitor, mpl::true_) { typename Grammar::template apply::type const &expr2 = Grammar::call(expr, state, visitor); detail::ignore_unused(expr2); typename apply::type that = { BOOST_PP_ENUM_BINARY_PARAMS(N, detail::as_transform::type::call(expr2, state, visitor) BOOST_PP_INTERCEPT) }; return that; } /// INTERNAL ONLY /// template static typename apply::type call_(Expr const &expr, State const &state, Visitor &visitor, mpl::false_) { typename Grammar::template apply::type const &expr2 = Grammar::call(expr, state, visitor); detail::ignore_unused(expr2); return typename apply::type( BOOST_PP_ENUM_BINARY_PARAMS(N, detail::as_transform::type::call(expr2, state, visitor) BOOST_PP_INTERCEPT) ); } }; template struct pod_construct : Grammar { template struct apply : detail::apply_::type, State, Visitor> {}; template static typename apply::type call(Expr const &expr, State const &state, Visitor &visitor) { typename Grammar::template apply::type const &expr2 = Grammar::call(expr, state, visitor); detail::ignore_unused(expr2); typename apply::type that = { BOOST_PP_ENUM_BINARY_PARAMS(N, detail::as_pod_transform::type::call(expr2, state, visitor) BOOST_PP_INTERCEPT) }; return that; } }; #undef N #endif