www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - CTFE and structs question

reply g <g g-desktop.com> writes:
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
parent reply Don <nospam nospam.com> writes:
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
next sibling parent Bill Baxter <wbaxter gmail.com> writes:
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
prev sibling parent reply g <g g-desktop.com> writes:
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
parent Don <nospam nospam.com> writes:
g wrote:
 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.
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.
 
 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