Why can't a Regex object be immutable?

cym13 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 1 18:56:35 PST 2016


On Saturday, 2 January 2016 at 02:39:36 UTC, Shriramana Sharma 
wrote:
> Aw come on. The immutability of the variable is *after* it has 
> been created at runtime.

Sure, but still...

>> > you'll find that using
>> ctRegex() instead will allow you to declare it immutable for 
>> example. I didn't look at the implementation to identify a 
>> precise cause though.
>
> You mean ctRegex!(), but nope:
>
>     immutable numbers = ctRegex!r"\d+";
>
> or doing const there gives the same error and using auto 
> doesn't.

... I definitely get no error with this line (DMD v2.069, GDC 
5.3.0, LDC
0.16.1). The exact code I used is below.

     void main(string[] args) {
         import std.regex;
         immutable numbers = ctRegex!r"\d+";
     }

So yes immutability occurs after its creation, but it clearly 
seems linked to
a runtime-related issue nonetheless. I don't know what you used 
to get an
error with ctRegex as I couldn't reproduce one, maybe the 
solution lies
there.



More information about the Digitalmars-d-learn mailing list