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.qualifier

Authors:
Ilya Yaroshenko
Examples:
import mir.math.common;
import mir.ndslice; //includes Mir's zip
import mir.qualifier;

//////////////// Native ///////////////

auto a = slice!double(5, 5);
auto b = iota([5, 5]).as!double.slice.lightConst;
auto c = magic(5).as!double.slice.trustedImmutable;

static assert(is(typeof(a) == ContiguousMatrix!double));
static assert(is(typeof(b) == ContiguousMatrix!(const double)));
static assert(is(typeof(c) == ContiguousMatrix!(immutable double)));

auto ac = (cast(const) a)[]; //[] calls lightConst
auto ai = (cast(immutable) a)[]; //[] calls lightImmutable

static assert(is(typeof(ac) == ContiguousMatrix!(const double)));
static assert(is(typeof(ai) == ContiguousMatrix!(immutable double)));


//////////// Incapsulation ////////////

// zip, map, vmap, zip, indexed, pairwise, slide
// and all other functons from ndslice.topology support
// constant propogation
auto abc0 = zip(a, b, c);
const abc1 = abc0;
auto abc2 = abc1[]; //[] calls lightConst

static assert(is(typeof(abc0) == Slice!(cast(SliceKind)2, [2LU], ZipIterator!(
            double*,  const(double)*, immutable(double)*))));
static assert(is(typeof(abc2) == Slice!(cast(SliceKind)2, [2LU], ZipIterator!(
    const(double)*, const(double)*, immutable(double)*))));
template LightConstOf(T)

template LightImmutableOf(T)
auto lightConst(SliceKind kind, size_t[] packs, Iterator)(const Slice!(kind, packs, Iterator) e);

auto lightConst(SliceKind kind, size_t[] packs, Iterator)(immutable Slice!(kind, packs, Iterator) e);

auto lightImmutable(SliceKind kind, size_t[] packs, Iterator)(immutable Slice!(kind, packs, Iterator) e);

auto lightConst(T)(auto ref const T e)
if (isImplicitlyConvertible!(const(T), T) && !isSlice!T);

auto lightConst(T)(auto ref immutable T e)
if (isImplicitlyConvertible!(immutable(T), T) && !isSlice!T);

auto lightImmutable(T)(auto ref immutable T e)
if (isImplicitlyConvertible!(immutable(T), T) && !isSlice!T);

auto lightConst(T)(const(T)[] e);

auto lightConst(T)(immutable(T)[] e);

auto lightImmutable(T)(immutable(T)[] e);

auto lightConst(T)(const(T)* e);

auto lightConst(T)(immutable(T)* e);

auto lightImmutable(T)(immutable(T)* e);

@trusted auto trustedImmutable(T)(auto ref const T e);