The OpenD Programming Language

YearQuarter.opOpAssign

struct YearQuarter
ref return @safe pure nothrow @nogc
opOpAssign
(
string op
)
(
int rhs
)
if (
op == "+" ||
op == "-"
)

Examples

auto x = YearQuarter(2020, Quarter.q1);
auto x1 = x + 1;
assert(x1 == YearQuarter(2020, Quarter.q2));
auto x2 = x + 2;
assert(x2 == YearQuarter(2020, Quarter.q3));
auto x3 = x + 3;
assert(x3 == YearQuarter(2020, Quarter.q4));
auto yq = YearQuarter(2020, Quarter.q1);
yq += 2;
assert(yq == YearQuarter(2020, Quarter.q3));
yq -= 1;
assert(yq == YearQuarter(2020, Quarter.q2));

Get a slice of YearQuarters

import mir.ndslice.topology: iota;

static immutable result1 = [YearQuarter(2020, Quarter.q1), YearQuarter(2020, Quarter.q2), YearQuarter(2020, Quarter.q3), YearQuarter(2020, Quarter.q4)];
static immutable result2 = [YearQuarter(2020, Quarter.q1), YearQuarter(2020, Quarter.q3), YearQuarter(2021, Quarter.q1), YearQuarter(2021, Quarter.q3)];

auto yq = YearQuarter(2020, Quarter.q1);

auto x = yq + 4.iota!uint;
assert(x == result1);

// every other quarter
auto y = yq + iota!uint([4], 0, 2);
assert(y == result2);

Meta