From: Dan McLeran (dan.mcleran_at_[hidden])
Date: 2005-09-14 11:56:44
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>
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
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?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk