Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If it needs to work in vs2010, then your best bet is <a href="http://www.boost.org/libs/preprocessor" rel="nofollow">Boost.Preprocessor</a>. It is not as robust as variadic templates in that it has a maximum recursion depth of 3 and a maximum iteration count of 256, but it works in every compiler with or without C++11 support. It isn't completely clear what you are trying to do with those examples, but if you are just trying to decorate functions, I use the following (utilizes C++11 for perfect forwarding with Boost.Preprocessor instead of variadic templates):</p> <pre><code>#define FORWARD(z, n, data) \ ::std::forward&lt;BOOST_PP_CAT(BOOST_PP_TUPLE_ELEM(2, 0, data), n)&gt; \ (BOOST_PP_CAT(BOST_PP_TUPLE_ELEM(2, 1, data), n)) \ /**/ //------------------------------------------------------------------------ // template&lt;class R, class... A&gt; // ::std::function&lt;R(A...)&gt; decorate(::std::function&lt;R(A...)&gt; const&amp; func) // { // return [func](A&amp;&amp;... a) -&gt; R // { // /* DECORATOR STUFF */ // return func(::std::forward&lt;A&gt;(a)...); // }; // } //------------------------------------------------------------------------ #define MACRO(z, n, _) \ template&lt;class R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, class A)&gt; \ ::std::function&lt;R(BOOST_PP_ENUM_PARAMS_Z(z, n, a)&gt; \ decorate(::std::function&lt;R(BOOST_PP_ENUM_PARAMS_Z(z, n, A))&gt; const&amp; func) \ { \ return [func](BOOST_PP_ENUM_BINARY_PARAMS_Z(z, n, A, &amp;&amp;a)) -&gt; R \ { \ /* DECORATOR STUFF */ \ return func(BOOST_PP_ENUM_ ## z(n, FORWARD, (A, a))); \ }; \ } \ /**/ BOOST_PP_REPEAT(10, MACRO, ~) #undef MACRO #undef FORWARD </code></pre> <p>If you are just trying to bind up function arguments, then <a href="http://en.cppreference.com/w/cpp/utility/functional/bind" rel="nofollow">std::bind</a> is what you are looking for. Note that you can do any of this with just <a href="http://en.wikipedia.org/wiki/Anonymous_function#C.2B.2B" rel="nofollow">lambdas</a>, but the decorator functions can be used to decorate multiple functions (where as lambdas are of course one offs) and bind can be a little more concise for binding arguments (however, the lambda equivalent is sometimes more readable).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload