ImmutableOf

Applies immutable to the given type.

This is primarily useful in conjunction with templates that take a template predicate (such as many of the templates in phobos.sys.meta), since while in most cases, you can simply do immutable T or immutable(T) to make T immutable, with something like phobos.sys.meta.Map, you need to pass a template to be applied.

alias ImmutableOf(T) = T

Examples

static assert(is(ImmutableOf!int == immutable int));

// Note that immutable overrides const and inout.
static assert(is(ImmutableOf!(const int) == immutable int));
static assert(is(ImmutableOf!(inout int) == immutable int));

// Note that immutable overrides shared, since immutable is implicitly
// shared.
static assert(is(ImmutableOf!(shared int) == immutable int));

static assert(is(ImmutableOf!(immutable int) == immutable int));

import phobos.sys.meta : AliasSeq, Map;

alias Types = AliasSeq!(int, long,
                        bool*, ubyte[],
                        string, immutable(string));
alias WithImmutable = Map!(ImmutableOf, Types);
static assert(is(WithImmutable ==
                 AliasSeq!(immutable int, immutable long,
                           immutable(bool*), immutable(ubyte[]),
                           immutable(string), immutable(string))));

See Also

Meta