C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::chimeric_ptr -- it's alive... it's ALIVE!

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 27 Nov 2025 23:20:12 +0000
On Thu, Nov 27, 2025 at 2:55 PM Magnus Fromreide wrote:
<snip>
> > Now let's say I was to come along at a later stage, with the goal of
> > writing a function that could safely prepare a microscope to be
> > powered down and packaged for shipping. So in this function, I would
> > move the stages to a safe place, I would cut the power circuit to the
> > lights and motors (but not before cooling down the lightbulbs), I
> > would reset the diagnostics, and so on. So I might write a function
> > something like:
> >
> > void PrepareForShipping( std::chimeric_ptr< IStage, IPower,
> > IIllumination, IDiagnostics, ICommsHandler > );
> >
> >
>
> Is this not the exact situation dynamic_cast was invented for?
>
> Using dynamic_cast also have the advantage that you are explicit about
> which interface you are working with so the whole ordering discussion
> becomes irrelevant.


In Arthur's blog post here:
https://quuxplusone.github.io/blog/2022/12/01/chimeric-ptr/ , he
mentions 4 possible solutions.

Scroll down to Solution No. 2, where he uses dynamic_cast.

It works, but you won't know until runtime if you give it an invalid
object. With 'std::chimeric_ptr', you get a compile-time error if you
supply a pointer which cannot be implicitly converted to a pointer to
any of the base types.

Received on 2025-11-27 23:20:10