问题描述
C ++标准定义了以下函数已删除:
The C++ standard defines the following functions deleted;
template <class T>
void ref(const T&&) = delete;
template <class T>
void cref(const T&&) = delete;
这是为了帮助确保函数不被滥用,不允许它们绑定到临时值
This is to aid in ensuring that the functions are not misused by disallowing them from binding to temporary values (rvalues).
-
const&&&
绑定到所有rvalues prvalues? - 将
const&&&
绑定到所有移动对象(xvalues;基本上从std :: move
或类似)?
- Does
const &&
bind to all rvalues, specifically prvalues? - Would
const &&
bind to all "moved objects" (xvalues; basically something returned fromstd::move
or similar)?
- 或者相反,有些情况下,右值(prvalue或xvalue)
const&&&
?
- 如果是,如何?
注意:从注释中有一些清楚,这个问题严重影响了经典值,即prvalue值类别。
Note: some clarity from the comments, this question is heavily swayed to classic rvalues, the prvalue value category.
推荐答案
T const&&
可以绑定类型T
或const T
。strong> [dcl.init.ref] 段落5:
From 8.5.3 [dcl.init.ref] paragraph 5:
如果初始化器表达式是非类型的prvalue,那么将创建一个用于引用绑定的临时副本(ibid)。
If the initializer expression is a prvalue of non-class type, then a temporary copy is created for reference binding (ibid).
引用兼容性在8.5 .3p4;它需要一个同类或基类关系和相同或更大的cv限定。
Reference-compatibility is defined in 8.5.3p4; it requires a same-or-base-class relationship and same-or-greater cv qualification.
所以对于一个右值绑定到
T const& ;&
,其cv-qualification必须不大于const
。So for an rvalue to bind to
T const&&
, its cv-qualification must be no greater thanconst
.这篇关于`const&&`绑定到所有prvalues(和xvalues)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!