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) == Slice!(double*, 2)));
static assert(is(typeof(b) == Slice!(const(double)*, 2)));
static assert(is(typeof(c) == Slice!(immutable(double)*, 2)));

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

static assert(is(typeof(ac) == Slice!(const(double)*, 2)));
static assert(is(typeof(ai) == Slice!(immutable(double)*, 2)));


//////////// 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!(ZipIterator!(
            double*,  const(double)*, immutable(double)*), 2)));
static assert(is(typeof(abc2) == Slice!(ZipIterator!(
    const(double)*, const(double)*, immutable(double)*), 2)));
template LightConstOf(T)

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

auto lightConst(Iterator, size_t N, SliceKind kind)(immutable Slice!(Iterator, N, kind) e);

auto lightImmutable(Iterator, size_t N, SliceKind kind)(immutable Slice!(Iterator, N, kind) e);

auto lightImmutable(T)(auto ref immutable T v)
if (!is(T : P*, P) && __traits(hasMember, immutable(T), "lightImmutable") && !isSlice!T);
auto lightConst(T)(auto ref const T v)
if (!is(T : P*, P) && __traits(hasMember, const(T), "lightConst") && !isSlice!T);
auto lightConst(T)(auto ref immutable T v)
if (!is(T : P*, P) && __traits(hasMember, immutable(T), "lightConst") && !isSlice!T);

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

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

T lightImmutable(T)(auto ref immutable T e)
if (isImplicitlyConvertible!(immutable(T), T) && !__traits(hasMember, immutable(T), "lightImmutable") && !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);