On Thursday, 17 July 2014 at 22:52:37 UTC, Justin Whear wrote:
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);

This is sufficient, but not adequate. Just as the built-in
unittest blocks with assertions, it's great when the assertion is
true but good luck finding out where the bug is when it's not.

The D Cookbook has an idiom to handle this by checking for __ctfe
but it's super hacky and there should be a better way.

I have lost count of how many times I wish the compiler would
help me with compile time interfaces as it does with runtime
code. static override and static interface? Yes please.

Atila

Reply via email to