Create const regex?

hane via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jun 6 07:25:25 PDT 2014


On Friday, 6 June 2014 at 12:01:55 UTC, AntonSotov wrote:
> const r1 = regex("bla");
> matchFirst( "big string", r1 );  //  ERROR!
>
> immutable r2 = regex("bla"); //  ERROR!
>
> Why can I not use const/immutable regex?

I think it's a Phobos bug that can't use regex as immutable.

You can use const regex with getting rid of "const" attribute 
with cast().
     matchFirst( "big string", cast()r1 );

Or using enum seems better way. This style appears in Phobos's 
code.
     enum r1 = regex("bla");


More information about the Digitalmars-d-learn mailing list