[Issue 12029] New: Swap on std.container.Array?
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Wed Jan 29 08:26:24 PST 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12029
Summary: Swap on std.container.Array?
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: bearophile_hugs at eml.cc
--- Comment #0 from bearophile_hugs at eml.cc 2014-01-29 08:26:22 PST ---
I'd like to use std.algorithm.swap on the items of std.array.Array.
Currently it's not possible, as shown here:
void main() {
import std.container: Array;
import std.range: hasSwappableElements;
auto arr = Array!int([1, 2]);
pragma(msg, hasSwappableElements!(typeof(arr)));
}
With dmd 2.065beta it outputs at compile time:
false
Current workaround is to swap the items manually:
void main() {
import std.container: Array;
auto arr = Array!int([1, 2]);
// Swap:
auto aux = arr[0];
arr[0] = arr[1];
arr[1] = aux;
assert(arr[0] == 2 && arr[1] == 1);
}
If std.container.Array was designed this way on purpose, perhaps to keep its
memory tightly sealed inside the container itself, then close down this
enhancement request.
--
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