digitalmars.D.learn - Mixin Problems with D2.0
- Brian White (16/16) Mar 06 2008 I'm new to D and am playing with D2.0. When I try to compile the
- Simen Kjaeraas (10/28) Mar 06 2008 er =
- Brian White (3/9) Mar 06 2008 Got it. Why not declare them "invariant char[]", or does it simply make...
- Simen Kjaeraas (14/22) Mar 06 2008 ke =
- Bill Baxter (5/36) Mar 06 2008 You can also use 'string' instead.
I'm new to D and am playing with D2.0. When I try to compile the example on http://www.digitalmars.com/d/2.0/mixin.html, I get a compiler error: -------------------------------------------------------------- template GenStruct(char[] Name, char[] M1) { const char[] GenStruct = "struct " ~ Name ~ "{ int " ~ M1 ~ "; }"; } mixin(GenStruct!("Foo", "bar")); -------------------------------------------------------------- testmixin.d(6): template instance GenStruct!("Foo","bar") does not match any template declaration attribute argument to mixin must be a string, not (GetStruct!("Foo","bar")) -------------------------------------------------------------- Is there something else needed? -- Brian
Mar 06 2008
On Thu, 06 Mar 2008 12:02:24 +0100, Brian White <bcwhite pobox.com> wrot= e:I'm new to D and am playing with D2.0. When I try to compile the =example on http://www.digitalmars.com/d/2.0/mixin.html, I get a compil=er =error: -------------------------------------------------------------- template GenStruct(char[] Name, char[] M1) { const char[] GenStruct =3D "struct " ~ Name ~ "{ int " ~ M1 ~ "; =}";} mixin(GenStruct!("Foo", "bar")); -------------------------------------------------------------- testmixin.d(6): template instance GenStruct!("Foo","bar") does not mat=ch =any template declaration attribute argument to mixin must be a string, not =(GetStruct!("Foo","bar")) -------------------------------------------------------------- Is there something else needed? -- BrianThe problem is that "Foo" and "bar", as D strings, are invariant(char)[]= , = not char[]. The solution is to change the template totemplate GenStruct(const char[] Name, const char[] M1)-- Simen
Mar 06 2008
The problem is that "Foo" and "bar", as D strings, are invariant(char)[], not char[]. The solution is to change the template toGot it. Why not declare them "invariant char[]", or does it simply make no difference? -- Briantemplate GenStruct(const char[] Name, const char[] M1)
Mar 06 2008
On Thu, 06 Mar 2008 13:32:57 +0100, Brian White <bcwhite pobox.com> wrot= e:The problem is that "Foo" and "bar", as D strings, are =ke =invariant(char)[], not char[]. The solution is to change the template toGot it. Why not declare them "invariant char[]", or does it simply ma=template GenStruct(const char[] Name, const char[] M1)no difference? -- BrianBoth char[] and invariant(char)[] are implicitly castable to = const(char)[]. Had you for some reason done something like this: template GenStruct(const char[] Name, const char[] M1) { //stuffs } char[] myString1 =3D "Foo"; char[] myString2 =3D "bar"; GenStruct!(myString1, myString2); // error here, char[] not implicitly = castable to invariant(char)[] -- Simen
Mar 06 2008
Simen Kjaeraas wrote:On Thu, 06 Mar 2008 12:02:24 +0100, Brian White <bcwhite pobox.com> wrote:You can also use 'string' instead. template GenStruct(string Name, string M1) which is an alias for invariant(char)[] in D2. --bbI'm new to D and am playing with D2.0. When I try to compile the example on http://www.digitalmars.com/d/2.0/mixin.html, I get a compiler error: -------------------------------------------------------------- template GenStruct(char[] Name, char[] M1) { const char[] GenStruct = "struct " ~ Name ~ "{ int " ~ M1 ~ "; }"; } mixin(GenStruct!("Foo", "bar")); -------------------------------------------------------------- testmixin.d(6): template instance GenStruct!("Foo","bar") does not match any template declaration attribute argument to mixin must be a string, not (GetStruct!("Foo","bar")) -------------------------------------------------------------- Is there something else needed? -- BrianThe problem is that "Foo" and "bar", as D strings, are invariant(char)[], not char[]. The solution is to change the template totemplate GenStruct(const char[] Name, const char[] M1)
Mar 06 2008