Bug 9391 – Constant std.regex.regex

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-01-24T18:52:00Z
Last change time
2017-01-07T03:02:18Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-01-24T18:52:04Z
This is a low-priority enhancement request (meta-enhancement request: in Bugzilla I'd like different tags for different enhancement request priorities). This code works: import std.stdio, std.regex; void main() { auto r = regex(r"\d+", "g"); "10 20 30".match(r).writeln(); } And prints: [["10"], ["20"], ["30"]] While this code: import std.stdio, std.regex; void main() { const r = regex(r"\d+", "g"); "10 20 30".match(r).writeln(); } Shows (dmd 2.062alpha): test.d(4): Error: template std.regex.match does not match any function template declaration. Candidates are: ...\dmd2\src\phobos\std\regex.d(6532): std.regex.match(R, RegEx)(R input, RegEx re) if (isSomeString!(R) && is(RegEx == Regex!(BasicElementOf!(R)))) ...\dmd2\src\phobos\std\regex.d(6539): std.regex.match(R, String)(R input, String re) if (isSomeString!(R) && isSomeString!(String)) ...\dmd2\src\phobos\std\regex.d(6545): std.regex.match(R, RegEx)(R input, RegEx re) if (isSomeString!(R) && is(RegEx == StaticRegex!(BasicElementOf!(R)))) ...\dmd2\src\phobos\std\regex.d(6532): Error: template std.regex.match cannot deduce template function from argument types !()(string,const(Regex!(char))) I suggest to support constant regex, if possible. (In D code I like to mark everything as not mutable unless it has to mutate).
Comment #1 by dmitry.olsh — 2013-01-25T12:50:39Z
This is more like a minor bug. Got to fix it.
Comment #2 by dmitry.olsh — 2016-10-06T22:31:14Z
Comment #3 by github-bugzilla — 2016-10-09T13:19:58Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/e98fa4ad5ad39487844c91357cfec4f698e88230 [std.regex] Fix issue 9391 - const regex, ctRegex is immutable https://github.com/dlang/phobos/commit/87847ed4804ccbbff84eeb60d5c6061ad3c138a5 [std.regex] More tests for issue 9391
Comment #4 by uaaabbjjkl — 2016-11-12T22:06:17Z
*** Issue 3880 has been marked as a duplicate of this issue. ***
Comment #5 by github-bugzilla — 2017-01-07T03:02:18Z
Commits pushed to stable at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/e98fa4ad5ad39487844c91357cfec4f698e88230 [std.regex] Fix issue 9391 - const regex, ctRegex is immutable https://github.com/dlang/phobos/commit/87847ed4804ccbbff84eeb60d5c6061ad3c138a5 [std.regex] More tests for issue 9391