Generic swap: Difference between revisions
Content added Content deleted
(→{{header|Pascal}}: add example) |
(Better D entry) |
||
Line 253:
=={{header|D}}==
<lang d>import std.algorithm: swap; // from Phobos standard library
The solution for D is quite similar to that for C++:▼
right = temp;
}
void main() {
import std.stdio;
int[] a = [10, 20];
writeln(a);
// contains a generic swap:
swap(a[0], a[1]);
writeln(a);
// Using mySwap:
mySwap(a[0], a[1]);
writeln(a);
}</lang>
{{out}}
▲The std.algorithm standard library module contains a generic swap.
<pre>[10, 20]
[20, 10]
[10, 20]</pre>
=={{header|dc}}==
|