www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - auto in function signature for defaulted arguments?

reply "bearophile" <bearophileHUGS lycos.com> writes:
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
Jun 27 2013
parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
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.
Jun 27 2013
parent reply "bearophile" <bearophileHUGS lycos.com> writes:
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
Jun 27 2013
parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
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.
Jun 27 2013