写这个表达式在语义上有什么区别吗?
std::tie( x, y, z )
下面的表达式呢?
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
创建的,而是通过显式指定类型来创建的。
发布于 2016-04-25 21:17:38
当x
、y
和z
中的任何一个是std::reference_wrapper
的特殊化时,这是有区别的。
#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&>
}
https://stackoverflow.com/questions/36839648
复制相似问题