dropping parentheses on template instantiation
Sean Kelly
sean at invisibleduck.org
Sun Oct 5 12:49:20 PDT 2008
Andrei Alexandrescu wrote:
> Sean Kelly wrote:
>> Andrei Alexandrescu wrote:
>>> I just realized something different. After making an informal review
>>> of some code, I saw that a large percentage of template
>>> instantiations only need ONE argument.
>>>
>>> This makes me think, with the old "!" notation, parentheses could be
>>> dropped entirely without prejudice:
>>>
>>> auto covariance = Matrix!real(n, n);
>>> auto normalized = SparseVector!double(n);
>>>
>>> and so on.
>>>
>>> To the unbridled joy of the enemies of the Sad Pirate, the dot won't
>>> work for template instantiation because without the parentheses it
>>> DOES engender ambiguity.
>>>
>>> Now say we take the following route:
>>>
>>> 1) We find something different from shouting
>>>
>>> 2) We drop the parentheses for 1 argument
>>
>> It's a bit off-topic, but why are we required to supply an empty
>> template list when instantiating a type that has all defaulted
>> template arguments? ie.
>>
>> class C( T = int, U = int ) {}
>>
>> auto c = new C!();
>> auto d = new C; // why can't it be this?
>>
>> I asked about this a while back but never got an answer.
>
> I'd love that. I think there's ambiguity here:
>
> struct A(T = int)
> {
> void foo()
> {
> auto x = new A;
> }
> }
>
> A at double whatever;
> whatever.foo;
>
> Will x be A at int or A at double?
Darnit, you're right. And I'm not sure I like the idea of making this
behavior context-sensitive.
> P.S. Boy I like the "at". Down with the shouting!
You really hate '!', don't you? ;-)
Sean
More information about the Digitalmars-d
mailing list