Re: Why this code can't take advantage from CTFE?

2016-02-05 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 22:45:47 UTC, Timon Gehr wrote: I would use enum forceCTFE(alias expr)=expr; though. With alias it won't force compile-time evaluation of expressions that can be interpreted as symbols. I've a code that build a JSON object using a wrapper over std.json.

Re: Why this code can't take advantage from CTFE?

2016-02-05 Thread Luis via Digitalmars-d-learn
On Friday, 5 February 2016 at 09:36:37 UTC, Andrea Fontana wrote: On Wednesday, 3 February 2016 at 22:45:47 UTC, Timon Gehr wrote: I would use enum forceCTFE(alias expr)=expr; though. With alias it won't force compile-time evaluation of expressions that can be interpreted as symbols. I've a

Re: Why this code can't take advantage from CTFE?

2016-02-05 Thread Andrea Fontana via Digitalmars-d-learn
On Friday, 5 February 2016 at 09:49:38 UTC, Luis wrote: Reading/parsing a JSON or a XML using std.json / std.xml could be done on CTFE ? parseJSON() from std.json doesn't work with CTFE. But I can build objects with with my code that works over std.json. So if you convert (with mixins) {

Why this code can't take advantage from CTFE?

2016-02-03 Thread Andrea Fontana via Digitalmars-d-learn
This code: import std.stdio; int very_very_long_function(in int k) { if (!__ctfe) writeln("Can't use ctfe!"); return k/2; } void main() { enum first = very_very_long_function(10); writeln("First is ", first); auto second = very_very_long_function(12);

Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 17:49:39 UTC, Marc Schütz wrote: On Wednesday, 3 February 2016 at 16:07:59 UTC, Messenger wrote: What is a good way to try to force it? Using enum? Then optionally copying the value once to avoid the "manifest constant" copy/paste behaviour, where applicable?

Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread Timon Gehr via Digitalmars-d-learn
On 02/03/2016 11:39 PM, Andrea Fontana wrote: On Wednesday, 3 February 2016 at 17:49:39 UTC, Marc Schütz wrote: On Wednesday, 3 February 2016 at 16:07:59 UTC, Messenger wrote: What is a good way to try to force it? Using enum? Then optionally copying the value once to avoid the "manifest

Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 16:07:59 UTC, Messenger wrote: What is a good way to try to force it? Using enum? Then optionally copying the value once to avoid the "manifest constant" copy/paste behaviour, where applicable? Yes, or static local variables are ctfe initialized too.

Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread Messenger via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 15:59:43 UTC, Adam D. Ruppe wrote: You never asked for CTFE. CTFE only happens when it *has* to - when you write code that specifically asks for or requires it. What is a good way to try to force it? Using enum? Then optionally copying the value once to

Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread anonymous via Digitalmars-d-learn
On 03.02.2016 16:34, Andrea Fontana wrote: void main() { enum first = very_very_long_function(10); writeln("First is ", first); auto second = very_very_long_function(12); writeln("Second is ", second); auto third = first; third += 1;

Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 15:34:51 UTC, Andrea Fontana wrote: enum first = very_very_long_function(10); auto second = very_very_long_function(12); Why second init doesn't work with CTFE? You never asked for CTFE. CTFE only happens when it *has* to - when you write code

Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 16:07:59 UTC, Messenger wrote: What is a good way to try to force it? Using enum? Then optionally copying the value once to avoid the "manifest constant" copy/paste behaviour, where applicable? template forceCTFE(alias expr) { alias forceCTFE = expr; }

Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread Messenger via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 17:16:30 UTC, Andrea Fontana wrote: But if I want a normal var, not static or enum? There's no way to force it? Just make a mutable copy of it, I think.

Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 3 February 2016 at 16:24:19 UTC, Adam D. Ruppe wrote: On Wednesday, 3 February 2016 at 16:07:59 UTC, Messenger wrote: What is a good way to try to force it? Using enum? Then optionally copying the value once to avoid the "manifest constant" copy/paste behaviour, where applicable?

Re: Why this code can't take advantage from CTFE?

2016-02-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/3/16 12:16 PM, Andrea Fontana wrote: On Wednesday, 3 February 2016 at 16:24:19 UTC, Adam D. Ruppe wrote: On Wednesday, 3 February 2016 at 16:07:59 UTC, Messenger wrote: What is a good way to try to force it? Using enum? Then optionally copying the value once to avoid the "manifest