This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.

### 2768. `any_cast` and move semantics

Section: 20.8.5 [any.nonmembers] Status: C++17 Submitter: Casey Carter Opened: 2016-08-27 Last modified: 2017-07-30

Priority: 0

View other active issues in [any.nonmembers].

View all other issues in [any.nonmembers].

View all issues with C++17 status.

Discussion:

LWG 2509 made two changes to the specification of `any` in v2 of the library fundamentals TS:

1. It altered the effects of the `any_cast(any&&)` overload to enable moving the value out of the `any` object and/or obtaining an rvalue reference to the contained value.
2. It made changes to support pathological copyable-but-not-movable contained values, which is madness.

Change 1 has very desirable effects; I propose that we apply the sane part of LWG 2509 to `any` in the C++17 WP, for all of the reasons cited in the discussion of LWG 2509.

[2016-09-09 Issues Resolution Telecon]

P0; move to Tentatively Ready

Previous resolution [SUPERSEDED]:

> This wording is relative to N4606.

> 1. In 20.8.5 [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 third forms, `*any_cast<remove_reference_t<ValueType>>(&operand)`. For the third form, `std::forward<ValueType>(*any_cast<remove_reference_t<ValueType>>(&operand))`.

>    > > […]

[Issues Telecon 16-Dec-2016]

Move to Tentatively Ready

Proposed resolution:

Resolved by the wording provided by LWG 2769.