On Tuesday, 28 July 2015 at 13:23:37 UTC, Daniel Kozák wrote:

I was thinking about same many times before. With one difference:

instead of this:
struct MyRange: isInputRange { ... }

I would use something like this:

@interface(InputRange, ...)
struct MyRange { ... }


@interface(InputRange, ...)
class MyClassRange { ... }

I have actually thought about this as well, and a thing that could actually make this possible is if UDAs could get the thing they are attached to. I realized it could be done easily when I saw that this worked:

template someuda(alias attach) {}
@someuda!(x) int x;

someuda can even inspect x and see itself attached to it, pretty cool. Only thing that would be needed to make it seamless is a for a new default arg value identifier like __FILE__ that just translates to whatever the UDA is attached to. I would call it __UDA_ATTACHMENT__. So the above would be translated to:


template someuda(alias attach = __UDA_ATTACHMENT__) {}
@someuda!() int x;


The parens would sadly still be necessary, but then you could do:

import std.range.interfaces;

template StaticInterface(alias Iface, alias attach = __UDA_ATTACHMENT__)
     if(is(Iface == interface))
{
     // See if attach statically implements Iface
}

@StaticInterface!(InputRange)
struct someRange {...}


Reply via email to