On Saturday, 7 June 2014 at 16:15:47 UTC, hane wrote:
At std.regex.


BTW, I found that immutable regex can be created with enum.
    enum r1_ = regex("bla");
    immutable r1 = r1_;
Regex struct created during compiling can be immutable?

In this case, it must be using enum to force CTFE. As for the immutable variable, in D, unique expressions can be implicitly casted to immutable. A unique expression is, roughly, a newly-created value that is not referenced anywhere else in the program. What that means is that it's legal to implicitly convert it to immutable, since there is no other references to that value which could modify it. The expression `regex("bla")` is a unique expression, and can therefore be implicitly casted to immutable. Whether the assignment to an immutable variable is happening at runtime or compile-time though, I don't know.

Reply via email to