Feature request - simpler constructors
Matti Niemenmaa
see_signature at for.real.address
Thu Sep 20 08:29:59 PDT 2007
Derek Parnell wrote:
> On Thu, 20 Sep 2007 11:05:40 +0100, Janice Caron wrote:
>
>> Please could we let
>>
>> this(auto n) {}
>> T n;
>>
>> be syntactic sugar for
>>
>> this(T n)
>> {
>> this.n = n;
>> }
>> T n;
>
> This looks exactly like a problem that AST macros could solve. This is only
> one example of a more generic construct, in which the code writer lists a
> set of names and each name is used to create an assignment from one
> variable to another variable whose name is based on the target variable's
> name.
What if you have a constructor in which you don't want some of the variables to
be automatically assigned? I.e.:
this(int a, auto x, auto y, auto z, int b) {
// code which handles a and b
}
You could, of course, write a simple macro within the constructor which
automatically does "this.x = x; this.y = y; this.z = z;" but you're losing the
main advantage (in my eyes), which is that the types of the variables need to be
specified only once.
--
E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi
More information about the Digitalmars-d
mailing list