www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2194] New: Variadic parameters of non-array types

reply d-bugmail puremagic.com writes:
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 ...)


-- 
Jul 05 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2194






-------
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.


-- 
Jul 05 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2194







 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. --
Jul 26 2008