Why can't a Regex object be immutable?
Shriramana Sharma via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri Jan 1 18:02:09 PST 2016
Hello. With this code:
import std.stdio, std.regex;
void main()
{
immutable numbers = regex(r"\d+");
foreach (match; "a1b2c3d4e5".matchAll(numbers))
writeln(match[0]);
}
compiling gives the error:
<src>(4): Error: cannot implicitly convert expression (regex("\\d+", "")) of
type Regex!char to immutable(Regex!char)
<src>(5): Error: template std.regex.matchAll cannot deduce function from
argument types !()(string, immutable(Regex!char)), candidates are:
/usr/include/dmd/phobos/std/regex/package.d(859):
std.regex.matchAll(R, RegEx)(R input, RegEx re) if (isSomeString!R &&
is(RegEx == Regex!(BasicElementOf!R)))
/usr/include/dmd/phobos/std/regex/package.d(867):
std.regex.matchAll(R, String)(R input, String re) if (isSomeString!R &&
isSomeString!String)
/usr/include/dmd/phobos/std/regex/package.d(874):
std.regex.matchAll(R, RegEx)(R input, RegEx re) if (isSomeString!R &&
is(RegEx == StaticRegex!(BasicElementOf!R)))
If I use `auto` all is fine. Why is it impossible for a Regex object to be
`immutable`?
--
Shriramana Sharma, Penguin #395953
More information about the Digitalmars-d-learn
mailing list