How to fix "typesafe variadic function parameter"?

2022-05-24 Thread Andrey Zherikov via Digitalmars-d-learn
How to fix this? ```d struct S { string[] s; } auto foo(string[] s...) // Error: typesafe variadic function parameter `s` of type `string[]` cannot be marked `return` { return S(s); } void main() { import std.stdio: writeln; writeln(foo("Hello D")); } ``` Th

Re: How to fix "typesafe variadic function parameter"?

2022-05-24 Thread Adam Ruppe via Digitalmars-d-learn
On Tuesday, 24 May 2022 at 22:46:55 UTC, Andrey Zherikov wrote: return S(s); return S(s.dup); The variadic lives in a temporary array that expires at the end of the function. So copying it out to the GC lets it live on. Your code was wrong on 2.099 too, but the compiler didn't tell

Re: How to fix "typesafe variadic function parameter"?

2022-05-24 Thread Andrey Zherikov via Digitalmars-d-learn
On Tuesday, 24 May 2022 at 22:51:50 UTC, Adam Ruppe wrote: On Tuesday, 24 May 2022 at 22:46:55 UTC, Andrey Zherikov wrote: return S(s); return S(s.dup); The variadic lives in a temporary array that expires at the end of the function. So copying it out to the GC lets it live on. Yo

Re: How to fix "typesafe variadic function parameter"?

2022-05-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/24/22 6:54 PM, Andrey Zherikov wrote: On Tuesday, 24 May 2022 at 22:51:50 UTC, Adam Ruppe wrote: On Tuesday, 24 May 2022 at 22:46:55 UTC, Andrey Zherikov wrote: return S(s); return S(s.dup); The variadic lives in a temporary array that expires at the end of the function. So copyin