Permutations: Difference between revisions

Better lazy D entry
(Added missing in lazy D version)
(Better lazy D entry)
Line 855:
<lang d>import std.algorithm, std.exception;
 
struct Permutations(bool doCopy=true, T) {
private immutable size_t num;
private T[] items;
Line 871:
return result;
}
 
 
this.num = items.length;
Line 878 ⟶ 877:
}
 
@property T[] front() /*const*/ pure /*nothrow*/ {
returnstatic items;if (doCopy)
return items.dup; // not nothrow
else
return Permutations!T(items);
}
 
Line 908 ⟶ 910:
}
 
Permutations!(doCopy,T) permutations(T)(/*in*/bool doCopy=true, T[] items) pure nothrow {
(/*in*/ T[] items)
return Permutations!T(items);
pure nothrow {
return Permutations!(doCopy, T)(items);
} unittest {
import std.bigint;
Line 919 ⟶ 923:
void main() {
import std.stdio;
foreach (p; permutations!false([1, 2, 3]))
writeln(p);
}