There are some questions which relate to this topic:
How to make a tuple of const references?
std::make_tuple doesn't make references
But neither discusses how to make a tuple of lvalue references from a tuple of values.
Here is what I've got:
template <typename... Args>
std::tuple<Args&...> MakeTupleRef(const std::tuple<Args...>& tuple)
{
return std::tie(tuple); // this fails because std::tie expects a list of arguments, not a tuple.
}
int main()
{
std::tuple<int, int> tup;
std::tuple<int&, int&> tup2 = MakeTupleRef(tup); // the values of tup2 should refer to those in tup
return 0;
}
As far as I can tell std::tie
is ideal here because it produces lvalue references, but it doesn't accept a tuple as an input. How can I get around this problem?