In general, you should only use tuple
for data that will be wrapped up and consumed within a few lines of each other, or when you actually have no knowledge of what the data is other than you need to package it together. Sometimes both.
This makes it very useful for generic programming where you want to, say, package up some arguments and unpack them later. Or, if you have a local lambda that you want to a sub-result out of and don't want to make a struct for it -- but even then, I'd be tempted with a struct.
A great use for tuple
is to have your struct
return a std::tie
(a tuple
of references) of its parameters via a make_tie
method (and const
version). tuple
writes things like a lexical operator<
for you, and this results in bug resistant implementations of <
and ==
and even =
in some cases (where default equality isn't quite right, but you want to invoke default equality as a sub-problem).