digitalmars.D.learn - Empty Associative Aarray Literal
- Jack Stouffer (19/19) Mar 03 2016 I want to have one of the parameters on a function be optional.
- cym13 (8/27) Mar 03 2016 Use null:
- =?UTF-8?Q?Ali_=c3=87ehreli?= (4/6) Mar 03 2016 Parentheses around int[int] works though. I don't know whether it's a bu...
I want to have one of the parameters on a function be optional. The problem is, is that it's a AA and D does not seem to support empty AA literals. Observe: string func(int a, int[int] b = []) { return "mem1"; } void main() { func(1); } $ dmd test test.d(8): Error: cannot implicitly convert expression ([]) of type void[] to int[int] This doesn't work either string func(int a, int[int] b = int[int].init) { return "mem1"; } void main() { func(1); }
Mar 03 2016
On Thursday, 3 March 2016 at 22:06:54 UTC, Jack Stouffer wrote:I want to have one of the parameters on a function be optional. The problem is, is that it's a AA and D does not seem to support empty AA literals. Observe: string func(int a, int[int] b = []) { return "mem1"; } void main() { func(1); } $ dmd test test.d(8): Error: cannot implicitly convert expression ([]) of type void[] to int[int] This doesn't work either string func(int a, int[int] b = int[int].init) { return "mem1"; } void main() { func(1); }Use null: string func(int a, int[int] b = null) { return "mem1"; } void main() { func(1); }
Mar 03 2016
On 03/03/2016 02:06 PM, Jack Stouffer wrote:This doesn't work either string func(int a, int[int] b = int[int].init) {Parentheses around int[int] works though. I don't know whether it's a bug. string func(int a, int[int] b = (int[int]).init) { Ali
Mar 03 2016