C++ Logo

std-proposals

Advanced search

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

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Thu, 11 Apr 2024 22:03:38 +0300
On Thu, 11 Apr 2024 at 21:54, Tiago Freire via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> For that I could design a templated class, let’s call it “doppelganger”, that can contain an object of a “derived” class but only presents itself as an interface to a “base” class.
>
> i.e.
>
>
>
> class A{};
>
> class B: public A {};
>
>
>
> std::doppelganger<A> tracked_object = B{};
>
>
>
> // tracked_object can be used as A, but is an object of type B //this is a pure liskov abstraction
>
>
>
> Kind of like what you already can do with std::unique_ptr but with value semantics instead.

In other words, the proposed std::polymorphic_value. https://wg21.link/p3019


> If you had this ^, would you really still need to use std::any?

Well, sometimes yes, if you have pieces of code that just transfer
anything at all from here to there.
They can transfer not just a polymorphic_value<Widget>, but any other
unrelated type as well.
The sending and receiving ends then know what to do with whatever
specific type is inside the std::any.

Received on 2024-04-11 19:03:56