One more about mixins
BCS
ao at pathlink.com
Sun Aug 24 16:25:35 PDT 2008
Reply to Tomasz,
> I got a code generating function:
>
> string intGen(string[] names...)
> {
> string result;
> foreach (name; names)
> result ~= "int " ~ name ~ "; ";
> return result;
> }
> void main() {
> writeln(intGen("aa", "bb", "cc")); // ok, writes "int aa; int bb;
> int cc; "
> }
> struct tag {
> mixin(intGen("aa", "bb", "cc")); // doesn't compile, but why?
> }
> I tried using a string[] as an argument instead of a variadic
> argument, but still it doesn't work. I know the compiler must be able
> to evaluate mixins at compile time and I think it's able to do so in
> the example.
>
> Tomek
>
using CTFE (compile time function evaluation) with arrays is "finicky"
To limit the problem to the CTFE issues switch to this:
pragma(msg, intGen("aa", "bb", "cc"));
Post the error messages from that if you can't figure them out.
More information about the Digitalmars-d-learn
mailing list