Apply function from std :: tuple

Possible duplicate:
"unzip" the tuple to call the corresponding function pointer

I create a closure object to wrap the function and its parameters in order to create a zero parameter functor:

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

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

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

What is the most concise way to build a function apply_from_tuple?

+3
source share

All Articles