template <typename Func, typename... Args>
static void WraperFunc(Func func, Args &&... args) {
SomeFunc(func, args...);
}
vs
template <typename Func, typename... Args>
static void WraperFunc(Func func, Args ... args) {
SomeFunc(func, args...);
}
Which is better and more recommended? Or is there an alternative which is better than both?
The first one, but you need to forward your arguments during expansion by using
std::forward<T>
. This allows your parameter pack to be expanded while properly deducing your arguments.As an example, say you have a function declared as follows:
Attempting to use said function with a temporary value or rvalue will fail:
This is due to the fact that 5 is a constant, which cannot be assigned to
int&
.