Thread overview
auto in function signature for defaulted arguments?
Jun 27, 2013
bearophile
Jun 27, 2013
Andrej Mitrovic
Jun 27, 2013
bearophile
Jun 27, 2013
Andrej Mitrovic
June 27, 2013
Sometimes I have code like this:

struct VeryLongNamedStruct {}
void foo(in VeryLongNamedStruct x = VeryLongNamedStruct(1)) {}
void main() {}

Or even:

void bar(in TupleFoo x = TupleFoo(TupleBar(2), TupleSpam(3))) {}

So is it a good idea to allow "auto" in the function signature for the arguments that have a default value?

void foo(in auto x = VeryLongNamedStruct(1)) {}

Bye,
bearophile
June 27, 2013
On 6/27/13, bearophile <bearophileHUGS@lycos.com> wrote:
> So is it a good idea to allow "auto" in the function signature for the arguments that have a default value?
>
> void foo(in auto x = VeryLongNamedStruct(1)) {}

I've wanted this too once. Although there's a tradeoff here, now the user has to work more to figure out what type it can pass to the foo function. On the other hand it could be useful in non-public and generic code.
June 27, 2013
Andrej Mitrovic:

> On the other hand it could be useful in non-public and generic code.

Do you have a realistic use case for generic code?

Bye,
bearophile
June 27, 2013
On 6/27/13, bearophile <bearophileHUGS@lycos.com> wrote:
>> On the other hand it could be useful in non-public and generic code.
>
> Do you have a realistic use case for generic code?

No, I'm just speaking out loud about the possibility.