#ifndef BOOST_PP_IS_ITERATING /////////////////////////////////////////////////////////////////////////////// /// \file poly_function.hpp /// A wrapper that makes a tr1-style function object that handles const /// and non-const refs and reference_wrapper arguments, too, and forwards /// the arguments on to the specified implementation. // // Copyright 2008 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_DETAIL_POLY_FUNCTION_EAN_2008_05_02 #define BOOST_PROTO_DETAIL_POLY_FUNCTION_EAN_2008_05_02 #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4181) // const applied to reference type #endif namespace boost { namespace proto { namespace detail { //////////////////////////////////////////////////////////////////////////////////////////////// template struct normalize_arg { typedef T type; typedef T const &reference; }; template struct normalize_arg { typedef T type; typedef T const &reference; }; template struct normalize_arg { typedef T type; typedef T const &reference; }; template struct normalize_arg > { typedef T &type; typedef T &reference; }; template struct normalize_arg &> { typedef T &type; typedef T &reference; }; template struct normalize_arg const &> { typedef T &type; typedef T &reference; }; //////////////////////////////////////////////////////////////////////////////////////////////// template struct arg { typedef T const &type; arg(type t) : value(t) {} operator type() const { return this->value; } type operator()() const { return *this; } private: arg &operator =(arg const &); type value; }; template struct arg { typedef T &type; arg(type t) : value(t) {} operator type() const { return this->value; } type operator()() const { return *this; } private: arg &operator =(arg const &); type value; }; //////////////////////////////////////////////////////////////////////////////////////////////// template struct is_poly_function : mpl::false_ {}; template struct is_poly_function : mpl::true_ {}; //////////////////////////////////////////////////////////////////////////////////////////////// #define BOOST_PROTO_POLY_FUNCTION() \ typedef void is_poly_function_base_; \ /**/ //////////////////////////////////////////////////////////////////////////////////////////////// struct poly_function_base { /// INTERNAL ONLY BOOST_PROTO_POLY_FUNCTION() }; //////////////////////////////////////////////////////////////////////////////////////////////// template struct poly_function : poly_function_base { template struct result; template struct result : Derived::template impl<> { typedef typename result::result_type type; }; NullaryResult operator()() const { result impl; return impl(); } #define BOOST_PP_ITERATION_PARAMS_1 (4, (1, BOOST_PROTO_MAX_ARITY, , 0)) #include BOOST_PP_ITERATE() }; template struct wrap_t; typedef char poly_function_t; typedef char (&mono_function_t)[2]; typedef char (&unknown_function_t)[3]; template poly_function_t test_poly_function(T *, wrap_t * = 0); template mono_function_t test_poly_function(T *, wrap_t * = 0); template unknown_function_t test_poly_function(T *, ...); //////////////////////////////////////////////////////////////////////////////////////////////// template(0,0))> > struct poly_function_traits { typedef typename Fun::template result::type result_type; typedef Fun function_type; }; //////////////////////////////////////////////////////////////////////////////////////////////// template struct poly_function_traits > { typedef typename Fun::result_type result_type; typedef Fun function_type; }; //////////////////////////////////////////////////////////////////////////////////////////////// template struct as_mono_function_impl; //////////////////////////////////////////////////////////////////////////////////////////////// template struct as_mono_function; #define BOOST_PP_ITERATION_PARAMS_1 (4, (1, BOOST_PROTO_MAX_ARITY, , 1)) #include BOOST_PP_ITERATE() }}} // namespace boost::proto::detail #ifdef _MSC_VER # pragma warning(pop) #endif #endif #elif 0 == BOOST_PP_ITERATION_FLAGS() #define N BOOST_PP_ITERATION() template struct result : Derived::template impl< BOOST_PP_ENUM_BINARY_PARAMS( N , typename normalize_arg::type BOOST_PP_INTERCEPT ) > { typedef typename result::result_type type; }; template typename result< Derived const( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const & BOOST_PP_INTERCEPT) ) >::type operator ()(BOOST_PP_ENUM_BINARY_PARAMS(N, A, const &a)) const { result< Derived const( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const & BOOST_PP_INTERCEPT) ) > impl; #define M0(Z, N, DATA) \ static_cast \ ::reference>(BOOST_PP_CAT(a, N)) return impl(BOOST_PP_ENUM(N, M0, ~)); #undef M0 } #undef N #elif 1 == BOOST_PP_ITERATION_FLAGS() #define N BOOST_PP_ITERATION() //////////////////////////////////////////////////////////////////////////////////////////////// template struct poly_function_traits > { typedef typename PolyFun::template impl function_type; typedef typename function_type::result_type result_type; }; //////////////////////////////////////////////////////////////////////////////////////////////// template struct as_mono_function_impl { typedef typename PolyFun::template impl type; }; //////////////////////////////////////////////////////////////////////////////////////////////// template struct as_mono_function_impl { typedef PolyFun type; }; //////////////////////////////////////////////////////////////////////////////////////////////// template struct as_mono_function : as_mono_function_impl::value> {}; #undef N #endif