Getting the mutable version of a type

Ali Çehreli acehreli at yahoo.com
Fri Mar 2 03:23:20 PST 2012


On 03/02/2012 02:18 AM, Magnus Lie Hetland wrote:
> I'm writing a template for generating data of some possibly immutable
> type -- e.g., a string. What I'm wondering is, is there some way of
> accessing the mutable version of an immutable type?

Yes, std.traits.Unqual:

   http://dlang.org/phobos/std_traits.html#Unqual

import std.stdio;
import std.traits;

void foo(T)()
{
     Unqual!T temp;
     writeln(typeof(temp).stringof);
}

void main()
{
     foo!(immutable int)();
}

Ali


More information about the Digitalmars-d-learn mailing list