C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::any::base

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 15 Apr 2024 13:34:29 +0100
On Mon, Apr 15, 2024 at 12:02 PM Sebastian Wittmeier via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Does the base function throw, if the base is not unique for the derived class object in any?
>
> This condition cannot be detected at compile-time, as the dynamic type of the object in any (and therefore its ancestry relationship) is not known.


How about we make it behave the same way dynamic_cast would in this scenario?
If you try to case from a Derived to a Base at runtime, and if the
Base is not unique, you get a nullptr (or it throws
std::bad_any_cast).

Received on 2024-04-15 12:34:41