Typesafe variadic argument taking struct

Satoshi via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Oct 20 09:30:37 PDT 2016


On Thursday, 20 October 2016 at 16:04:00 UTC, Nordlöw wrote:
> On Thursday, 20 October 2016 at 12:48:34 UTC, Satoshi wrote:
>> Hello,
>> why ... cannot be used with structs?
>>
>> struct Foo {
>>     this(int a) { }
>> }
>>
>> void bar(Foo foo...) {
>>
>> }
>>
>> bar(42);
>
> Being explicit about these things makes complex code more clear.

With class it works fine.
https://dlang.org/spec/function.html#typesafe_variadic_functions

I have struct Point(x, y) and I want to let the people call some 
methods with Point or just pass x and y argument. I can make 
Point as a class but it's not efficient.

I think this
void moveMouseTo(float x, float y);
is same clear as
void moveMouseTo(Point point);


More information about the Digitalmars-d-learn mailing list