On 3/7/18 3:20 AM, Andrea Fontana wrote:
On Tuesday, 6 March 2018 at 20:37:34 UTC, Steven Schveighoffer wrote:
What triggers the compile-time execution is the fact that static
*initializers* need to be decided at compile time.
So while it is executing the regex building at compile time in your
example, there are other ways to do it, and in this case, I'd prefer
using an enum. You can also use ctRegex.
The drawback of using static is that it keeps its value between
What about static immutable? I think enums exist only for compiler but
they're not a l-value, so you can't take a reference, am I wrong?
Static immutable works (and makes sense as a static variable) if you can
use it as immutable. I'm not sure regex can do that.
enums force the compile time execution, then you need to generate a
runtime value from the result. i.e.:
enum Xval = someCTFEfunction(); // run at CTFE.
auto x = Xval; // no calls, just pastes the result there.