Getting the mutable version of a type

Magnus Lie Hetland magnus at hetland.org
Fri Mar 2 02:18:14 PST 2012


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?

I mean, I could do something like (for strings and related immutable arrays)...

void func(T)(ref immutable(T)[] arg) {
    T[] res;
    ...
    arg = cast(immutable(T)[]) res;
}

But it would be useful to be able to write the same template for both 
mutable and immutable types, and just use something like

void func(T)(ref T arg) {
    mutable(T) res;
    ...
    arg = cast(T) res;
}

Is there something like that? (E.g., a template in Phobos or 
something.) I guess I could do a match with an is() expression to 
extract the type, perhaps.


-- 
Magnus Lie Hetland
http://hetland.org



More information about the Digitalmars-d-learn mailing list