member arguments in D?

Nick Sabalausky a at a.a
Sun Apr 26 02:00:00 PDT 2009


"Daniel Keep" <daniel.keep.lists at gmail.com> wrote in message 
news:gt159p$1bq0$1 at digitalmars.com...
>
>
> Penguin wrote:
>> What do you think about:
>>
>> class Foo {
>>
>>    int a;
>>    float b;
>>
>>    this( member a, member b ) {
>>
>>    }
>>
>> }
>>
>> instead of:
>>
>> class Foo {
>>
>>    int a;
>>    float b;
>>
>>    this( int a, float b ) {
>>       this.a = a;
>>       this.b = b;
>>    }
>>
>> }
>
> I don't know that saving a few (very simple) lines of code is worth
> adding a new keyword and magic behaviour to ctor arguments.
>
> If you really wanted to just do that, you could probably write a mixin
> to take care of it.
>

I just happen to already have such a thing in my bag-o-tricks. See 
attachment.

Usage:
----
mixin(initMember!(someVar));
mixin(initMember!(a, b, c));
----

Turns Into:
----
this.someVar = someVar;
this.a = a;
this.b = b;
this.c = c;
----


begin 666 initMember.d
M:6UP;W)T('1A;F=O+F-O<F4N5')A:71S.PT*#0HO*BH-"E5S969U;"!I;B!C
M;VYS=')U8W1O<G, at 9F]R($1262X-"@T*57-A9V4Z#0HM+2TM#0IM:7AI;BAI
M;FET365M8F5R(2AS;VUE5F%R*2D[#0IM:7AI;BAI;FET365M8F5R(2AA+"!B
M+"!C*2D[#0HM+2TM#0H-"E1U<FYS($EN=&\Z#0HM+2TM#0IT:&ES+G-O;656
M87(@/2!S;VUE5F%R.PT*=&AI<RYA(#T at 83L-"G1H:7,N8B ](&([#0IT:&ES
M+F,@/2!C.PT*+2TM+0T**B\-"G1E;7!L871E(&EN:71-96UB97(H=F%R:6%B
M;&5S+BXN*0T*>PT*"6-O;G-T(&-H87);72!I;FET365M8F5R(#T at 7VEN:71-
M96UB97)&<F]M(2 at B(BP@=F%R:6%B;&5S*3L-"@DO+W!R86=M82AM<V<L(")I
M;FET365M8F5R.B B('X@:6YI=$UE;6)E<BD[#0I]#0H-"B\J*@T*57-E9G5L
M(&EN(&-O<'D at 8V]N<W1R=6-T;W)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;6)E<D9R;VT@/2 B(CL-"@EE;'-E#0H)>PT*"0EC;VYS="!C:&%R6UT at 7VEN
M:71-96UB97)&<F]M(#T-"@D)"2)T:&ES+B)^=F%R:6%B;&5S6S!=+G-T<FEN
M9V]F?B(@/2 B?F9R;VU^=F%R:6%B;&5S6S!=+G-T<FEN9V]F?B([7&XB#0H)
M"0E^(%]I;FET365M8F5R1G)O;2$H9G)O;2P@=F%R:6%B;&5S6S$N+B1=*3L-
M"B\O"0EP<F%G;6$H;7-G+" B7VEN:71-96UB97)&<F]M.EQN(B!^(%]I;FET
5365M8F5R1G)O;2D[#0H)?0T*?0T*
`
end




More information about the Digitalmars-d mailing list