Search code examples
metaprogrammingd

Remove a const qualifier from a variable in D


I want to create a non-const copy of a variable. I am doing this inside a templated function, which has an in ref input, so the type (T) has the const set. I see a ConstOf function in https://dlang.org/phobos/std_traits.html but I cannot find an inverse so I can get a non-const type from T.


Solution

  • You might be interested in std.traits.Unqual.

    Note that this gives the type with all qualifiers removed, not just const.