Boost logo

Boost :

From: Dan McLeran (dan.mcleran_at_[hidden])
Date: 2005-09-14 13:27:47


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_at_[hidden]> wrote in message
news:12F38DF504DEFB4FA6BBF26668FE96DA02A61A_at_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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk