October 19, 2014
I have something like this for mixin interfaces that require that the host struct support certain semantics. There's a Traits struct (concept-ish) that takes a set of strings for trait identifiers and their definitions (which is some code that compiles if and only if the trait is satisfied).

The Traits struct has a member mixin template, "require", which can be used by the interface that instantiated the Traits. When one of the mixed-in requirements is failed, the compiler generates an error message like this:

source/evx/meta/traits/generator.d-mixin-49(50): Error: static assert  "MyStruct must support {size_t x = buffer.length;} to enable TransferOps."

Not as nice as a compiler-aided concept solution but I have been pretty happy with it so far. It doesn't take me long to forget what some interface requirements are, and this way the compiler can explicitly guide me.
1 2
Next ›   Last »