C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Get base class from std::any

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Mon, 27 Mar 2023 00:32:01 +0500
> Of course it only took an hour after writing the email to work out
> how to do this...
>
> The key thing is that we can throw a Derived* and catch a Base*.
>
> So any can store a function that throws the contained value, and the
> any_cast implementation can invoke that function, and catch the cast-to
> type.
>
> Would an implementation that didn't throw-catch but used the
> compiler-generated tables more directly be significantly more efficient?

You can look at an implementation relying on Itanium ABI to cast type-erased thing here: https://github.com/root-project/root/pull/463

BTW: http://wg21.link/p0042

Received on 2023-03-26 19:32:09