D2 cast away const
Robert DaSilva
spunit262.nospam at gmail.com
Wed Nov 7 12:32:27 PST 2007
Janice Caron wrote:
> On 11/5/07, Frank Benoit <keinfarbton at googlemail.com> wrote:
>> Is there a way to make a generic T const free?
>
> I think this works
>
> template(T) { typedef T Mutable; }
> template(T:const(T)[]) { typedef T[] Mutable; }
>
> Then Mutable!(T) is the mutable equivalent of T
>
> That's from memory, but I've had something like that working.
Almost,
template Mutable(T)
{
alias typeof(T) Mutable;
}
template Mutable(T : T[])
{
alias typeof(T)[] Mutable;
}
typedef creates a new distinct type, and for some reason you need to use
typeof to remove the invariantness from T.
More information about the Digitalmars-d
mailing list