Bug 9299 – std.algorithm.minPos of const(int)[]

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2013-01-12T02:40:00Z
Last change time
2013-01-13T21:05:06Z
Keywords
rejects-valid
Assigned to
monarchdodra
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2013-01-12T02:40:50Z
import std.algorithm: minPos; void main() { const(int)[] a1 = [2, 3, 1, 4]; assert(minPos(a1) == [1, 4]); immutable int[] a2 = [2, 3, 1, 4]; assert(minPos(a2) == [1, 4]); } DMD 2.062alpha gives: ...\dmd2\src\phobos\std\algorithm.d(1489): Error: cannot modify const expression target ...\dmd2\src\phobos\std\algorithm.d(6183): Error: template instance std.algorithm.move!(const(int)) error instantiating test.d(4): instantiated from here: minPos!("a < b", const(int)[]) test.d(4): Error: template instance std.algorithm.minPos!("a < b", const(int)[]) error instantiating ...\dmd2\src\phobos\std\algorithm.d(1489): Error: cannot modify immutable expression target ...\dmd2\src\phobos\std\algorithm.d(6183): Error: template instance std.algorithm.move!(immutable(int)) error instantiating test.d(6): instantiated from here: minPos!("a < b", immutable(int)[]) test.d(6): Error: template instance std.algorithm.minPos!("a < b", immutable(int)[]) error instantiating
Comment #1 by monarchdodra — 2013-01-12T05:02:09Z
Hum. This pull is related: https://github.com/D-Programming-Language/phobos/commit/58fef77d02919f844b83b7de157420d9f8f8edda#L0R5498 It added support for non-LvalueRange, but broke support for immutables. I'll fix it. minCount also seems impacted :/
Comment #2 by bearophile_hugs — 2013-01-12T05:20:31Z
(In reply to comment #1) > It added support for non-LvalueRange, but broke support for immutables. I'll > fix it. Thank you. If you want to fix it, then I suggest to also add a good amount of unittests, to catch future related problem.
Comment #3 by monarchdodra — 2013-01-12T08:50:38Z
Comment #4 by github-bugzilla — 2013-01-13T16:21:06Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/5afbfac8c50d1cc1ef2d211d1f09ca3c47a2d67f Fixes issue 9299 - std.algorithm.minPos of const(int)[] https://github.com/D-Programming-Language/phobos/commit/bdc959933c56d664d59bbd2ff4c911f7e50c490a Merge pull request #1070 from monarchdodra/9299 Fixes issue 9299 - std.algorithm.minPos of const(int)[]
Comment #5 by bearophile_hugs — 2013-01-13T21:05:06Z
(In reply to comment #1) > minCount also seems impacted :/ I have created Issue 9314