Proposal: user defined attributes

Manu turkeyman at gmail.com
Fri Mar 16 08:18:43 PDT 2012


On 16 March 2012 17:14, Adam D. Ruppe <destructionator at gmail.com> wrote:

> On Friday, 16 March 2012 at 15:10:06 UTC, Manu wrote:
>
>> Interesting approach, how will that affect 'thing's type?
>>
>
> It will strictly be myAttribute!int, but alias this
> means that you can pass it anywhere an int is expected
> too (and assign ints to it all the same).
>
> Check it:
>
> void cool(int a) {}
> void main() {
>
>        myAttribute!int thing;
>        thing.refresh = true;
>
>        thing = 10; // we can assign ints to it, like if it was an int
>        assert(thing.bNeedsAttention); // should be unchanged
>
>        int a = thing; // no problem, thing is usable as an int
>        assert(a == 10);
>
>        cool(thing); // ditto
> }
>

I can see that it might work nicely in very simple cases, but it could get
nasty in complex constructs. If some template tries to take the typeof for
instance, now I'm cloning the attributes functionality too, which I don't
think is desirable...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120316/0f5fcb15/attachment-0001.html>


More information about the Digitalmars-d mailing list