Re: Infer function template parameters

2012-09-20 Thread Jonas Drewsen
On Thursday, 20 September 2012 at 19:56:48 UTC, Jonas Drewsen wrote: In foreach statements the type can be inferred: Clicked the send butten too early by mistake but I guess you get the idea. /Jonas

Re: Infer function template parameters

2012-09-20 Thread Peter Alexander
On Thursday, 20 September 2012 at 19:56:48 UTC, Jonas Drewsen wrote: Wouldn't it make sense to allow the same for function templates as well: What am I missing (except some code that needs chaging because only param type and not name has been specified in t? I can't see any implementation i

Re: Infer function template parameters

2012-09-20 Thread Timon Gehr
On 09/20/2012 09:57 PM, Jonas Drewsen wrote: ... What am I missing (except some code that needs chaging because only param type and not name has been specified in [i]t? Nothing, that is about it. (C backwards-compatibility could maybe be added) Of course, we could make upper case identifiers i

Re: Infer function template parameters

2012-09-20 Thread Timon Gehr
On 09/20/2012 10:52 PM, Peter Alexander wrote: On Thursday, 20 September 2012 at 19:56:48 UTC, Jonas Drewsen wrote: Wouldn't it make sense to allow the same for function templates as well: What am I missing (except some code that needs chaging because only param type and not name has been spec

Re: Infer function template parameters

2012-09-20 Thread Jonathan M Davis
On Thursday, September 20, 2012 21:57:47 Jonas Drewsen wrote: > In foreach statements the type can be inferred: > > foreach (MyFooBar fooBar; fooBars) writeln(fooBar); > same as: > foreach (foobar; fooBars) writeln(fooBar); > > This is nice and tidy. > Wouldn't it make sense to allow the same for

Re: Infer function template parameters

2012-09-21 Thread Jonas Drewsen
On Thursday, 20 September 2012 at 21:39:31 UTC, Jonathan M Davis wrote: On Thursday, September 20, 2012 21:57:47 Jonas Drewsen wrote: In foreach statements the type can be inferred: foreach (MyFooBar fooBar; fooBars) writeln(fooBar); same as: foreach (foobar; fooBars) writeln(fooBar); This is

Re: Infer function template parameters

2012-09-21 Thread deadalnix
I'll add that delegate literals already allow a similar syntax, so, for consistency reasons, this is something that make sense.

Re: Infer function template parameters

2012-09-21 Thread Jonathan M Davis
On Friday, September 21, 2012 13:14:56 Jonas Drewsen wrote: > Maybe I wasn't clear in my suggestion. The new syntax in simply a > way to define a templated function - not a non-templated one ie: > > auto foo(a,b) {} > is exactly the same as > auto foo(A,B)(A a, B b) {} So all it does is save you

Re: Infer function template parameters

2012-09-21 Thread Peter Alexander
On Thursday, 20 September 2012 at 21:04:15 UTC, Timon Gehr wrote: On 09/20/2012 10:52 PM, Peter Alexander wrote: Like it or not, templates still cause a lot of code bloat, complicate linking, cannot be virtual, increase compilation resources, and generate difficult to understand messages. They

Re: Infer function template parameters

2012-09-21 Thread Steven Schveighoffer
On Thu, 20 Sep 2012 15:57:47 -0400, Jonas Drewsen wrote: In foreach statements the type can be inferred: foreach (MyFooBar fooBar; fooBars) writeln(fooBar); same as: foreach (foobar; fooBars) writeln(fooBar); This is nice and tidy. Wouldn't it make sense to allow the same for function templ

Re: Infer function template parameters

2012-09-21 Thread jerro
Although I like it, I wonder if it works in D's context free grammar. Timon probably would know best... I came up with this code, which compiles today: import std.stdio; alias int x; void foo(x) {} void foo2(string x) {writeln(x);} void main() { foo(1); foo2("hello"); } Under your

Re: Infer function template parameters

2012-09-21 Thread Jonas Drewsen
On Friday, 21 September 2012 at 11:40:54 UTC, Jonathan M Davis wrote: On Friday, September 21, 2012 13:14:56 Jonas Drewsen wrote: Maybe I wasn't clear in my suggestion. The new syntax in simply a way to define a templated function - not a non-templated one ie: auto foo(a,b) {} is exactly the

Re: Infer function template parameters

2012-09-21 Thread Jonas Drewsen
On Friday, 21 September 2012 at 15:04:14 UTC, Steven Schveighoffer wrote: On Thu, 20 Sep 2012 15:57:47 -0400, Jonas Drewsen wrote: In foreach statements the type can be inferred: foreach (MyFooBar fooBar; fooBars) writeln(fooBar); same as: foreach (foobar; fooBars) writeln(fooBar); This is

Re: Infer function template parameters

2012-09-22 Thread Simen Kjaeraas
On 2012-09-21, 21:29, Jonas Drewsen wrote: A mentioned in the proposal (albeit not very clear) it requires non-templated function definitions to include both type and param names. If only one name is provided in a definition is always a param name. Unfortunately this is a breaking change fo

Re: Infer function template parameters

2012-09-24 Thread Jonas Drewsen
On Saturday, 22 September 2012 at 07:48:14 UTC, Simen Kjaeraas wrote: On 2012-09-21, 21:29, Jonas Drewsen wrote: A mentioned in the proposal (albeit not very clear) it requires non-templated function definitions to include both type and param names. If only one name is provided in a definitio

Re: Infer function template parameters

2012-09-24 Thread Jonathan M Davis
On Monday, September 24, 2012 10:37:04 Jonas Drewsen wrote: > On Saturday, 22 September 2012 at 07:48:14 UTC, Simen Kjaeraas > > wrote: > > On 2012-09-21, 21:29, Jonas Drewsen wrote: > >> A mentioned in the proposal (albeit not very clear) it > >> requires non-templated function definitions to inc

Re: Infer function template parameters

2012-09-24 Thread Jonas Drewsen
On Monday, 24 September 2012 at 10:05:49 UTC, Jonathan M Davis wrote: On Monday, September 24, 2012 10:37:04 Jonas Drewsen wrote: On Saturday, 22 September 2012 at 07:48:14 UTC, Simen Kjaeraas wrote: > On 2012-09-21, 21:29, Jonas Drewsen wrote: >> A mentioned in the proposal (albeit not very cl

Re: Infer function template parameters

2012-09-24 Thread Jonathan M Davis
On Monday, September 24, 2012 19:18:09 Jonas Drewsen wrote: > What about: > > int fun() { > return (0, "abc")[0]; > } > > in the comma operator case it would return 'a' as an int. > in the tuple case it would return 0 Like I said, I'd have to examine the situation more closely to be certain that