Specialization - Major hole in the spec?

Trass3r un at known.com
Thu Jan 5 16:03:37 PST 2012


On Thursday, 5 January 2012 at 23:11:31 UTC, Peter Alexander 
wrote:
> http://dlang.org/templates-revisited.html
>
> ------------------------------------------------------------------------
> Each can have default values, and type parameters can have (a 
> limited form of) constraints:
>
> class B { ... }
> interface I { ... }
>
> class Foo(
>  R,            // R can be any type
>  P:P*,         // P must be a pointer type
>  T:int,        // T must be int type
>  S:T*,         // S must be pointer to T

Hmm that's tricky. On the one hand the above doesn't make sense. 
If : is indeed just a constraint and it was supposed to mean _no 
implicit conversions_ you could just leave T out and replace it 
with int in the first place.
On the other hand if you want to implement C++-like 
specialization you probably need explicit types.
Both issues could still be solved either way with the use of 
template constraints.

However, I think it's correct to have : mean implicit conversion.
1. it's a bit more consistent with is expressions.
2. you can always use overloading of non-template and template 
functions which is much clearer anyway (resp. for now use the 
workaround Sean mentioned: void foo()(int* t)).


More information about the Digitalmars-d mailing list