string mixin only works once per block?
Chris
wendlec at tcd.ie
Fri Apr 11 07:31:46 PDT 2014
On Friday, 11 April 2014 at 14:05:17 UTC, Vlad Levenfeld wrote:
> I'm trying to cut down on some boilerplate with this function:
>
> const string link (alias variable) ()
> {
> const string name = __traits (identifier, variable);
> return name~`= glGetUniformLocation (program, "`~name~`");`;
> }
>
> Applied in this kind of context:
>
> this ()
> {
> super ("default.vert", "gradient.frag");
> mixin link!start_color;
> mixin link!final_color;
> mixin link!center_pos;
> mixin link!lerp_vec;
> mixin link!lerp_range;
> }
>
>
> And the first mixin in every such function works fine, but the
> rest don't. Specifically, I get this error:
>
> source/main.d(483): Error: mixin link!final_color link isn't a
> template
>
> for each mixin after the first. If I put the argument to mixin
> in parenthesis:
>
> mixin (link!start_color);
>
> I get:
>
> source/main.d(483): Error: value of 'this' is not known at
> compile time
>
> Finally, removing the parenthesis and putting each mixin
> statement in its own block:
>
> {mixin link!start_color;}
>
> compiles, but the mixed-in string has no apparent effect.
>
> Is this a bug or am I doing it wrong?
Just of the top of my head, have you tried
mixin template Link {
const string link() {
// ...
}
}
or something like this?
More information about the Digitalmars-d-learn
mailing list