Constructs a sieve with the given size.
Return a finite slice of the sieve.
import std.algorithm : sum, until; import std.range : take, array; assert(Sieve!int(50).until!(n => n >= 50).sum == 328); assert(Sieve!int(nthPrimeUpperBound(50)).take(50).sum == 5117); assert(Sieve!int(30).fixed.array == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]); assert(Sieve!int(0).fixed.array == []); // this causes compilation to take about 9s and 2 GB of memory. // static assert(Sieve!ulong(2_000_000).fixed.sum = 142913828922); auto ps = Sieve!int(); assert(ps.front == 2); ps.popFront(); assert(ps.front == 3);
The Sieve of Eratosthenes
Backed by a bool[]; the template argument is only used for integral type yielded by the range.