c++ - Why does C++17's std::any not allow returning a movable value by any_cast? -
while implementing c++17's std::any
according specification available in wiki stumbled across seemed nonsensical me:
in definition of free function std::any_cast
, used retrieve values std::any
instance, overload r-value references supplied (it's third one):
template< class valuetype > valuetype any_cast(any&& operand); // (3)
now, there requirement listed below synopsis applies overloads 2 , 3 (that means including r-value overload):
2-3)
returns*any_cast<std::remove_reference_t<valuetype>>(&operand)
the definition does not seem allow moving data!
the function call redirected pointer-based overload; information temporary nature of operand
is lost!
is intended can't move out of instance? error in wiki? wrong here?
the issue in wp status @ time of writing this, which means:
wp - (working paper) - proposed resolution has not been accepted technical corrigendum, full wg21/pl22.16 committee has voted apply defect report's proposed resolution working paper.
see lwg here more info: http://wg21.cmeerw.net/lwg/issue2509
a proposed resolution indeed
for third form, if
is_move_constructible_v<valuetype>
true ,is_lvalue_reference_v<valuetype>
false,std::move(*any_cast<remove_reference_t<valuetype>>(&operand))
, otherwise,*any_cast<remove_reference_t<valuetype>>(&operand)
and defect report list listing wp: http://cplusplus.github.io/lwg/lwg-defects.html#2509
Comments
Post a Comment