Pretty please: Named arguments
KennyTM~
kennytm at gmail.com
Mon Feb 28 14:28:32 PST 2011
On Mar 1, 11 05:04, Simen kjaeraas wrote:
> Adam Ruppe <destructionator at gmail.com> wrote:
>
>> Another alternative is to give each element their own struct...
>>
>> struct Width { int width; alias width this; }
>>
>> foo(Width(10), Height(20));
>
> Clearly this can be done better:
>
> struct _(string s) { int data; alias data this; }
>
> foo(_!"width"(10), _!"height"(20));
>
How are these better than
foo(/*width*/ 10, /*height*/ 20);
? One advantage of named parameter is the compiler can verify you've
passed in the correct order, and all these alternatives cannot.
More information about the Digitalmars-d
mailing list