Re: Can You Expand Arrays into an Argument List?

2020-05-15 Thread surlymoor via Digitalmars-d-learn
On Friday, 15 May 2020 at 19:19:59 UTC, H. S. Teoh wrote: It's possible to do it, but the called function has to support it. If that's not an option, then you're out of luck and probably have to use metaprogramming instead. Here's how to do it: int add(int[] args...) {

Re: Can You Expand Arrays into an Argument List?

2020-05-15 Thread Dennis via Digitalmars-d-learn
On Friday, 15 May 2020 at 19:19:59 UTC, H. S. Teoh wrote: Here's how to do it: int add(int[] args...) { ... // access `args` here as an array } Beware that that language feature, typesafe variadic functions, might become deprecated:

Re: Can You Expand Arrays into an Argument List?

2020-05-15 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 15, 2020 at 06:44:52PM +, surlymoor via Digitalmars-d-learn wrote: [...] > I don't often miss JS, but one particular feature that I enjoyed is > the ability to expand arrays into argument lists using a unary > operator. > > Example: add(...[1, 1]) === add(1, 1) // IIRC > > I've

Can You Expand Arrays into an Argument List?

2020-05-15 Thread surlymoor via Digitalmars-d-learn
Hello, I don't often miss JS, but one particular feature that I enjoyed is the ability to expand arrays into argument lists using a unary operator. Example: add(...[1, 1]) === add(1, 1) // IIRC I've been looking in Phobos and the spec, but nothing's popped out to me. Is there a fairly