On Monday, 13 October 2014 at 19:18:39 UTC, Walter Bright wrote:
Nothing requires function overloads to use the same names in
the same order for parameters. "color" can be the name for
parameter 1 in one overload and for parameter 3 in another and
not be there at all for a third.
Parameters need not be named in D:
int foo(long);
int foo(ulong x);
Named parameters are often desired so that default arguments
need not be in order at the end:
int foo(int x = 5, int y);
int foo(int y, int z);
To deal with all this, a number of arbitrary rules will have to
be created. Overloading is already fairly complex, with the
implemented notions of partial ordering. Even if this could all
be settled, is it worth it? Can anyone write a document
explaining this to people? Do people really want pages and
pages of specification for this?
If you have several functions that take optional arguments, like
the following:
int foo(bool b = false, int n, float f = 0.0f);
int foo(float n, bool b = false, float f = 0.0f);
foo(2, b: true);
foo(3.0f, f: 1.0f);
Wouldn't it only be necessary to overload on the non-optional
arguments? Extending this, if a functional has only optional
arguments, then there can only be one version of it.
int foo(int n = 0, bool b = false, float f = 0.0f);
//Error: cannot overload two functions with no non-optional
parameters.
int foo(float n = 0.0f, bool b = false, float f = 0.0f);