Interfaces, traits, concepts, and my idea for a DIP
Tofu Ninja via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jul 29 13:41:00 PDT 2015
On Wednesday, 29 July 2015 at 20:26:53 UTC, Tofu Ninja wrote:
> If you write:
>
> @satisfies!(isInputRange, MyRange) struct MyRange { ... }
>
> the UDA can check it self, it really works as expected. Which
> is why I suggested a way to get whatever the UDA is attached to
> automatically in my other post.
A UDA can reference the thing it's being attached to with no
problems.
For example, this works 100% as expected right now...
@UDA!testS struct testS // UDA fails to instantiate because testS
is not an inputRange!
{
}
template UDA(alias a)
{
import std.range;
static assert(isInputRange!a);
}
The only thing that would be needed to make this a nice solution
is some syntax sugar to automatically get whatever the UDA is
attached to, which is why I suggested this:
template UDA(alias a = __UDA_ATTACHMENT__) { ... }
More information about the Digitalmars-d
mailing list