Report a bug
If you spot a problem with this page, click here to create a Github issue.
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 a local clone.

mir.primitives

Templates used to check primitives.
Publicly imports mir.array.primitives.
Authors:
Ilya Yaroshenko
enum bool hasLength(R);
Returns:
true if R has a length member that returns an integral type implicitly convertible to size_t.
R does not have to be a range.
Examples:
static assert(hasLength!(char[]));
static assert(hasLength!(int[]));
static assert(hasLength!(inout(int)[]));

struct B { size_t length() { return 0; } }
struct C { @property size_t length() { return 0; } }
static assert(hasLength!(B));
static assert(hasLength!(C));
enum bool hasShape(R);
Returns:
true if R has a shape member that returns an static array type of size_t[N].
Examples:
static assert(hasLength!(char[]));
static assert(hasLength!(int[]));
static assert(hasLength!(inout(int)[]));

struct B { size_t length() { return 0; } }
struct C { @property size_t length() { return 0; } }
static assert(hasLength!(B));
static assert(hasLength!(C));
@property auto shape(Range)(auto ref Range range)
if (hasLength!Range || hasShape!Range);
Examples:
static assert([2, 2, 2].shape == [3]);
template DimensionCount(T)
@property bool anyEmpty(Range)(Range range)
if (hasShape!Range || __traits(hasMember, Range, "anyEmpty"));
@property size_t elementsCount(Range)(Range range)
if (hasShape!Range || __traits(hasMember, Range, "elementsCount"));
template DeepElementType(S) if (is(S == struct) || is(S == class) || is(S == interface))

template DeepElementType(S : T[], T)
Returns the element type of a struct with .DeepElemType inner alias or a type of common array.
Examples:
import mir.ndslice.slice;
import mir.ndslice.topology : iota;
static assert(is(DeepElementType!(Slice!(Universal, [4], const(int)[]))     == const(int)));
static assert(is(DeepElementType!(Slice!(Universal, [4], immutable(int)*))  == immutable(int)));