Andrei's interface requests
Christopher Wright
dhasenan at gmail.com
Fri Apr 3 13:43:45 PDT 2009
Andrei has put up a few enhancement requests in the bugzilla:
http://d.puremagic.com/issues/show_bug.cgi?id=2784
http://d.puremagic.com/issues/show_bug.cgi?id=2785
http://d.puremagic.com/issues/show_bug.cgi?id=2786
These are intended to change interfaces from being solely a tool of
polymorphism into a way of specifying type constraints. The additions
recommended can only be used at compile time (constructors, static
functions, and nested types).
I grant that it would be quicker and clearer to write:
interface Foo
{
static void stuff();
this (int);
}
template Template(Arg : Foo) {}
than to write:
template Template(Arg) if (is (typeof (new Arg(0)) &&
isStaticFunction!(Arg, "stuff")) {}
However, I'm not sure whether this would be used much at all, and it
deserves some discussion.
One detail of #2785 seems problematic:
interface Foo
{
extern void bar(int, Foo, double);
}
meaning that a non-member function bar should exist that accepts an int,
*the implementor of Foo*, and a double.
This is a huge and silent divergence from the standard meaning of using
the interface name; it would allow:
class C : Foo
{
static void bar(int, C, double);
}
and disallow:
class C : Foo
{
static void bar(int, Foo, double);
}
Thoughts? Any concerns that I have not raised? I don't do sufficient
metaprogramming to find any of this useful, I admit.
More information about the Digitalmars-d
mailing list