RFC: Value range propagation for if-else

"Nordlöw" via Digitalmars-d digitalmars-d at puremagic.com
Wed Jun 18 13:21:28 PDT 2014


On Wednesday, 18 June 2014 at 13:31:01 UTC, bearophile wrote:

> OK. But how?

The simplest example is probably the constructor for Bound 
defined something like

this(T value)
{
     enum r = __traits(valueRange, value);
     static if (this.min <= r[0] &&
                this.max <= r[1])
     {
         // were within inclusive range
     }
     else
     {
         // need range check here!
     }
     _value = value;
}

assuming that

- `this.min` and `this.max` are statically defined values (which 
they are in bound.d) and that
- value range information is propagated to the constructor 
argument `value`

Other functions such as arithmetic operators should be analogous.

Destroy!


More information about the Digitalmars-d mailing list