Compile-time Interfaces

Kapps Kapps at NotValidEmail.com
Sat Nov 26 17:20:46 PST 2011


On 26/11/2011 7:03 PM, Andrei Alexandrescu wrote:
> On 11/26/11 6:40 PM, Kapps wrote:
>> auto DoSomething(T)(T Data) if(isInputRange!(T)) { }
>> You could simply do:
>> auto DoSomething(Range Data) { }
>> where Range is defined as:
>> enum interface Range {
>> void popFront() const;
>> @property bool empty() const;
>> @property auto front();
>> }
>
> What's "auto" here? This thing alone pretty much destroys the idea;
> we've considered it very seriously.
>
> Andrei
>

At this point, my solutions may not be particularly useful/feasible 
because I am not experienced in compiler writing.

My thoughts though, would be that because the interface is essentially 
compile-time verification, that the interface would never truly be part 
of the class. Then, when the compiler tries to verify it implements the 
interface, it checks the signatures for static methods replacing auto 
with any type (perhaps excluding void). This way auto does not need an 
actual value for the interface, but is still transparent to the user.

But this still wouldn't solve the issue of when you have multiple types 
that should be the same value. An alias, similar to Timon's suggestion, 
could be used. Another option is something like:
@property auto front();
@property typeof(front) getAndPopFront();


More information about the Digitalmars-d mailing list