首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >带std::ref参数的std::tie和std::make_tuple有什么区别?

带std::ref参数的std::tie和std::make_tuple有什么区别?
EN

Stack Overflow用户
提问于 2016-04-25 19:46:46
回答 1查看 2.5K关注 0票数 22

写这个表达式在语义上有什么区别吗?

代码语言:javascript
复制
std::tie( x, y, z )

下面的表达式呢?

代码语言:javascript
复制
std::make_tuple( std::ref(x), std::ref(y), std::ref(z) )

如果是这样,有什么不同?

顺便说一下,这个问题与What is the difference between assigning to std::tie and tuple of references?的问题不同,因为引用元组不是通过std::ref创建的,而是通过显式指定类型来创建的。

EN

回答 1

Stack Overflow用户

发布于 2016-04-25 21:17:38

xyz中的任何一个是std::reference_wrapper的特殊化时,这是有区别的。

代码语言:javascript
复制
#include <tuple>
#include <functional>

void f(std::reference_wrapper<int> x, int y, int z)
{
    std::tie(x,y,z); // type is std::tuple<std::reference_wrapper<int>&, int&, int&>
    std::make_tuple(std::ref(x),std::ref(y),std::ref(z)); // type is std::tuple<int&, int&, int&>
}
票数 16
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36839648

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档