I've been trying to understand the difference between Ts&&...
and Ts&...
for variadic functions, but can't find any explanations.
What are the differences between the two, and when would I use one over the other?
I've been trying to understand the difference between Ts&&...
and Ts&...
for variadic functions, but can't find any explanations.
What are the differences between the two, and when would I use one over the other?
It's the same as the difference between T&
and T&&
.
Ts&...
only binds to lvalues. Ts&&...
binds to both lvalues and rvalues and can be used to implement perfect forwarding.
Usually you'll probably want Ts&&...
since it's hard to imagine why a function should be specified to accept arbitrarily many lvalues of arbitrary type, but not any rvalues. Functions that contain a Ts&&...
are usually functions like emplace
member functions that forward all the arguments to another function, such as a constructor.