3

Possible Duplicate:
“unpacking” a tuple to call a matching function pointer

I'm building a closure object to wrap a function and its parameters, to create a functor of zero parameters:

template<typename Function, typename... Args>
  struct closure
{
  closure(Function f, Args... args)
    : f(f),args(args...)
  {}

  void operator()()
  {
    // call f using the tuple's elements as arguments
    apply_from_tuple(f,args);
  }

  Function f;
  std::tuple<Args...> args;
};

What's the most concise way to build the function apply_from_tuple?

Community
  • 1
  • 1
Jared Hoberock
  • 11,118
  • 3
  • 40
  • 76
  • 2
    [Boost.Fusion](http://www.boost.org/libs/fusion/) already has this functionality in `boost::fusion::fused`, `boost::fusion::fused_procedure`, and `boost::fusion::fused_function_object` -- are you sure you need to reinvent the wheel here? – ildjarn Apr 20 '12 at 22:22
  • 1
    Yes, I'm sure. It would be valuable to me to understand the details of the technique involved. – Jared Hoberock Apr 20 '12 at 22:23
  • 6
    Seems very similar to [“unpacking” a tuple to call a matching function pointer](http://stackoverflow.com/questions/7858817/unpacking-a-tuple-to-call-a-matching-function-pointer). – Jesse Good Apr 20 '12 at 22:32
  • No problem. There also is a similar but different technique [here](http://stackoverflow.com/questions/4763736/vs2010-c-variadic-template-example) in the second answer. – Jesse Good Apr 20 '12 at 22:39

0 Answers0