Tag: 文献

C ++ std :: ref(T)与T&的区别

我有关于这个程序的一些问题: #include <iostream> #include <type_traits> #include <functional> using namespace std; template <typename T> void foo ( T x ) { auto r=ref(x); cout<<boolalpha; cout<<is_same<T&,decltype(r)>::value; } int main() { int x=5; foo (x); return 0; } 输出是: false 我想知道,如果std::ref没有返回一个对象的引用,那么它是做什么的? 基本上有什么区别: T x; auto r = ref(x); 和 T x; T &y = x; 另外,我想知道为什么这种差异存在? 当我们有引用(即T& )时,为什么我们需要std::ref或std::reference_wrapper […]