Thread overview |
---|
July 05, 2008 [Issue 2194] New: Variadic parameters of non-array types | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=2194 Summary: Variadic parameters of non-array types Product: D Version: 2.013 Platform: PC OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: brunodomedeiros+bugz@gmail.com D accepts variadic parameters that are not array types, such as this: void foo(int bar ...) However this does not make much sense, since the bar parameter is not variadic, the function can only be called with one argument. To avoid confusion, it would be an improvement to disallow non-array parameter types as variadic parameters. An alternatice sugestion, would be for any variadic parameter to automatically become of the array type of the type declared in the signature. Such that in: void foo(int bar ...) then typeof(bar) becomes int[]. This behavior would be identical to Java. Also it would allow a further improvement, a more consistent syntax for lazy variadic templates, like this: void foo(lazy int bar ...) where typeof(bar) would be int delegate()[] And we would no longer need the awkward special case where variadic arguments can be converted to delegates, such as with this: void cond(bool delegate()[] cases ...) -- |
July 05, 2008 [Issue 2194] Variadic parameters of non-array types | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2194 ------- Comment #1 from matti.niemenmaa+dbugzilla@iki.fi 2008-07-05 14:06 ------- The advantage is that, given: class C { int a, b, c; } void foo(C c...) {} You can call either: foo(new C(1, 2, 3)); foo(1, 2, 3); For primitive types it is indeed useless, though. -- |
July 26, 2008 [Issue 2194] Variadic parameters of non-array types | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/issues/show_bug.cgi?id=2194 ------- Comment #2 from brunodomedeiros+bugz@gmail.com 2008-07-26 06:06 ------- (In reply to comment #1) > The advantage is that, given: > class C { int a, b, c; } > void foo(C c...) {} > You can call either: > foo(new C(1, 2, 3)); > foo(1, 2, 3); > For primitive types it is indeed useless, though. I see. Well then, it becomes an issue of which alternative is better. I still prefer the first one, as I think it's cleaner. -- |
Copyright © 1999-2021 by the D Language Foundation