Struct Interface Implementation?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Jun 12 18:46:09 PDT 2011


On 6/12/11 8:28 PM, Jonathan M Davis wrote:
> On 2011-06-12 18:20, Mehrdad wrote:
>> Is there any particular reason that structs and unions can't implement
>> interfaces?
>>
>> If that was possible, template conditions could become much simpler
>> for a variety of cases, such as for checking if something is a
>> particular type of range or container.
>>
>> Thoughts?
>
> They aren't virtual. For an interface to work, it has to be virtual. structs
> are value types, not reference types. They have no virtual table and have no
> polymorphism.

He must be referring to nominal conformance. It's been discussed many 
times. There are important disadvantages (e.g. you can't "implement" a 
type alias) but there are advantages too.

Ultimately we never got around to it.


Andrei


More information about the Digitalmars-d mailing list