Can You Expand Arrays into an Argument List?
surlymoor
surlymoor at cock.li
Fri May 15 22:55:34 UTC 2020
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...) {
> ... // access `args` here as an array
> }
>
> void main() {
> int[] arr = [ 1, 2, 3 ];
> add(arr);
> add(1, 2);
> add(1, 3, 4, 5, 7);
> }
>
>
> T
Unfortunately, this isn't applicable to my situation, but I'm
thankful nevertheless for the information. It would be nice if
such an expansion were more universal in its applicability, but
I'm not a language designer.
With thanks,
sm
More information about the Digitalmars-d-learn
mailing list