Array literal template parameter?

Jacob Carlborg doob at me.com
Tue Nov 20 23:35:20 PST 2012


On 2012-11-21 00:22, Maxime Chevalier wrote:
> I need to pass an array literal as a template parameter. The reference
> on this website seems to imply this is possible, but doesn't illustrate
> it. The obvious way doesn't seem to work:
>
> mixin template MyTemplate(int[] arr) {}
> Error: arithmetic/string type expected for value-parameter, not int[]
>
> Is there no way to do this without using a mixin and CTFE? I don't think
> I can use tuple types because I need to initialize a struct member using
> the array literal parameter.

It seems an "alias" parameter is working:

mixin template MyTemplate(alias arr) {}

You might want to add some kind of template constraint on that.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list