Date: Fri, 10 Apr 2026 08:26:23 -0700
On Friday, 10 April 2026 02:39:31 Pacific Daylight Time Frederick Virchanza
Gotham via Std-Proposals wrote:
> I was told to remove the inheritance, but I wasn't allowed to edit
> code beneath the indicated line. So here's what I gave them back:
...
> struct Animal {
> std::function< string(void) > name;
>
> template<typename T>
> Animal(T &&arg)
> {
> name = [&arg](void){ return arg.name(); };
> }
> };
In other words, instead of *removing* the inheritance, you reimplemented it.
It's not the C++ syntactic construct called inheritance, but it's the
semantically and logically the same thing, only implemented in user code.
Exactly like one would do inheritance in C (and Glib/GObject *do* in C).
> This got me thinking . . . . Should we have native language support for
> this?
>
> For example let's say we were to define a class with the interface that we
want:
> struct Interface {
> string name(void) const;
> string weight(void) const;
> string height(void) const;
> };
We have language support for this. It's called inheritance.
> Another nice thing about this is that we would get a very intuitive
> compiler warning if the supplied type doesn't fulfil all the criteria
> of the type-erased type -- it can clearly tell us that the supplied
> type is missing a member function that's required for the interface.
Go back to the pre-C++11 concepts proposal, in particular the concept_map
feature. There's a reason we did not add those at the time and why what we got
in C++20 is called "lightweight concepts". Please review the proposal and the
arguments why it was rejected, to see if anything has changed since.
Gotham via Std-Proposals wrote:
> I was told to remove the inheritance, but I wasn't allowed to edit
> code beneath the indicated line. So here's what I gave them back:
...
> struct Animal {
> std::function< string(void) > name;
>
> template<typename T>
> Animal(T &&arg)
> {
> name = [&arg](void){ return arg.name(); };
> }
> };
In other words, instead of *removing* the inheritance, you reimplemented it.
It's not the C++ syntactic construct called inheritance, but it's the
semantically and logically the same thing, only implemented in user code.
Exactly like one would do inheritance in C (and Glib/GObject *do* in C).
> This got me thinking . . . . Should we have native language support for
> this?
>
> For example let's say we were to define a class with the interface that we
want:
> struct Interface {
> string name(void) const;
> string weight(void) const;
> string height(void) const;
> };
We have language support for this. It's called inheritance.
> Another nice thing about this is that we would get a very intuitive
> compiler warning if the supplied type doesn't fulfil all the criteria
> of the type-erased type -- it can clearly tell us that the supplied
> type is missing a member function that's required for the interface.
Go back to the pre-C++11 concepts proposal, in particular the concept_map
feature. There's a reason we did not add those at the time and why what we got
in C++20 is called "lightweight concepts". Please review the proposal and the
arguments why it was rejected, to see if anything has changed since.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel Data Center - Platform & Sys. Eng.
Received on 2026-04-10 15:26:25
