Proposal: user defined attributes
Adam D. Ruppe
destructionator at gmail.com
Fri Mar 16 08:14:35 PDT 2012
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
}
More information about the Digitalmars-d
mailing list