Interfaces, traits, concepts, and my idea for a DIP
Tofu Ninja via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jul 29 13:26:51 PDT 2015
On Wednesday, 29 July 2015 at 14:51:52 UTC, Atila Neves wrote:
> On Wednesday, 29 July 2015 at 08:25:04 UTC, Roland Hadinger
> wrote:
>> On Tuesday, 28 July 2015 at 12:49:17 UTC, Atila Neves wrote:
>>> So... instead of having traits / concepts, what I wanted from
>>> D is to be able to do this:
>>>
>>> struct MyRange: isInputRange { ... }
>>
>> +1
>>
>>> or
>>>
>>> struct MyRange: static isInputRange { ... } // that way
>>> classes could do this too
>>
>> What about this instead:
>>
>> @satisfies(isInputRange) struct MyRange { ... }
>>
>> which is not as terse, but maybe less confusing, because
>> intuitively ':' could be mistaken to mean 'extends'.
>>
>> 'static' has too many meanings already for my taste. I really
>> don't like it when frequently used keywords are reused to mean
>> different things in slightly different places.
>
> That looks nice, but who's going to check it? UDAs have to be
> reflected on to well, do anything. At least a template mixin
> will cause a static assert to fail.
>
> Atila
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.
More information about the Digitalmars-d
mailing list