Range

Range struct template

Members

Aliases

This
alias This = typeof(this)

The This alias for the type of this struct

Functions

contains
bool contains(T x)

Predicate that checks whether the specified value is inside this range.

isCoveredBy
bool isCoveredBy(This[] ranges)

Predicate that checks whether this range is covered by the given array of ranges (i.e. whether it is a subset of the union of the array of ranges).

isSubsetOf
bool isSubsetOf(This other)

Determines whether this instance is non-empty subset of the specified range. All values in this range must be within the other range.

isSupersetOf
bool isSupersetOf(This other)

Determines whether this instance is a superset of the non-empty specified range. All values in the other range must be within this range.

isTessellatedBy
bool isTessellatedBy(This[] ranges)

Predicate that checks whether the provided array of ranges exactly tessellates this range. The term "tessellation" means that this range is a union of the given ranges and that the given ranges form a contiguous chain without gap or overlap.

is_empty
bool is_empty()
is_full_range
bool is_full_range()
is_valid
bool is_valid()

Note that in non-release builds, the struct invariant ensures that instances are always valid. This method can be called by user code to explicitly check the validity of a range, for example when creating a range from run-time data.

length
size_t length()
max
T max()
max
T max(T max)

Sets the maximum value of the range.

min
T min()
min
T min(T min)

Sets the minimum value of the range.

opCmp
int opCmp(typeof(this) rhs)

Compares this instance with rhs. An empty range is considered to be < all non-empty ranges. Otherwise, the comparison always considers the range's minimum value before comparing the maximum value.

opEquals
equals_t opEquals(This other)

Checks whether the specified range is exactly identical to this range.

overlapAmount
size_t overlapAmount(Range other)

Calculates the number of values shared by this range and the other range specified.

overlaps
bool overlaps(This other)

Checks whether this range shares any values with the other range specified.

subtract
void subtract(This other, This lower, This upper)

Subtracts the specified range from this range, returning the remaining range(s) via the out parameters. Two separate ranges can result from a subtraction if the range being subtracted bisects the range being subtracted from, like:

toString
istring toString()

The range must always be valid.

Static functions

isEmpty
bool isEmpty(T min, T max)

Checks whether the specified range is empty.

isFullRange
bool isFullRange(T min, T max)

Checks whether the specified range is the full range of T.

isValid
bool isValid(T min, T max)

Checks whether the specified range is valid.

makeRange
This makeRange(T min, T max)

Range factory which provides extended wrapper to opCall. It returns empty range when min > max or when it is impossible to respect the specified boundaries.

opCall
This opCall(T min, T max)

Static opCall. Disables the default "constructor", with the advantage that the invariant is run after calling this method, making it impossible to construct invalid instances.

Examples

Unittest to instantiate the Range template with all supported types, in turn running the unittests for each of them.

Range!(ubyte) br;
Range!(ushort) sr;
Range!(ulong) lr;

Meta