digitalmars.D - Allow auto in function parameters with default arguments?
- Andrej Mitrovic (11/11) Sep 09 2012 It occurred to me that using a parameter with a default value that is
- Timon Gehr (5/16) Sep 10 2012 As parameter names are optional, foo is parsed as the parameter type in
- Andrej Mitrovic (2/4) Sep 10 2012 Yeah but it's repetitive. typeof(exp) arg = exp;
- Mehrdad (1/1) Sep 10 2012 http://forum.dlang.org/thread/is9jmn$2ia5$1@digitalmars.com
- Artur Skawina (7/8) Sep 11 2012 Completely different issue. That one is about syntax sugar for template
It occurred to me that using a parameter with a default value that is a function call could benefit from using auto: struct Foo(T) { } auto getFoo() { return Foo!int(); } void func(int x, auto foo = getFoo()) { } Granted this is a simple case and might be overkill, but if the function returns some complicated range type (or worse, a Voldemort type) it might be hard or impossible to specify the type.
Sep 09 2012
On 09/10/2012 06:20 AM, Andrej Mitrovic wrote:It occurred to me that using a parameter with a default value that is a function call could benefit from using auto: struct Foo(T) { } auto getFoo() { return Foo!int(); } void func(int x, auto foo = getFoo()) { } Granted this is a simple case and might be overkill,As parameter names are optional, foo is parsed as the parameter type in this case. What exact change do you propose?but if the function returns some complicated range type (or worse, a Voldemort type) it might be hard or impossible to specify the type.Every type that you can get hold of a value of can be specified by the means of typeof.
Sep 10 2012
On 9/10/12, Timon Gehr <timon.gehr gmx.ch> wrote:Every type that you can get hold of a value of can be specified by the means of typeof.Yeah but it's repetitive. typeof(exp) arg = exp;
Sep 10 2012
http://forum.dlang.org/thread/is9jmn$2ia5$1 digitalmars.com
Sep 10 2012
On 09/11/12 08:21, Mehrdad wrote:http://forum.dlang.org/thread/is9jmn$2ia5$1 digitalmars.comCompletely different issue. That one is about syntax sugar for template functions, while this one would just save the programmer some typing when declaring "normal" functions (by propagating the type of the default argument expression, which would make it possible to skip the redundant 'typeof(expr)' part). artur
Sep 11 2012