static interface

Jesse Phillips jessekphillips+D at gamil.com
Mon Nov 16 16:14:03 PST 2009


Leandro Lucarella Wrote:

> 
> The problem is "regular" interfaces provide dynamic dispatch. Andrei could
> implement all the range stuff using interfaces, but that would mean:
> 1) You have to inherit from the interface (i.e., you can't use arrays)
> 2) All calls to ranges functions are virtual (inefficient; this is
>    particularly relevant since they are called inside loops => lot of
>    times)
> 
> A static interface don't have those problems, and I don't see a way to mix
> static and dynamic interfaces without introducing a "new" type of
> interfaces (static interface).

I realize that a class that inherits an interface would have these issues, but if you aren't required to inherit the interface and the use of interface in a function parameter constitutes a compile-time check instead of inheritance check...

But this does bring up the question in your suggestion the following code couldn't compile, but based on the signature it looks like it should:

size_t walkLength(InputRange range, size_t upTo = size_t.max)
{
        InputRange temp = range;
        // implementation
}

I only know enough about the inner workings of compiling Classes to be able to follow explanation why my ideas won't work. This could give a very clear compiler error, but just doesn't appear wrong outside of that.



More information about the Digitalmars-d mailing list