Comment #0 by bearophile_hugs — 2014-01-29T08:26:22Z
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.
Comment #1 by peter.alexander.au — 2014-01-29T11:57:12Z