Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
您可以获得using的n第 th 个元素的值。但是我需要将该元组的一个元素作为对函数的引用传递。std::tuplestd::get<n>(tuple)
n
std::tuple
std::get<n>(tuple)
如何获取对 a 元素的引用std::tuple?
std::get返回一个引用(常量或非常量),所以这有效:
std::get
void fun(int &a) { a = 15; } void test() { std::tuple<int, char> foo{ 12, 'a' }; fun(std::get<0>(foo)); }
演示在这里。
get根据其参数的类型返回引用、右值引用或 const 引用。
get