Two cases showing imperfection of the const system

Timon Gehr timon.gehr at
Thu Feb 16 15:36:32 PST 2012

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;

More information about the Digitalmars-d mailing list