#if !defined(BOOST_PP_IS_ITERATING) /* ************************************************************************** * * * (C) Copyright Paul Mensonides 2002. Permission to copy, use, * * modify, sell, and distribute this software is granted provided * * this copyright notice appears in all copies. This software is * * provided "as is" without express or implied warranty, and with * * no claim at to its suitability for any purpose. * * * ************************************************************************** */ #ifndef BOOST_CLOSURE_HPP #define BOOST_CLOSURE_HPP #include #include #include #include #include #include #if !defined BOOST_CLOSURE_MAX_ARITY # define BOOST_CLOSURE_MAX_ARITY 15 #endif namespace boost { template class closure; // pointer-to-data-member specialization template class closure { public: typedef typename add_reference::type return_type; static inline return_type make(O* obj, T O::* ptr) { return obj->*ptr; } }; // cv-qualifiers #define BOOST_CLOSURE_APPLY(x) BOOST_PP_CAT(BOOST_CLOSURE_APPLY_, x) #define BOOST_CLOSURE_APPLY_BOOST_CLOSURE_APPLY_ITEM(v) v #define BOOST_CLOSURE_APPLY_BOOST_CLOSURE_APPLY_NIL #define BOOST_CLOSURE_CV_QUALIFIERS() (4, ( \ BOOST_CLOSURE_APPLY_NIL, \ BOOST_CLOSURE_APPLY_ITEM(const), \ BOOST_CLOSURE_APPLY_ITEM(volatile), \ BOOST_CLOSURE_APPLY_ITEM(const volatile) \ )) // repetition macros (BOOST_PP_ENUM_PARAMS is too slow) #define BOOST_CLOSURE_NTH(n, text) BOOST_PP_COMMA_IF(n) text ## n #define BOOST_CLOSURE_BIN_NTH(n, _) \ BOOST_PP_COMMA_IF(n) \ BOOST_PP_CAT(BOOST_PP_ARRAY_ELEM(0, _), n) \ BOOST_PP_CAT(BOOST_PP_ARRAY_ELEM(1, _), n) // iterate over cv-qualifiers... #define BOOST_PP_ITERATION_PARAMS_1 3, (0, 3, "closure.hpp") ??=include BOOST_PP_ITERATE() // clean-up temporary pp facilities #undef BOOST_CLOSURE_APPLY #undef BOOST_CLOSURE_APPLY_BOOST_CLOSURE_APPLY_ITEM #undef BOOST_CLOSURE_APPLY_BOOST_CLOSURE_APPLY_NIL #undef BOOST_CLOSURE_CV_QUALIFIERS #undef BOOST_CLOSURE_NTH #undef BOOST_CLOSURE_BIN_NTH template inline typename closure::return_type make_closure(T* obj, U ptr) { return closure::make(obj, ptr); } } // boost #endif // BOOST_CLOSURE_HPP #elif BOOST_PP_ITERATION_DEPTH() == 1 // iterate over function arities... #define BOOST_PP_ITERATION_PARAMS_2 3, (0, BOOST_CLOSURE_MAX_ARITY, "closure.hpp") ??=include BOOST_PP_ITERATE() #elif BOOST_PP_ITERATION_DEPTH() == 2 #line BOOST_PP_LINE(__LINE__, closure.hpp) #define I BOOST_PP_ITERATION() #define Q BOOST_CLOSURE_APPLY(BOOST_PP_ARRAY_ELEM(BOOST_PP_RELATIVE_ITERATION(1), BOOST_CLOSURE_CV_QUALIFIERS())) // pointer-to-member-function specializations template struct closure { private: O* m_obj; typedef R (O::* ptm_t)(BOOST_PP_REPEAT(I, BOOST_CLOSURE_NTH, P)) Q; ptm_t m_ptr; public: typedef closure return_type; inline closure(O* obj, ptm_t ptr) : m_obj(obj), m_ptr(ptr) { return; } inline R operator()(BOOST_PP_REPEAT(I, BOOST_CLOSURE_BIN_NTH, (2, (P, p)))) const { return (m_obj->*m_ptr)(BOOST_PP_REPEAT(I, BOOST_CLOSURE_NTH, p)); } static inline closure make(O* obj, ptm_t ptr) { return closure(obj, ptr); } }; #undef N #undef Q #endif