Re: [boost] Checked Integral Class

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. Matt
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}

I also do some static assertions and I was thinking of adding static functionality to add, multiply, divide, etc. at compile time. One could do this if one knew the lhs & rhs values at compile-time. What's the "typename DT" template parameter for?
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 :)
This makes me think about something like representing the float in unsigned format: sign, exponent, mantissa. You could figure out how to add and subtract, etc. the floats in this form and use meta-programming techniques to do some floating-point math with the compiler. Let me clean up what I've got and I'll send it to you via email with a small test program and we can kick it around a while. "Matt Doyle" <mdoyle@a-m-c.com> wrote in message news:12F38DF504DEFB4FA6BBF26668FE96DA02A61A@python.a-m-c.com... 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. Matt
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}
--------------------------------------------------------------------------------
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

--- Dan McLeran <dan.mcleran@seagate.com> wrote:
I also do some static assertions and I was thinking of adding static functionality to add, multiply, divide, etc. at compile time. One could do this if one knew the lhs & rhs values at compile-time.
Have you checked out MPL? <http://www.boost.org/libs/mpl/doc/> If you haven't done so, check out the section on "Numeric Metafunctions".
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 :)
This makes me think about something like representing the float in unsigned format: sign, exponent, mantissa. You could figure out how to add and subtract, etc. the floats in this form and use meta-programming techniques to do some floating-point math with the compiler.
Peder Holt and I are doing some work in that area. Peder's work is in the "metamath" sections of the Sandbox CVS <http://cvs.sourceforge.net/viewcvs.py/boost-sandbox/boost-sandbox/>; as soon as I fix a couple of bugs, I'll upload my work to the Vault <http://boost-consulting.com/vault/>. In the meantime, keep track of the "metadouble" threads and any discussions regarding MPL and numerics. Cromwell D. Enage __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Cromwell, Yes, I have used the MPL quite a bit, but I don't claim to be an expert. I will check out the numeric metafunctions section when I get a chance. Thanks for the info. "Cromwell Enage" <sponage@yahoo.com> wrote in message news:20050914190126.65780.qmail@web53903.mail.yahoo.com...
--- Dan McLeran <dan.mcleran@seagate.com> wrote:
I also do some static assertions and I was thinking of adding static functionality to add, multiply, divide, etc. at compile time. One could do this if one knew the lhs & rhs values at compile-time.
Have you checked out MPL? <http://www.boost.org/libs/mpl/doc/>
If you haven't done so, check out the section on "Numeric Metafunctions".
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 :)
This makes me think about something like representing the float in unsigned format: sign, exponent, mantissa. You could figure out how to add and subtract, etc. the floats in this form and use meta-programming techniques to do some floating-point math with the compiler.
Peder Holt and I are doing some work in that area. Peder's work is in the "metamath" sections of the Sandbox CVS <http://cvs.sourceforge.net/viewcvs.py/boost-sandbox/boost-sandbox/>; as soon as I fix a couple of bugs, I'll upload my work to the Vault <http://boost-consulting.com/vault/>. In the meantime, keep track of the "metadouble" threads and any discussions regarding MPL and numerics.
Cromwell D. Enage
__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (3)
-
Cromwell Enage
-
Dan McLeran
-
Matt Doyle