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).
- Does
const &&bind to all rvalues, specifically prvalues? - Would
const &&bind to all "moved objects" (xvalues; basically something returned fromstd::moveor similar)?
I can reason that it should, but I don't have any "proof" for this.
- Or conversely, are there cases where an rvalue (prvalue or xvalue) will not bind to
const &&?- If so, how so?
Note: some clarity from the comments, this question is heavily swayed to classic rvalues, the prvalue value category.
std::moveor similar - Niallconst T &&cannot work when you have an rvalue of typevolatile T. ButTis deduced here, soTcan be deduced as avolatile-qualified type if needed. - user743382std::movedoes" Sure, as long as someone taught you thatstd::movedoesn't actually move anything. - Lightness Races in Orbitstd::movealways returns an rvalue except when the argument is of function type---in this case it returns an lvalue, since there are no rvalues of function type. However, "rvalue reference to function" will still bind to an lvalue of function type. - Brian Bi