Compile-Time Interfaces (Concepts)

Justin Whear via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 17 15:52:37 PDT 2014


On Thu, 17 Jul 2014 22:49:30 +0000, Nordlöw wrote:

> AFAIK there is no compile-time variant of interfaces right?
> 
> Why is that?
> 
> Wouldn't it be nice to say something like
> 
>      struct SomeRange realize InputRange {
>          /* implement members of InputRange */
>      }
> 
> and then the compiler will statically check that that all members are
> implemented correctly.
> 
> I guess this requires some new syntax to describe what an InputRange is.
> 
> Kind of like C++ Concepts.

What benefits would accrue from adding this?  Static verification that a 
structure implements the specified concepts?  If so, you can simply do 
this instead:

static assert(isInputRange!SomeRange);


More information about the Digitalmars-d-learn mailing list