as far know, cannot declare rvalue reference void
.
example, following code ill-formed:
void f(void &&v) { }
from [20.2.6/1] (function template declval) have declaration declval
is:
template <class t> add_rvalue_reference_t<t> declval() noexcept;
thus, declval<void>
(let me say) would result in void &&
, guessed ill-formed in previous example.
anyway, following minimal, working example compiles:
#include<utility> int main() { decltype(std::declval<void>())* ptr = nullptr; }
note following true too:
static_assert(std::is_same<decltype(std::declval<void>()), void>::value, "!");
i have expected void&&
mentioned (or better, expecting fails compile).
actually, happens rvalue reference other non-reference type.
example:
static_assert(std::is_same<decltype(std::declval<int>()), int&&>::value, "!");
is declval<void>
valid expression or not? code above legal?
why behavior in case of void
different other type? (for wouldn't have worked otherwise answer, if code legal).
if it's legal, standard allow that? i've not been able find case.
of course, standard says:
the template parameter t of declval may incomplete type.
anyway, here result in non acceptable type (void&&
) , works around discarding rvalue reference.
add_rvalue_reference<t>
results in t&&
if t
referenceable type. when t
void
, result void
. why can add_rvalue_reference<int&&>
, not error attempting construct reference reference. (same lvalue reference.)
Comments
Post a Comment