- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
cppreference.com关于std::add_lvalue_reference
/std::add_rvalue_reference
:
If T is an object type or a function type that has no cv- or ref- qualifier, provides a member typedef type which is T&&, otherwise type is T.
这是否意味着如果 T 是 const 或 volatile 则 T 不会转换为引用?如果不是,那么“没有 cv 限定符”是什么意思。
最佳答案
Does it mean that if T is const or volatile than T is not converted to reference?
是的,但前提是它是一个函数。
cppreference 中的引述可能有点令人困惑。 cppreference有
If T is an object type or a function type that has no cv- or ref- qualifier, provides a member typedef type which is T&&, otherwise type is T.
这会让您相信 cv-qualifer 部分适用于对象和函数,但事实并非如此。实际text from the standard是
an object type, a function type that does not have cv-qualifiers or a ref-qualifier, or a reference type
所以没有cv-qualifier 和ref-qualifier 的任何对象类型和任何函数都会产生引用。带有 cv-qualifier 和/或 ref-qualifier 的引用或函数将产生 T
当您看到 cv-qualifier 时,表示 const 和/或 volatile 限定符,即它是 const 和/或 volatile 对象或 const 或 volatile 限定函数。 ref-qualifier 表示引用限定符,即函数只能在左值或右值上调用:void foo() &
或 void foo() &&
.
关于c++ - add_lvalue_reference/add_rvalue_reference 和 cv 限定类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57856978/
我有这样一个类,它为 montecarlo 模拟器创建路径,它需要从可用整数数组创建整数路径。因此,例如,我们可以从包含 {0,1,2,3,4} 的数组中提取长度为 3 的路径,这将生成 3,1,2
#include template using Ref1 = T & ; template using Ref2 = std::add_lvalue_reference_t; template vo
cppreference.com关于std::add_lvalue_reference/std::add_rvalue_reference: If T is an object type or a f
std::add_lvalue_reference 和 std::add_rvalue_reference 的用途是什么? 看起来使用 T &/T && 的效果是一样的,因为这成功编译了: #incl
将类型更改为类型的reference,允许访问该类型的成员而无需创建该类型的实例。 lvalue references 和 rvalue references 似乎都是如此。 declval 是用 a
我是一名优秀的程序员,十分优秀!