Paulo Pinto wrote:
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?

For convenience. In the above example, List without parameters could handle any value (as Variant), but I can always specialize it for some type. List (which would be List!()) would then become a shortcut to List!Variant.

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.

Yes, but it's more convenient to write List than List<Object>. And in D: List vs List!().

Reply via email to