I'm trying to extend my wrapper class Bound to support CTFE Value Range Propagation in primary in opUnary and opBinary similar to what Ada's Range Types.

My current try so far for binary arithmetic is

    auto opBinary(string op, U,
                  U lower_rhs = U.min,
                  U upper_rhs = U.max,
                  string file = __FILE__,
int line = __LINE__)(Bound!(U, lower_rhs, upper_rhs) rhs)
    {
        Bound!(CommonType!(T, U),
               min(T.min, U.min),
               max(T.max + U.max)) tmp = void; // TODO: Needs fix
        mixin("tmp = _value " ~ op ~ "rhs;");
        mixin(check());
        return tmp;
    }

but this errors as

bound.d(120,19): Error: undefined identifier U and I don't understand why I can't parameterize opBinary in this way.

Ideas anyone?

For reference, this older version

https://github.com/nordlow/justd/blob/master/bound.d

compiles but do not do value range propagation in arithmetic.

Reply via email to