Two cases showing imperfection of the const system

Timon Gehr timon.gehr at gmx.ch
Thu Feb 16 15:39:44 PST 2012


On 02/17/2012 12:36 AM, Timon Gehr wrote:
> On 02/17/2012 12:08 AM, James Miller wrote:
>>> The first problem is trivial, solving the second one in a type safe way
>>> would require adding parametric polymorphism to D. (Which I'd love to
>>> have!)
>>>
>>
>> Can't you emulate type-safe parametric polymorphism with template
>> constraints?
>
> In general, no.
>
> class A{
> T foo[T](T x){ ... }
> }
> class B{
> override T foo[T](T x){ ... }
> }
>
> Often you can, but then you get unnecessary code duplication, which is
> presumably why SiegeLord dislikes templates.
>
> T test(T)(T x) if(is(T:const(char[])){
> T[int] a;
> }

This is closer to the wanted semantics:
T[] test(T)(T[] x) if(is(T[]:const(char[])){
     T[][int] a;
}


More information about the Digitalmars-d mailing list