This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of TS status.
Section: 6.4 [fund.ts.v2::any.nonmembers] Status: TS Submitter: Ville Voutilainen Opened: 2015-06-13 Last modified: 2017-07-30
View all issues with TS status.
In Library Fundamentals v1, [any.nonmembers]/5 says:
For the first form, *any_cast<add_const_t<remove_reference_t<ValueType>>>(&operand). For the second and third forms, *any_cast<remove_reference_t<ValueType>>(&operand).
This means that
is always ill-formed. That's unfortunate, because forwarding such a cast result of an any is actually useful, and such uses do not want to copy/move the underlying value just yet.
Another problem is that that same specification prevents an implementation from moving to the target when
ValueType any_cast(any&& operand);
is used. The difference is observable, so an implementation can't perform an optimization under the as-if rule. We are pessimizing every CopyConstructible and MoveConstructible type because we are not using the move when we can. This unfortunately includes types such as the library containers, and we do not want such a pessimization!
Jonathan to provide wording
[2015-10, Kona Saturday afternoon]
Eric offered to help JW with wording
Move to Open
[2016-01-30, Ville comments and provides wording]
Drafting note: the first two changes add support for types that have explicitly deleted move constructors. Should we choose not to support such types at all, the third change is all we need. For the second change, there are still potential cases where Requires is fulfilled but Effects is ill-formed, if a suitably concocted type is thrown into the mix.
This wording is relative to N4562.
In 6.3.1 [fund.ts.v2::any.cons] p11+p12, edit as follows:
template<class ValueType> any(ValueType&& value);
-10- Let T be equal to decay_t<ValueType>.-11- Requires: T shall satisfy the CopyConstructible requirements. If is_copy_constructible_v<T> is false, the program is ill-formed. -12- Effects:
Constructs an object of type any that contains an object of type T direct-initialized with std::forward<ValueType>(value). […]
In 6.4 [fund.ts.v2::any.nonmembers] p5, edit as follows:
template<class ValueType> ValueType any_cast(const any& operand); template<class ValueType> ValueType any_cast(any& operand); template<class ValueType> ValueType any_cast(any&& operand);
-4- Requires: is_reference_v<ValueType> is true or is_copy_constructible_v<ValueType> is true. Otherwise the program is ill-formed.-5- Returns: For the first form, *any_cast<add_const_t<remove_reference_t<ValueType>>>(&operand). For the second
and thirdform s, *any_cast<remove_reference_t<ValueType>>(&operand). […]