C ++ 11标准是否通过“ auto n2 = const_cast <int&>(n);”来保证“ n2 is int&”?

xmllmx
const int n = 0;
auto& n1 = const_cast<int&>(n);
auto n2 = const_cast<int&>(n);

请问C ++ 11标准保证n2 is int&auto n2 = const_cast<int&>(n);

我必须使用auto& n1 = const_cast<int&>(n);代替auto n2 = const_cast<int&>(n);吗?

按照C ++ 11标准,这两种方式是否完全彼此等同?

马克西姆·埃格鲁什金

auto 使用与常规函数模板参数推导相同的规则,该规则从未推导引用。

decltype(auto)另一方面,C ++ 14可以在此推论参考。以及C ++ 11 auto&&

const int n = 0;
auto a = const_cast<int&>(n);           // a is int
decltype(auto) b = const_cast<int&>(n); // b is int&
auto&& c = const_cast<int&>(n);         // c is int&

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

通过将std :: tuple <int&,int>分配给const std :: tuple <int,int>&来延长其寿命

返回类型const int&

'max'没有重载匹配'std :: function <const int&(const int&,const int&)>'

结构接触{int n1; 浮点数n2; char st [10]} d1;

没有匹配的函数可以调用'std :: less <int> :: less(const int&,const int&)'

为什么使用别名int&允许创建非函数类型const(int&)?

返回值int&和const int&之间的差异

打印出大于等于N1且小于等于N2的11的倍数

int vs const int&,当我使用它时

INT 如何在 C++ 中作为 INT& 返回?

C ++返回不能从int转换为int&

转换后获取\ n1 \ n2输出

“const int&”作为返回类型有什么作用?

如何编写矩阵 nxn 的 O(n2) 程序?

时间复杂度小于 O(n2) 的算法

返回值int&

如何證明定理 plus_lt : forall n1 n2 m, n1 + n2 < m -> n1 < m /\ n2 < m

类型'const int'的表达式对类型'int&'的引用的无效初始化

C++ 错误:不匹配调用 '(std::list<int>) (int&)'

将std :: function <int(int)>分配给std :: function <const int&(const int&x)>

我可以在Cloud Dataproc中使用n2或n2d机器类型吗?

为什么2 for循环的时间复杂度不是O(N2 ^ N)?

如何编写is_reference_const函数,使is_reference_const <const int&> :: value`正确

is_const <const int&> :: value为false-为什么?

试图了解Θ(n2)和Θ(n)在运行时间方面的差异

O(nm + n2 log n) 复杂度时间多项式时间?

在SELECT查询中插入COUNT n1和n2列

在 python 中使用 super().Sub(n1,n2) 出错

大O表示法-这是O(n)还是O(n2)?