I want to pass a parameter pack into a template method that creates a new instance of an object of a type specified by another template argument.
Minimal code example:
my code actually does more operations with the created type and the handler
template<typename T, typename... Args>
static bool CreateAndDo(Handler & rHandler, Args.. args)
{
auto pT = T::Create(args...);
rHandler.DoStuff(std::move(pT));
}
Simple Usage:
Handler tHander;
// the 0 is just an example of an argument
CreateAndDo<ConcreteType>(tHander, 0);
Now my problem is that one of my arguments is a std::unique_ptr
.
auto pPtr = std::make_unique<ConcreteArg>();
CreateAndDo<ConcreteType>(tHander, std::move(pPtr));
This fails to compile, because the std::unique_ptr
would have to be moved by CreateAndDo
Method.
I know that I need to keep moving the arguments but I don't know how to do that with a parameter pack.
How could I accomplish this?