digitalmars.D.bugs - [Issue 5134] New: std.algorithm.startsWith won't accept var from "in" as first arg
- d-bugmail puremagic.com (40/40) Oct 29 2010 http://d.puremagic.com/issues/show_bug.cgi?id=5134
- d-bugmail puremagic.com (10/10) Jan 09 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5134
- d-bugmail puremagic.com (15/15) Jul 12 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5134
- d-bugmail puremagic.com (43/43) Jul 12 2011 http://d.puremagic.com/issues/show_bug.cgi?id=5134
http://d.puremagic.com/issues/show_bug.cgi?id=5134 Summary: std.algorithm.startsWith won't accept var from "in" as first arg Product: D Version: D2 Platform: Other OS/Version: Windows Status: NEW Keywords: rejects-valid Severity: regression Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: cbkbbejeap mailinator.com 23:57:54 PDT --- import std.algorithm; void main() { foo("hello"); } void foo(in string str) { startsWith(str, "a"); } DMD 2.050 output: testStartsWith.d(8): Error: template std.algorithm.startsWith(alias pred = "a == b",Range,Ranges...) if (Ranges.length > 1 && isInputRange!(Range) && is(typeof(.startsWith!(pred)(doesThisStart,withOneOfThese[0])) : bool) && is(typeof(.startsWith!(pred)(doesThisStart,withOneOfThese[1..__dollar])) : uint)) does not match any function template declaration testStartsWith.d(8): Error: template std.algorithm.startsWith(alias pred = "a == b",Range,Ranges...) if (Ranges.length > 1 && isInputRange!(Range) && is(typeof(.startsWith!(pred)(doesThisStart,withOneOfThese[0])) : bool) && is(typeof(.startsWith!(pred)(doesThisStart,withOneOfThese[1..__dollar])) : uint)) cannot deduce template function from argument types !()(const(immutable(char)[]),string) Worked in DMD 2.049 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 29 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5134 Andrei Alexandrescu <andrei metalanguage.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED CC| |andrei metalanguage.com AssignedTo|nobody puremagic.com |andrei metalanguage.com -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 09 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5134 yebblies <yebblies gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |yebblies gmail.com Component|DMD |Phobos This is not a regression in dmd, but the result of fixing a dmd accepts-invalid. I'll leave it up to the phobos developers to decide if this is a regression or not. There are other similar bugs in bugzilla, and also enhancement requests for dmd that may make this valid code again. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 12 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5134 Jonathan M Davis <jmdavisProg gmx.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |RESOLVED CC| |jmdavisProg gmx.com Resolution| |INVALID PDT --- Of course startsWith won't accept something which was an in parameter. That would make it const. And a const range is useless. startsWith could work for but they're not. They instantiate with the exact type that you give them, and a const array can't have popFront called on it, so it's useless in a range-based function. const arrays with range-based functions by slicing them void foo(in string str) { startsWith(str[], "a"); } but as long as a slice of an array is the exact same type as the original instead of making the slice mutable (leaving the elements at the appropriate level of mutability of coures - immutable in the case of string), that doesn't work. You can cast the string - startsWith(cast(string)str, "a") - and it should work just fine, but as long str is const, it won't. So, this is not a bug that's going to be fixed by changing anything with startsWith. It's an inherent limitation in the language with regards to templates. Improving the situation with slicing const/immutable arrays should help, because then you can just slice them (as you would have to do with a static array), but until then, a cast is your best option. Of course, I would point out that having a string be in is of debatable value in the first place, since the original array can't be altered anyway. All it does is make it so that str can't be reassigned to another string inside of foo. Granted, you may want that, but in plenty of cases, it really doesn't buy you much. implemented, then that would definitely fix it (though it's questionable whether that's ever going to happen), but as it stands, startsWith isn't doing anything wrong. If it worked before, it was a bug in dmd. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 12 2011