Search code examples
pointersdconst-correctnessphobos

D: Cannot seem to create an std.container.Array of const struct pointers


Suppose I have a struct type Foo. I'm trying to create an std.container.Array of const pointers to Foo. I tried the obvious first:

import std.container;

alias FooArray = Array!(const(Foo*));

However, this causes a compiler error. Then I tried it with fewer parentheses:

alias FooArray = Array!(const Foo*);

But this gave the same error (error instantiating apparently). What am I doing wrong here?


Solution

  • Array probably needs to modify the reference (if not the object).

    Try this:

    alias FooArray = Array!(const(Foo)*);