Bug 3880 – std.regex functions with const/immutable Regex object

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-03-05T01:31:00Z
Last change time
2016-11-12T22:06:17Z
Assigned to
nobody
Creator
repeatedly

Comments

Comment #0 by repeatedly — 2010-03-05T01:31:57Z
A few days ago, I wrote Alcor's scoring algorithm (source is here http://d.hatena.ne.jp/repeatedly/20100302/1267541283 (text in japanese)). At that time, I notice std.regex functions can't use const/immutable Regex object. const r = regex("123"); //auto m = "0123".match(r); // Error: template std.regex.match(Range,Engine) if ... //auto c = "0123".replace(r, "456"); // Error: no overload matches for replace(T,Range) I think match and replace shuold use const/immutable Regex object (splitter can use const/immutable object). Finally, std.regex.splitter example of DDoc is incorrect. auto s1 = ", abc, de, fg, hi, "; assert(equal(splitter(s1, regex(", *")), ["", "abc", "de", "fg", "hi"][])); // lack last element auto s1 = ", abc, de, fg, hi, "; assert(equal(splitter(s1, regex(", *")), ["", "abc", "de", "fg", "hi", ""][])); // correct!
Comment #1 by rsinfu — 2010-05-23T04:59:19Z
Fixed in svn r1545.
Comment #2 by john.loughran.colvin — 2016-11-11T14:28:28Z
Seems like this is still happening: auto foo() { import std.regex : regex, matchFirst; const r = regex("asdf"); matchFirst("fdsaf", r); } test.d(5): Error: template std.regex.matchFirst cannot deduce function from argument types !()(string, const(Regex!char)), candidates are: /usr/local/Cellar/dmd/2.072.0/include/dlang/dmd/std/regex/package.d(934): std.regex.matchFirst(R, RegEx)(R input, RegEx re) if (isSomeString!R && is(RegEx == Regex!(BasicElementOf!R))) /usr/local/Cellar/dmd/2.072.0/include/dlang/dmd/std/regex/package.d(942): std.regex.matchFirst(R, String)(R input, String re) if (isSomeString!R && isSomeString!String) /usr/local/Cellar/dmd/2.072.0/include/dlang/dmd/std/regex/package.d(950): std.regex.matchFirst(R, String)(R input, String[] re...) if (isSomeString!R && isSomeString!String) /usr/local/Cellar/dmd/2.072.0/include/dlang/dmd/std/regex/package.d(957): std.regex.matchFirst(R, RegEx)(R input, RegEx re) if (isSomeString!R && is(RegEx == StaticRegex!(BasicElementOf!R)))
Comment #3 by uaaabbjjkl — 2016-11-12T22:06:17Z
It is already fixed, but still not released. *** This issue has been marked as a duplicate of issue 9391 ***