do对于const的引用有什么用处? [英] Do rvalue references to const have any use?
问题描述
我想没有,但我想确认。是否有用于 const Foo&&&
,其中 Foo
是类类型?
I guess not, but I would like to confirm. Is there any use for const Foo&&
, where Foo
is a class type?
推荐答案
它们偶尔有用。 C ++ 0x本身在几个地方使用它们,例如:
They are occasionally useful. The draft C++0x itself uses them in a few places, for example:
template <class T> void ref(const T&&) = delete;
template <class T> void cref(const T&&) = delete;
上述两个重载确保另一个 ref(T& code>和
cref(const T&)
函数不绑定到右值(否则可能)。
The above two overloads ensure that the other ref(T&)
and cref(const T&)
functions do not bind to rvalues (which would otherwise be possible).
更新
I've just checked the official standard N3290, which unfortunately isn't publicly available, and it has in 20.8 Function objects [function.objects]/p2:
template <class T> void ref(const T&&) = delete;
template <class T> void cref(const T&&) = delete;
然后我检查了最新的后C ++ 11草稿, href =http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3485.pdf> N3485 ,并在20.8函数对象[function.objects] / p2它仍然说:
Then I checked the most recent post-C++11 draft, which is publicly available, N3485, and in 20.8 Function objects [function.objects]/p2 it still says:
template <class T> void ref(const T&&) = delete;
template <class T> void cref(const T&&) = delete;
这篇关于do对于const的引用有什么用处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!