Static override?
Artur Skawina
art.08.09 at gmail.com
Fri Apr 4 03:55:25 PDT 2014
On 04/04/14 11:22, Atila Neves wrote:
> enum hasAccept(T) = is(typeof(() {
> auto s = T();
> auto foo = FooVisitor();
> s.accept(foo);
> auto bar = BarVisitor();
> s.accept(bar);
> }));
> The static asserts are there to verify that the structs I define actually do implement the interface I want them to. Which is great when they work, but tricky to find out why they don't when the assert fails.
template hasAccept(T) {
static iface(CT)(CT t) {
auto foo = FooVisitor();
t.accept(foo);
auto bar = BarVisitor();
t.accept(bar);
}
static if (is(typeof(iface!T)))
enum hasAccept = true;
else
enum hasAccept = &iface!T;
}
[Should probably be split into three parts: 1) the if-definition, 2) the
does-T-implement-the-if check, and 3) the T-must-implement-the-if assertion.]
artur
More information about the Digitalmars-d
mailing list