You can get the value of the nth element std::tupleusing std::get<n>(tuple). But I need to pass one element of this tuple as a reference to a function.
n
std::tuple
std::get<n>(tuple)
How to get a link to an item std::tuple?
std::get returns a link (either const or not const), so this works:
std::get
void fun(int &a) { a = 15; } void test() { std::tuple<int, char> foo{ 12, 'a' }; fun(std::get<0>(foo)); }
Demo is here .
std::get returns a reference to the element at the specified position in the tuple.
http://www.cplusplus.com/reference/tuple/get/
get , rvalue .
get