higher-order funcs for ranges (with usual interface)

Torarin torarind at gmail.com
Mon Feb 7 04:07:12 PST 2011


If you want to use an interface as a concept, you can take kenji's
adaptTo module and add this:

template conformsTo(T, Interfaces...)
{
 enum conformsTo = AdaptTo!Interfaces.hasRequiredMethods!T;
}

and use it like this

void draw(T)(T shape) if (conformsTo!(T, Shape, Drawable))

This will of course only work for methods, not properties or aliases,
so you still need constraints in some cases.

Torarin


More information about the Digitalmars-d-learn mailing list