C++ C++;std::reference\u包装器如何隐式转换为reference?
我最近开始使用C++ C++;std::reference\u包装器如何隐式转换为reference?,c++,reference,c++11,implicit-conversion,reference-wrapper,C++,Reference,C++11,Implicit Conversion,Reference Wrapper,我最近开始使用std::reference\u包装器类。在替换基元引用的某些用法时,我注意到我不必使用get()函数将引用包装器作为参数传递给采用普通引用的函数 void foo(const T& a); //... T obj; std::reference_wrapper<const T> ref(obj); foo(ref); //works! //foo(ref.get()); also works, but I expected that it would be
std::reference\u包装器类。在替换基元引用的某些用法时,我注意到我不必使用get()
函数将引用包装器作为参数传递给采用普通引用的函数
void foo(const T& a);
//...
T obj;
std::reference_wrapper<const T> ref(obj);
foo(ref); //works!
//foo(ref.get()); also works, but I expected that it would be required
void foo(const T&a);
//...
T-obj;
标准:参考包装参考(obj);
foo(ref)//作品
//foo(ref.get());也可以,但我认为这是必需的
std::reference\u包装器
在传递到函数时如何隐式转换为基元引用?它重载此转换运算符:
operator T& () const;
参考文件包括(§20.8.3):
这是一个转换运算符,因为它没有指定为显式
,所以它允许从引用包装器
隐式转换为t&
// access
operator T& () const noexcept;