Bug 9016 – swap() doesn't work with std.container.DList.front and back

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2012-11-12T20:31:00Z
Last change time
2014-04-07T07:39:28Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2012-11-12T20:31:03Z
std.container.DList supports a manually written swap of its front and back items, but it seems std.algorithm.swap() on them is not supported: import std.stdio, std.algorithm, std.container; void main() { auto L = DList!int([10, 20, 30]); writeln(L[]); // [10, 20, 30] auto aux = L.front; L.front = L.back; L.back = aux; writeln(L[]); // [30, 20, 10] //swap(L.front, L.back); } If you uncomment the swap dmd 2.061alpha gives: test.d(9): Error: template std.algorithm.swap does not match any function template declaration ...\dmd2\src\phobos\std\algorithm.d(1767): Error: template std.algorithm.swap cannot deduce template function from argument types !()(int,int)
Comment #1 by monarchdodra — 2014-04-07T07:39:28Z
This didn't work because containers were sealed, and swap operates on references. It is now resolved thanks to the unsealing of containers: https://github.com/D-Programming-Language/phobos/pull/1857