C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Extend std::type_info with more information

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Sat, 13 Apr 2024 01:51:05 +0100
On Sat, Apr 13, 2024 at 12:54 AM Marcin Jaczewski
<marcinjaczewski86_at_[hidden]> wrote:
>
> template<typename T>
> MyAny(T&& t) : std::any(t), throw_object_ptr { +[](std::any& a) {
> throw std::any_cast<T>(&a); } } {}


We're trying to get this done without an ABI break. If we're allowed
to break ABI then we can do all sorts of stuff -- such as creating a
lambda like you've done.

We want to add more functionality without inducing an ABI break. That
is to say, if you have a pre-built DLL file on Windows from two years
ago, or a prebuilt SO file on Linux from last year, and if this
prebuilt library exports a function such as:

    std::any &get_my_any(void);

Then we want to be able to determine if the contained object has a
base T. So all we have to work with is:
   (1) The address of the object
   (2) The type_info of the object

We don't have a lambda that was created upon construction of the 'any'.

Received on 2024-04-13 00:51:17