Index: ref.hpp =================================================================== --- ref.hpp (revision 78366) +++ ref.hpp (working copy) @@ -12,6 +12,16 @@ #include #include +// operator() forwarding +#include +#include +#include +#include +#include + +#include +#include + // // ref.hpp - ref/cref, useful helper functions // @@ -50,6 +60,33 @@ T* get_pointer() const { return t_; } +#define FWD_REF(z, n, name) BOOST_PP_CAT(BOOST_FWD_REF(BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, name), n)) BOOST_PP_TUPLE_ELEM(2, 1, name), n) +#define FWD(x, y) boost::forward(y) +#define FWDER(z, n, x) FWD(BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, x), n), BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 1, x), n)) + +#define FN(z, n, data) \ + template \ + typename boost::result_of::type \ + operator()( BOOST_PP_ENUM(n, FWD_REF, (T, t) ) ) \ + { \ + return t_->operator()(BOOST_PP_ENUM(n, FWDER, (T, t) )); \ + } \ + + // null-ary written without FN macro to prevent no-argument template + typename boost::result_of::type + operator()() + { + return t_->operator()(); + } + + // TODO make argument length configurable + BOOST_PP_REPEAT_FROM_TO(1, 8, FN, _); + +#undef FWD_REF +#undef FWD +#undef FWDER +#undef FN + private: T* t_;