Ticket #6876: add_forwarding_to_ref.patch

File add_forwarding_to_ref.patch, 1.9 KB (added by philipp.moeller@…, 10 years ago)

patch to add forwarding of operator() to reference_wrapper

  • ref.hpp

     
    1212#include <boost/mpl/bool.hpp>
    1313#include <boost/detail/workaround.hpp>
    1414
     15// operator() forwarding
     16#include <boost/preprocessor/cat.hpp>
     17#include <boost/preprocessor/repetition/repeat_from_to.hpp>
     18#include <boost/preprocessor/repetition/enum.hpp>
     19#include <boost/preprocessor/repetition/enum_params.hpp>
     20#include <boost/preprocessor/tuple/elem.hpp>
     21
     22#include <boost/utility/result_of.hpp>
     23#include <boost/move/move.hpp>
     24
    1525//
    1626//  ref.hpp - ref/cref, useful helper functions
    1727//
     
    5060
    5161    T* get_pointer() const { return t_; }
    5262
     63#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)
     64#define FWD(x, y) boost::forward<x>(y)
     65#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))
     66
     67#define FN(z, n, data)                                                    \
     68    template<BOOST_PP_ENUM_PARAMS(n, class T)>                            \
     69    typename boost::result_of<T( BOOST_PP_ENUM_PARAMS(n, T) )>::type      \
     70    operator()( BOOST_PP_ENUM(n, FWD_REF, (T, t) ) )                      \
     71    {                                                                     \
     72      return t_->operator()(BOOST_PP_ENUM(n, FWDER, (T, t) ));            \
     73    }                                                                     \
     74
     75    // null-ary written without FN macro to prevent no-argument template
     76    typename boost::result_of<T()>::type
     77    operator()()
     78    {
     79      return t_->operator()();
     80    }
     81
     82    // TODO make argument length configurable
     83    BOOST_PP_REPEAT_FROM_TO(1, 8, FN, _);
     84
     85#undef FWD_REF
     86#undef FWD
     87#undef FWDER
     88#undef FN
     89
    5390private:
    5491
    5592    T* t_;