D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 3880 - std.regex functions with const/immutable Regex object
Summary: std.regex functions with const/immutable Regex object
Status: RESOLVED DUPLICATE of issue 9391
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-05 01:31 UTC by Masahiro Nakagawa
Modified: 2016-11-12 22:06 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Masahiro Nakagawa 2010-03-05 01:31:57 UTC
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 Shin Fujishiro 2010-05-23 04:59:19 UTC
Fixed in svn r1545.
Comment 2 John Colvin 2016-11-11 14:28:28 UTC
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 Jakub Łabaj 2016-11-12 22:06:17 UTC
It is already fixed, but still not released.

*** This issue has been marked as a duplicate of issue 9391 ***