digitalmars.D.learn - CTFE and structs question
- g (13/13) Nov 07 2009 At what point structs are supported in CTFE.
- Don (9/26) Nov 07 2009 You can create them without templates. std.metastrings was created
- Bill Baxter (9/12) Nov 08 2009 I posted about this the other day, wouldn't it make sense to update
- g (15/23) Nov 08 2009 strange. you can do that only if there is no constructor.
- Don (4/28) Nov 08 2009 It also works with opCall. ctor calls don't yet work in CTFE calls from
At what point structs are supported in CTFE. Cause this fails in dmd 2.036: import std.metastrings; pragma(msg,toStringNow!(A.init.a)); struct A{ uint a; } with this message (note that the end seems truncated): g g-desktop:~/Documentos/NCHESS$ dmd oh oh.d(3): Error: no property 'a' for type 'A' toStringNow!(__error) g g-desktop:~/Documentos/NCHESS$ also, ¿Is there any way to generate structs with ctfe or it is obligatory to use templates?
Nov 07 2009
g wrote:At what point structs are supported in CTFE. Cause this fails in dmd 2.036: import std.metastrings; pragma(msg,toStringNow!(A.init.a)); struct A{ uint a; } with this message (note that the end seems truncated): g g-desktop:~/Documentos/NCHESS$ dmd oh oh.d(3): Error: no property 'a' for type 'A' toStringNow!(__error) g g-desktop:~/Documentos/NCHESS$ also, ¿Is there any way to generate structs with ctfe or it is obligatory to use templates?You can create them without templates. std.metastrings was created before CTFE existed, it's rather outdated. It's intended for use with template metaprogramming, not for use with CTFE. You can do stuff like: struct Foo { int x; } enum Foo b = Foo(56);
Nov 07 2009
On Sat, Nov 7, 2009 at 10:40 PM, Don <nospam nospam.com> wrote:You can create them without templates. std.metastrings was created before CTFE existed, it's rather outdated. It's intended for use with template metaprogramming, not for use with CTFE.I posted about this the other day, wouldn't it make sense to update std.metastrings to be a set of functions useful for CTFE? Because that way they would be usable from either templates or other CTFE functions. And as CTFE capabilities of the compiler get better the functions could be replaced with simple aliases to regular functions in std.string. But at the moment there's not much in std.string that works for CTFE. --bb
Nov 08 2009
Don Wrote:You can do stuff like: struct Foo { int x; } enum Foo b = Foo(56);strange. you can do that only if there is no constructor. Also trying with templates, i got a segfault, i dont know if it is already reported. Why this segfaults?. At least it should print a error message. enum Move b = genMove!(); struct Move{ int Dx; } template genMove(){ enum invariant(Move) genMove = { Dx:4}; } it just segfaults: /Documentos/NCHESS$ dmd pi Fallo de segmentación /Documentos/NCHESS$
Nov 08 2009
g wrote:Don Wrote:It also works with opCall. ctor calls don't yet work in CTFE calls from module scope (works OK inside a function) -- structural problem with DMD.You can do stuff like: struct Foo { int x; } enum Foo b = Foo(56);strange. you can do that only if there is no constructor.Also trying with templates, i got a segfault, i dont know if it is already reported. Why this segfaults?. At least it should print a error message. enum Move b = genMove!(); struct Move{ int Dx; } template genMove(){ enum invariant(Move) genMove = { Dx:4}; } it just segfaults:That's new. I've entered it as bug 3488.
Nov 08 2009