Compile-time Interfaces
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sun Nov 27 07:47:11 PST 2011
On 11/27/11 5:36 AM, Jacob Carlborg wrote:
> "auto" cannot be used here. Just like it can't be used in any place
> where there is no implementation of a function.
>
> Seems to me it needs to look something like this:
>
> enum interface Range (T)
> {
> void popFront();
> @property bool empty() const;
> @property T front();
> }
That seems helpful, but it doesn't lead on a good path, for several reasons.
1. Right now we have "function applies to any type R that is a range".
With the other approach, there'd be "function applies to any type T such
that the given type R is a Range!T". That roundabout approach is likely
to scale poorly to more complex cases. It's arguably inferior because
often the range-ness is of interest, not naming T.
2. Restrictions can be any Boolean expression, whereas interfaces only
apply to types.
3. In an interface-based approach, everything must be named; there are
no optional properties such as hasLength or isInfinite. That could, of
course, be added as restricted templates, which means interfaces must
coexist with restricted templates, a more powerful feature. So in the
end interfaces are redundant.
Andrei
More information about the Digitalmars-d
mailing list