Chris@16: Chris@16: // Copyright (C) 2009-2012 Lorenzo Caminiti Chris@16: // Distributed under the Boost Software License, Version 1.0 Chris@16: // (see accompanying file LICENSE_1_0.txt or a copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: // Home at http://www.boost.org/libs/functional/overloaded_function Chris@16: Chris@16: #if !BOOST_PP_IS_ITERATING Chris@16: # ifndef BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_BASE_HPP_ Chris@16: # define BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_DETAIL_BASE_HPP_ Chris@16: Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: # include Chris@16: Chris@16: #define BOOST_FUNCTIONAL_DETAIL_arg_type(z, n, unused) \ Chris@16: BOOST_PP_CAT(A, n) Chris@16: Chris@16: #define BOOST_FUNCTIONAL_DETAIL_arg_name(z, n, unused) \ Chris@16: BOOST_PP_CAT(a, n) Chris@16: Chris@16: #define BOOST_FUNCTIONAL_DETAIL_arg_tparam(z, n, unused) \ Chris@16: typename BOOST_FUNCTIONAL_DETAIL_arg_type(z, n, unused) Chris@16: Chris@16: #define BOOST_FUNCTIONAL_DETAIL_arg(z, n, unused) \ Chris@16: BOOST_FUNCTIONAL_DETAIL_arg_type(z, n, unused) \ Chris@16: BOOST_FUNCTIONAL_DETAIL_arg_name(z, n, unused) Chris@16: Chris@16: #define BOOST_FUNCTIONAL_DETAIL_f \ Chris@16: R (BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity, \ Chris@16: BOOST_FUNCTIONAL_DETAIL_arg_type, ~)) Chris@16: Chris@16: // Do not use namespace ::detail because overloaded_function is already a class. Chris@16: namespace boost { namespace overloaded_function_detail { Chris@16: Chris@16: template Chris@16: class base {}; // Empty template cannot be used directly (only its spec). Chris@16: Chris@16: # define BOOST_PP_ITERATION_PARAMS_1 \ Chris@16: (3, (0, BOOST_FUNCTIONAL_OVERLOADED_FUNCTION_CONFIG_ARITY_MAX, \ Chris@16: "boost/functional/overloaded_function/detail/base.hpp")) Chris@16: # include BOOST_PP_ITERATE() // Iterate over funciton arity. Chris@16: Chris@16: } } // namespace Chris@16: Chris@16: #undef BOOST_FUNCTIONAL_DETAIL_arg_type Chris@16: #undef BOOST_FUNCTIONAL_DETAIL_arg_name Chris@16: #undef BOOST_FUNCTIONAL_DETAIL_arg_tparam Chris@16: #undef BOOST_FUNCTIONAL_DETAIL_arg Chris@16: #undef BOOST_FUNCTIONAL_DETAIL_f Chris@16: Chris@16: # endif // #include guard Chris@16: Chris@16: #elif BOOST_PP_ITERATION_DEPTH() == 1 Chris@16: # define BOOST_FUNCTIONAL_DETAIL_arity BOOST_PP_FRAME_ITERATION(1) Chris@16: Chris@16: template< Chris@16: typename R Chris@16: BOOST_PP_COMMA_IF(BOOST_FUNCTIONAL_DETAIL_arity) Chris@16: BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity, Chris@16: BOOST_FUNCTIONAL_DETAIL_arg_tparam, ~) Chris@16: > Chris@16: class base< BOOST_FUNCTIONAL_DETAIL_f > { Chris@16: public: Chris@16: /* implicit */ inline base( Chris@16: // This requires specified type to be implicitly convertible to Chris@16: // a boost::function<> functor. Chris@16: boost::function< BOOST_FUNCTIONAL_DETAIL_f > const& f): f_(f) Chris@16: {} Chris@16: Chris@16: inline R operator()(BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity, Chris@16: BOOST_FUNCTIONAL_DETAIL_arg, ~)) const { Chris@16: return f_(BOOST_PP_ENUM(BOOST_FUNCTIONAL_DETAIL_arity, Chris@16: BOOST_FUNCTIONAL_DETAIL_arg_name, ~)); Chris@16: } Chris@16: Chris@16: private: Chris@16: boost::function< BOOST_FUNCTIONAL_DETAIL_f > const f_; Chris@16: }; Chris@16: Chris@16: # undef BOOST_FUNCTIONAL_DETAIL_arity Chris@16: #endif // iteration Chris@16: