c++ - How to get reference to an element of a std::tuple? -
you can value of nth element of std::tuple using std::get<n>(tuple). need pass 1 element of tuple reference function.
how reference element of std::tuple?
std::get returns reference(either const or non-const), works:
void fun(int &a) { = 15; } void test() { std::tuple<int, char> foo{ 12, 'a' }; fun(std::get<0>(foo)); } demo here.
Comments
Post a Comment