On Friday, 5 October 2012 at 12:01:30 UTC, Piotr Szturmaj wrote:
Java and C# with their generics can do the following:

class List { }
class List<T> { }

List list = new List();
List<int> intList = new List<int>();

In D similar code can't work because we can't have both a type and a template with the same name. So this code must be rewritten to:

class List(T = Variant) { }

List!() list = new List!();
List!int intList = new List!int;

When template name is used as a type and it can be instantiated with no parameters it could be automatically rewritten to List!() by the compiler. That code would then look like this:

List list = new List;
List!int intList = new List!int;

The question is... is it possible to change D's behaviour to avoid awkward !() template parameters _without_ breaking backward compatibility?

Why to you need this?

Java and C# only allow this type of code due to backwards compatibility, because their first version did not allow for generics, and their creators did not want to force everyone to recode their code bases.

--
Paulo

Reply via email to