Re: Checking if CTFE is used?

2018-12-20 Thread MachineCode via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 14:23:38 UTC, berni wrote: On Tuesday, 18 December 2018 at 13:53:01 UTC, Stefan Koch wrote: Why would you need to know? Well, first out of curiosity. But there are also other reasons: I've got a large immutable array. Without CTFE I'd use some php script and

Re: Checking if CTFE is used?

2018-12-18 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, December 18, 2018 9:20:11 AM MST berni via Digitalmars-d-learn wrote: > On Tuesday, 18 December 2018 at 14:32:29 UTC, Adam D. Ruppe wrote: > > CTFE is used if and only if it MUST be used by context. That's > > a runtime function, so no ctfe. > > > > Do something like: > > > > int[4]

Re: Checking if CTFE is used?

2018-12-18 Thread berni via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 14:32:29 UTC, Adam D. Ruppe wrote: CTFE is used if and only if it MUST be used by context. That's a runtime function, so no ctfe. Do something like: int[4] generate() { int[4] tmp; foreach(i; 0..4) tmp[i] = i; return tmp; } static immutable int[4]

Re: Checking if CTFE is used?

2018-12-18 Thread Adam D. Ruppe via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 14:23:38 UTC, berni wrote: import std.stdio; class A { static immutable int[4] clue; static this() { if(__ctfe) assert(0, "Yep, CTFE used"); foreach (i;0..4) clue[i] = i; } } CTFE is used if and only if it MUST be used by

Re: Checking if CTFE is used?

2018-12-18 Thread berni via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 13:53:01 UTC, Stefan Koch wrote: Why would you need to know? Well, first out of curiosity. But there are also other reasons: I've got a large immutable array. Without CTFE I'd use some php script and add it as a large literal. With CTFE I don't need that php

Re: Checking if CTFE is used?

2018-12-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 12/18/18 7:21 AM, berni wrote: Is there a way to check if a function is indeed executed at compile time or not? (Other than going through the whole executable binaries...) I tried static this() {   if (__ctfe) pragma(msg,"works");   // some other stuff } but unfortunatley this "if" is

Re: Checking if CTFE is used?

2018-12-18 Thread Stefan Koch via Digitalmars-d-learn
On Tuesday, 18 December 2018 at 12:21:44 UTC, berni wrote: Is there a way to check if a function is indeed executed at compile time or not? (Other than going through the whole executable binaries...) I tried static this() { if (__ctfe) pragma(msg,"works"); // some other stuff } but

Re: Checking if CTFE is used?

2018-12-18 Thread Daniel Kozak via Digitalmars-d-learn
On Tue, Dec 18, 2018 at 1:25 PM berni via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Is there a way to check if a function is indeed executed at > compile time or not? (Other than going through the whole > executable binaries...) > > I tried > > > static this() > > { > >

Checking if CTFE is used?

2018-12-18 Thread berni via Digitalmars-d-learn
Is there a way to check if a function is indeed executed at compile time or not? (Other than going through the whole executable binaries...) I tried static this() { if (__ctfe) pragma(msg,"works"); // some other stuff } but unfortunatley this "if" is also executed at compile time,