structs inheriting from and implementing interfaces

rikki cattermole rikki at cattermole.co.nz
Fri Dec 29 13:08:38 UTC 2017


On 29/12/2017 12:59 PM, rjframe wrote:
> On Fri, 29 Dec 2017 12:39:25 +0000, Nicholas Wilson wrote:
> 
>> On Friday, 29 December 2017 at 12:03:59 UTC, Mike Franklin wrote:
>>
>> The problem is that interfaces are a runtime thing (e.g. you can cast a
>> class to an interface)
>> structs implement compile time interfaces via template duck typing
>> (usually enforced via an if()).
>> you could probably write a wrapper that introspected an interface and
>> enforced that all members were implemented.
> 
> I've actually thought about doing this to get rid of a bunch of if
> qualifiers in my function declarations. `static interface {}` compiles but
> doesn't [currently] seem to mean anything to the compiler, but could be a
> hint to the programmer that nothing will directly implement it; it's a
> compile-time interface. This would provide a more generic way of doing
> stuff like `isInputRange`, etc.

Or we could get signatures, which are even better still!



More information about the Digitalmars-d-learn mailing list