ndassign

Assignment utility for generic code that works both with scalars and with ndslices.

  1. auto ndassign(L lside, R rside)
    @property
    ndassign
    (
    string op = ""
    L
    R
    )
    (
    ref L lside
    ,
    auto ref R rside
    )
    if (
    !isSlice!L &&
    (
    op.length == 0 ||
    op[$ - 1] != '='
    )
    )
  2. auto ndassign(L lside, R rside)

Parameters

op

assign operation (generic, optional)

lside L

left side

rside R

right side

Return Value

Type: auto

expression value

Examples

import mir.ndslice.topology: iota;
import mir.ndslice.allocation: slice;
auto scalar = 3;
auto vector = 3.iota.slice; // [0, 1, 2]

// scalar = 5;
scalar.ndassign = 5;
assert(scalar == 5);

// vector[] = vector * 2;
vector.ndassign = vector * 2;
assert(vector == [0, 2, 4]);

// vector[] += scalar;
vector.ndassign!"+"= scalar;
assert(vector == [5, 7, 9]);

Meta