C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Allow downcasting at compile time if Derived has no extra member objects

From: Breno Guimarães <brenorg_at_[hidden]>
Date: Wed, 22 Feb 2023 22:37:47 -0300
Also, you can always go with something like this:
https://godbolt.org/z/dfKdq7Er4

On Wed, Feb 22, 2023 at 10:32 PM Jason McKesson via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Wed, Feb 22, 2023 at 7:52 PM Frederick Virchanza Gotham via
> Std-Proposals <std-proposals_at_[hidden]> wrote:
> >
> > To give an example where this would be useful, let's say that I want
> > to use a 'std::binary_semaphore' as though it were a Lockable. The
> > following code works fine with every C++ compiler:
>
> No, absolutely not.
>
> Ignoring the fact that this is a bad idea because that's not how
> semaphores work (more on that in the other thread), this also isn't
> how the type system works.
>
> What you're talking about is analogous with Rust traits, but Rust
> traits are not *types* and are not treated as types. You can't use the
> type mechanism for this; you'd have to build some other mechanism the
> way Rust did (or C++ does using traits classes in templates).
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2023-02-23 01:38:00