[Issue 12188] New: std.algorithm.nextPermutation requires random access
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Mon Feb 17 12:20:20 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12188
Summary: std.algorithm.nextPermutation requires random access
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: peter.alexander.au at gmail.com
--- Comment #0 from Peter Alexander <peter.alexander.au at gmail.com> 2014-02-17 12:20:14 PST ---
The constraints says it requires bidirectional, but it actually requires random
access due to this line:
reverse(takeExactly(retro(range), n));
'reverse' requires a bidirectional range, but 'takeExactly' on a bidirectional
range returns a forward range. You need to provide a random access range to
'takeExactly' to get bidirectional, so this becomes a requirement of
'nextPermutation'.
nextPermutation must be modified to support bidirectional ranges. Changing the
constraint to random access is not an acceptable fix.
Here's a simple test case where a bidirectional range fails:
---------------------
import std.algorithm, std.array;
struct MyRange
{
int[] a = [1, 2, 3];
@property
{
auto ref front() { return a.front; }
auto ref back() { return a.back; }
auto empty() { return a.empty; }
auto save() { return MyRange(a); }
}
void popFront() { a.popFront(); }
void popBack() { a.popBack(); }
}
void main()
{
MyRange r;
nextPermutation(r);
}
---------------------
--
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list