On 2011-06-02 20:16, Mehrdad wrote: > I just thought of something: > > The patterns > > auto foo1(T)(T arg) { /+ ... +/ } > auto foo2(T...)(T args) { /+ ... +/ } > > are very common. > > > Why not just supporting the syntax > > auto foo1(auto arg) { /+ ... +/ } > auto foo2(auto args...) { /+ ... +/ } > > to make things easier? > > People can still say typeof(arg), typeof(args[0]), etc., just like > before, but it's a lot easier (and cooler!) to have a code with all > inferred types, rather than explicitly typed templates. > > Any ideas?
And what benefit would that really be? Using auto like that would have to be converted to a template anyway. It's not like a function can magically take any type for a parameter. The type must be known. Templates do that by generating a new version of the function for every new set of template parameters. auto couldn't do it without being turned into a template. And then you're just covering up the template syntax with some potentially confusing syntactic sugar. You wouldn't have any template constraints, which would mean that the error messages would be horrible. You _can't_ explicitly instantiate the template anymore if you need to, and it doesn't give you any more type inference than you do with templates. It's not even any less typing! In fact, it's exactly the same number of characters. All such a feature would do would be to hide the fact that templates were being used, and since you need to understand templates to use D properly - especially when dealing with Phobos - that doesn't help at all. I see no advantages with this idea and quite a few disadvantages. This proposal adds absolutely nothing. - Jonathan M Davis