Boost logo

Boost :

From: Matt Doyle (mdoyle_at_[hidden])
Date: 2005-09-14 12:33:58

I have pretty much the same template in my lib with the main exceptions being that, where possible, I statically assert as well, and I (sort of) allow for non-integral types (run time only).
        TBoundValue<typename RT, typename DT, RT min, RT max>

I would love to figure out how to trick the compiler into evaluating a floating point, non-type argument but so far I haven't found it (a few ideas though :)

Anyway, if there's interest in it I'd be willing to work together with you on it and merge our approaches together.

> I've written a template class to hold a range of valid
> integral values. My
> intent was to mimic Ada's ability to define a type like this:
> type SmallInt is range -10 .. 10;
> One can then declare objects of this type and any subsequent
> assignment that
> violated this range constraint woud throw an exception.
> I have built a C++ template class that does the same thing:
> template<typename T, T min, T max>
> struct CheckedIntegralValue
> To define a type that can hold the same range as the example above:
> typedef CheckedIntegralValue<int, -10, 10> SmallIntType;
> SmallIntType i = -10;//OK
> SmallIntType i2 = -100;//Will throw an exception at run-time
> for value
> out-of-range
> I won't include the whole thing here, but I can do so if
> there is enough
> interest. I have defined most of the operators one needs to
> use this type
> just as one would use a 'normal' integer.
> Would anyone be interested in something like this in the
> Boost libraries?
> Regards,
> Dan McLeran

Scanned by Fortigate {X3BTB534}

Boost list run by bdawes at, gregod at, cpdaniel at, john at