View source code
Display the source code in std/range/primitives.d from which this page was generated on
github.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Page wiki
View or edit the community-maintained wiki page associated with this page.
Template std.range.primitives.isInfinite
Returns true if R is an infinite input range. An
infinite input range is an input range that has a statically-defined
enumerated member called that is always emptyfalse,
for example:
struct MyInfiniteRange
{
enum bool empty = false;
...
}
Arguments
template isInfinite(R);
Example
import std.range : Repeat; static assert(!isInfinite!(int[])); static assert( isInfinite!(Repeat!(int))); } /** ReturnstrueifRoffers a slicing operator with integral boundaries that returns a forward range type. For finite ranges, the result ofopSlicemust be of the same type as the original range type. If the range definesopDollar, then it must support subtraction. For infinite ranges, when not usingopDollar, the result ofopSlicemust be the result of take or takeExactly on the original range (they both return the same type for infinite ranges). However, when usingopDollar, the result ofopSlicemust be that of the original range type. The following code must compile forhasSlicingto betrue:
R r = void;
static if(isInfinite!R)
typeof(take(r, 1)) s = r[1 .. 2];
else
{
static assert(is(typeof(r[1 .. 2]) == R));
R s = r[1 .. 2];
}
s = r[1 .. 2];
static if(is(typeof(r[0 .. $]))) { static assert(is(typeof(r[0 .. $]) == R)); R t = r[0 .. $]; t = r[0 .. $];
static if(!isInfinite!R)
{
static assert(is(typeof(r[0 .. $ - 1]) == R));
R u = r[0 .. $ - 1];
u = r[0 .. $ - 1];
}
Authors
Andrei Alexandrescu, David Simcha, and Jonathan M Davis. Credit for some of the ideas in building this module goes to Leonardo Maffi.