Vin*_*ent 3 c++ templates reference c++11 universal-reference
在下面,是&&一个普遍的参考?
template <class Function = std::greater<int> > void f(Function&& f = Function());
Run Code Online (Sandbox Code Playgroud)
该术语universal reference是由Scott Meyers用来区分正常的右值引用,即int&&模板代码中的右值引用,即T&&.这很重要,因为参考折叠规则与模板代码一起发挥作用,因此该术语用于辅助教学.它被称为a的原因unversal reference是因为它可以绑定任何东西.
请记住,universal reference在C++语言中没有这样的东西,Function&&就语言而言,它是一个右值引用.但是,是的,在Scott Meyer的术语中,Function&&是一个universal reference在你的例子中.