Re: Variadic Struct Parameter

2021-01-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/12/21 2:49 PM, ryuukk_ wrote: On Tuesday, 12 January 2021 at 18:44:53 UTC, Jonathan Levi wrote: On Tuesday, 12 January 2021 at 17:46:14 UTC, Q. Schroll wrote: It's obvious why arrays work, it's the primary use case. I have no idea why classes are allowed. That classes are allowed, but stru

Re: Variadic Struct Parameter

2021-01-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 1/12/21 12:46 PM, Q. Schroll wrote: On Tuesday, 12 January 2021 at 17:26:15 UTC, Jonathan Levi wrote: Why is this not working? ``` struct S {     int x;     string y; } void fun(S s ...) { This is intended for arrays and classes, not structs. Using ... for something other than arrays and

Re: Variadic Struct Parameter

2021-01-12 Thread Q. Schroll via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 18:44:53 UTC, Jonathan Levi wrote: On Tuesday, 12 January 2021 at 17:46:14 UTC, Q. Schroll wrote: It's obvious why arrays work, it's the primary use case. I have no idea why classes are allowed. That classes are allowed, but structs are not, makes no sense to me.

Re: Variadic Struct Parameter

2021-01-12 Thread ryuukk_ via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 18:44:53 UTC, Jonathan Levi wrote: On Tuesday, 12 January 2021 at 17:46:14 UTC, Q. Schroll wrote: It's obvious why arrays work, it's the primary use case. I have no idea why classes are allowed. That classes are allowed, but structs are not, makes no sense to me.

Re: Variadic Struct Parameter

2021-01-12 Thread Ali Çehreli via Digitalmars-d-learn
On 1/12/21 10:44 AM, Jonathan Levi wrote: > why does `fun` still compile? I'm not familiar with that particular syntax, I don't know why it compiles, and I don't know why structs are different. :) However, it looks very much like the following *slice* syntax: void fun(S[] s...) { writeln

Re: Variadic Struct Parameter

2021-01-12 Thread Jonathan Levi via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 17:46:14 UTC, Q. Schroll wrote: It's obvious why arrays work, it's the primary use case. I have no idea why classes are allowed. That classes are allowed, but structs are not, makes no sense to me. I like the variadic feature for classes, but I wish it worked for

Re: Variadic Struct Parameter

2021-01-12 Thread Q. Schroll via Digitalmars-d-learn
On Tuesday, 12 January 2021 at 17:26:15 UTC, Jonathan Levi wrote: Why is this not working? ``` struct S { int x; string y; } void fun(S s ...) { This is intended for arrays and classes, not structs. Using ... for something other than arrays and c fun(S(5,"hi")); That one sho

Variadic Struct Parameter

2021-01-12 Thread Jonathan Levi via Digitalmars-d-learn
Why is this not working? ``` struct S { int x; string y; } void fun(S s ...) { writeln(s); } void main() { fun(S(5,"hi")); fun(5,"hi"); } ``` Why does `fun` compile if calling it does not?