Re: Structures and CTFE

2018-09-03 Thread Stefan Koch via Digitalmars-d-learn
On Monday, 3 September 2018 at 15:08:57 UTC, agorkvmh wrote: On Monday, 3 September 2018 at 15:00:33 UTC, Alex wrote: On Monday, 3 September 2018 at 14:00:23 UTC, agorkvmh wrote: [...] Yes. Put a pragma where you static assert for Foo(1).pos equality with 2: [...] Thanks, by the way,

Re: Structures and CTFE

2018-09-03 Thread agorkvmh via Digitalmars-d-learn
On Monday, 3 September 2018 at 15:00:33 UTC, Alex wrote: On Monday, 3 September 2018 at 14:00:23 UTC, agorkvmh wrote: [...] Yes. Put a pragma where you static assert for Foo(1).pos equality with 2: [...] Thanks, by the way, the autocomplete suggests me '__ctfeWrite', what is it?

Re: Structures and CTFE

2018-09-03 Thread Alex via Digitalmars-d-learn
On Monday, 3 September 2018 at 14:00:23 UTC, agorkvmh wrote: There is a way to do print the two values at compile time? Yes. Put a pragma where you static assert for Foo(1).pos equality with 2: -- static assert(Foo(1).pos == 2); pragma(msg, Foo(1).pos); struct Foo { this(int i)

Re: Structures and CTFE

2018-09-03 Thread agorkvmh via Digitalmars-d-learn
On Monday, 3 September 2018 at 13:52:24 UTC, bauss wrote: On Monday, 3 September 2018 at 13:39:25 UTC, agorkvmh wrote: [...] It prints 1, because pragma(msg) is called when the compiler is analyzing the code through the semantic process and not when the body of the function is executed

Re: Structures and CTFE

2018-09-03 Thread bauss via Digitalmars-d-learn
On Monday, 3 September 2018 at 13:39:25 UTC, agorkvmh wrote: Hi all, Running this: --- static assert(Foo(1).pos == 2); struct Foo { this(int i){ advance(); } size_t pos =1; void advance() { pragma(msg, pos); pos = pos+1; pragma(msg, pos); } } dmd