- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
std::add_lvalue_reference
和 std::add_rvalue_reference
的用途是什么?
看起来使用 T &
/T &&
的效果是一样的,因为这成功编译了:
#include <utility>
int main() {
{ using T = int; static_assert(std::is_same_v<std::add_lvalue_reference_t<T>, T &>); };
{ using T = int &; static_assert(std::is_same_v<std::add_lvalue_reference_t<T>, T &>); };
{ using T = int &&; static_assert(std::is_same_v<std::add_lvalue_reference_t<T>, T &>); };
{ using T = int; static_assert(std::is_same_v<std::add_rvalue_reference_t<T>, T &&>); };
{ using T = int &; static_assert(std::is_same_v<std::add_rvalue_reference_t<T>, T &&>); };
{ using T = int &&; static_assert(std::is_same_v<std::add_rvalue_reference_t<T>, T &&>); };
}
最佳答案
void&
格式不正确。 std::add_lvalue_reference<void>
是 void
.
一般来说,add_lvalue_reference
如果不可能,则不会添加对类型的引用。每[meta.trans.ref] :
template <class T>
struct add_lvalue_reference;If T names a referenceable type then the member typedef
type
namesT&
; otherwise,type
namesT
. [ Note: This rule reflects the semantics of reference collapsing ([dcl.ref]). — end note ]
什么是可引用类型?每[defns.referenceable] ,可引用的类型是
an object type, a function type that does not have cv-qualifiers or a ref-qualifier, or a reference type [ Note: The term describes a type to which a reference can be created, including reference types. — end note ]
关于c++ - std::add_lvalue_reference 和 std::add_rvalue_reference 的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57819653/
我有这样一个类,它为 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
我是一名优秀的程序员,十分优秀!