digitalmars.D - auto type for defaulted arguments? [Repost]
- bearophile (17/17) Jun 27 2013 (This is an extended repost of a message that I have put in
- Maxim Fomin (3/20) Jun 27 2013 Alias supposed to be used for such cases, but auto can be used in
- Nick Sabalausky (5/27) Jun 27 2013 I've noticed a need for that, too.
- Maxim Fomin (3/6) Jun 27 2013 Actually I meant "dmd does not support the feature now, but I see
- bearophile (9/9) Jun 29 2013 In the meantime I have opened an enhancement request:
(This is an extended repost of a message that I have put in D.learn.) 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))) {} In those cases something I'd like to use "auto" in the function signature for the arguments that have a default value: void foo(in auto x = VeryLongNamedStruct(1)) {} Do you like? Is it safe enough? Is it useful enough? Is it too much work to implement? A bit more complex case: void spam(T)(const x = Foo!T(4)) {} Bye, bearophile
Jun 27 2013
On Thursday, 27 June 2013 at 17:42:14 UTC, bearophile wrote:(This is an extended repost of a message that I have put in D.learn.) 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))) {} In those cases something I'd like to use "auto" in the function signature for the arguments that have a default value: void foo(in auto x = VeryLongNamedStruct(1)) {} Do you like? Is it safe enough? Is it useful enough? Is it too much work to implement? A bit more complex case: void spam(T)(const x = Foo!T(4)) {} Bye, bearophileAlias supposed to be used for such cases, but auto can be used in paramenters too.
Jun 27 2013
On Thu, 27 Jun 2013 19:58:58 +0200 "Maxim Fomin" <maxim maxim-fomin.ru> wrote:On Thursday, 27 June 2013 at 17:42:14 UTC, bearophile wrote:I've noticed a need for that, too.(This is an extended repost of a message that I have put in D.learn.) 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))) {} In those cases something I'd like to use "auto" in the function signature for the arguments that have a default value: void foo(in auto x = VeryLongNamedStruct(1)) {} Do you like? Is it safe enough? Is it useful enough? Is it too much work to implement?but auto can be used in paramenters too.It can? Cool!
Jun 27 2013
On Thursday, 27 June 2013 at 20:24:46 UTC, Nick Sabalausky wrote:Actually I meant "dmd does not support the feature now, but I see no reason for not supporting it".but auto can be used in paramenters too.It can? Cool!
Jun 27 2013
In the meantime I have opened an enhancement request: http://d.puremagic.com/issues/show_bug.cgi?id=10491 Henning Pohl has written a patch: https://github.com/D-Programming-Language/dmd/pull/2270 And Kenji has written some comments in Bugzilla, explaining why he doesn't like this ER. I usually trust Kenji judgement. So let's close down this idea? Bye, bearophile
Jun 29 2013