c – 如何引用std :: tuple的元素?
发布时间:2020-12-16 03:26:59 所属栏目:百科 来源:网络整理
导读:您可以使用std :: get n(元组)获取std :: tuple的第n个元素的值.但我需要传递该元组的一个元素作为函数的引用. 如何获取std :: tuple元素的引用? 解决方法 std::get 返回一个引用(const或非const),所以这适用: void fun(int a) { a = 15;}void test() { st
您可以使用std :: get< n>(元组)获取std :: tuple的第n个元素的值.但我需要传递该元组的一个元素作为函数的引用.
如何获取std :: tuple元素的引用? 解决方法std::get 返回一个引用(const或非const),所以这适用:
void fun(int &a) { a = 15; } void test() { std::tuple<int,char> foo{ 12,'a' }; fun(std::get<0>(foo)); } 演示here. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |