C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Fwd: Extension to runtime polymorphism proposed

From: <weinrich.steve_at_[hidden]>
Date: Sun, 5 Apr 2026 11:49:34 -0600
I have tried unsuccessfully to get Muneem to move from theoretical concepts
into actual C++ code. I have shown a standard solution to his "storage"
problem (copied below), but so far he has been unwilling to work with that.

He seems to be fixated on a container of some type that returns references
to different type of containers. For the life of me, I can't figure out why
this would be needed or how to make it type-safe!

///////////////////////////////////

A "standard" solution to storing the same type in different containers based
on a run-time discrimination:

class Storage
{
public:
    class Data {// TBD };
    class Key {// TBD};
 
    inline void put (const Key & key, const Data & data) {
storage[discriminator(data).put(key, data); }
    Data get (const Key &) const { return
storage[discriminator(data).put(key); }

private:
    int discriminator (const Data &) { // do something}

    class Impl
    {
    public:
        virtual void put (const Key &, const Data &) = 0;
        virtual Data get (const Key &) const = 0;
    };
 
    class FlavorOne : public Impl
    {
    private:
        void put (const Key &, const Data &) override {// do something}
        Data get (const Key &) const override {//do something}
 
        std::vector<Data> data;
    };
 
    FlavorOne flavorOne;
 
    class FlavorTwo : public Impl
    {
    private:
        void put (const Key &, const Data &) override {// do something}
        Data get (const Key &) const override {//do something}
 
        std::list<Data> data;
    };
 
    FlavorTwo flavorTwo;
 
    class FlavorThree : public Impl
    {
    private:
        void put (const Data &) override {// do something}
        Data get () const override {//do something}
 
        Std::deque<Data> data;
    };
 
    FlavorThree flavorThree;
 
    std::array<Storage &, 3> storage(flavorOne, flavorTwo, flavorThree);
 };

Storage storage;

To store some data: storage.put(data);

-----Original Message-----
From: Std-Proposals <std-proposals-bounces_at_[hidden]> On Behalf Of
Thiago Macieira via Std-Proposals
Sent: Sunday, April 5, 2026 10:04 AM
To: std-proposals_at_[hidden]
Cc: Thiago Macieira <thiago_at_[hidden]>
Subject: Re: [std-proposals] Fwd: Extension to runtime polymorphism proposed

On Saturday, 4 April 2026 23:57:02 Pacific Daylight Time Simon Schröder via
Std-Proposals wrote:
> Also, rvalues (if I’m not mistaken) go down to the IR and don’t
> optimize on the level of the AST. If your optimizations can only be
> done on the AST, this is certainly a totally different thing.
>
> Don’t just use “guaranteed semantics” as a buzz word, but actually
> describe what you want to guarantee

Muneem might be misusing "AST optimisation" term. If we put together the two
above, what he may be proposing is like what rvalue references enabled:
distinct functions that may be able to do more/different things than what
existed before. That would be a difference in the AST, because it would be a
different program altogether.

However:
a) I don't know if that's the case. There's no syntax proposed.

b) even what little I understand doesn't match the problem in question of
replacing a switch

c) I don't buy that this is worth it, because without a clear explanation of
where this solution would be used, it's impossible to judge its value

The adding of even more seemingly unrelated things into the discussion, like
virtual functions, does not help understanding what the problem is. Making
imprecise statements that can be easily refuted only muddies the problem
further.

--
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2026-04-05 17:49:41