Permutations: Difference between revisions
Content added Content deleted
(updated faster D entry) |
|||
Line 865: | Line 865: | ||
this (/*in*/ T[] items) /*pure*/ nothrow |
this (/*in*/ T[] items) /*pure*/ nothrow |
||
in { |
in { |
||
static |
static enum string L = text(indexes.length); // impure |
||
assert(items.length >= 0 && items.length <= indexes.length, |
assert(items.length >= 0 && items.length <= indexes.length, |
||
"Permutations: items.length must be >= 0 && < " ~ L); |
"Permutations: items.length must be >= 0 && < " ~ L); |
||
Line 883: | Line 883: | ||
} |
} |
||
@property T[] front() |
@property T[] front() pure nothrow { |
||
static if (doCopy) |
static if (doCopy) |
||
return items.dup; // not nothrow |
//return items.dup; // not nothrow |
||
return items ~ []; // slower |
|||
else |
else |
||
return items; |
return items; |
||
Line 894: | Line 895: | ||
} |
} |
||
void popFront() |
void popFront() pure nothrow { |
||
tot--; |
tot--; |
||
if (tot > 0) { |
if (tot > 0) { |
||
Line 931: | Line 932: | ||
version (permutations2_main) { |
version (permutations2_main) { |
||
void main() { |
void main() { |
||
import std.stdio; |
import std.stdio, std.bigint; |
||
foreach (p; permutations!false([1, 2, 3])) |
foreach (p; permutations!false([1, 2, 3])) |
||
writeln(p); |
writeln(p); |
||
alias BigInt B; |
|||
foreach (p; permutations!false([B(1), B(2), B(3)])) {} |
|||
} |
} |
||
}</lang> |
}</lang> |