between

Ensures that a number is between an upper bound and a lower bound.

By default, this function's bounds are **inclusive**, inclusivity/exclusivity can be changed on a per-bound basis by passing in a string template argument similar to std.random.uniform.

The string template parameter expects a 2-character long string consisting of an opening parenthesis or opening square bracket, followed by a closing parenthesis or closing square bracket. The opening bracket is for the lower bound, while the closing bracket is for the upper bound. Parenteses indicate that the boundary is inclusive, and square brackets indicate the boundary is exclusive.

All possible combinations:

- **()** - Both lower bound and upper bound are inclusive. - **(]** - Lower bound is inclusive and upper bound is exclusive. - **[)** - Lower bound is exclusive and upper bound is inclusive. - **[]** - Both lower bound and upper bound are exclusive.

Arg!N
between
(
string how = "()"
N
)
if (
isNumeric!N &&
isValidRangeSpecifier!how
)

Parameters

arg Arg!N

A wrapped argument, obtained with ensure.

Throws

EnsureException when validation fails.

Examples

const zero = 0;
const five = 5;

ensure!(zero).between!"[)"( 0, 5 ); // exception, lower bound is exclusive

See Also

ensure

Meta

Authors

Tony J. Hudgins