|
Boost : |
From: Robert Kawulak (kawulak_at_[hidden])
Date: 2007-08-31 22:30:05
> From: Martin Dowie
> I've managed to download this now (thanks!) and I've played
> about with added support for floats/doubles.
I don't think it's a good idea to use constrained floats - explanation is
attached at the bottom of this message (it's an excerpt from a message in
another thread about this library). Anyway - use at your own risk! :P
> I'd also quite like the idea of being able to retrieve
> the range of a constrained value
[...]
> typedef bounded_int<int, 0, 359>::type degrees_in_circle;
Not a problem, it's already been there:
degrees_in_circle::constraint_type::lower_gen_type::value
I know it's not pretty, but I can't help it - this is the price of modularity.
;-)
BTW, to get runtime value in case of stored bounds:
bounded<int>::type b;
// ...
b.constraint().lower_bound()
This works for compile-time bounds too (i.e., for bounded_int etc.).
Best regards,
Robert
ON FLOATING POINT:
> 2 I don't see any examples with floating-point. Does this
> mean that it is only suitable for integral types? Could a
> floating-point type set to a NaN if out of bounds?
Any value type with 'normal' semantics can be used (with exception of wrapping -
the underlying type must represent integers, although not necessarily integral)
-- see examples with strings. The problem with floats is that they are not
'normal' - see http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.17.
Therefore this may make it impossible for constrained float to guarantee its
invariant (I'm not completely sure about this, but at least extreme care should
be taken when trying to use float as constrained underlying value). I'll add a
note on this issue.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk