Boost logo

Boost :

From: Martin Dowie (martin.dowie_at_[hidden])
Date: 2007-09-15 08:39:35


> From: Robert Kawulak
>
> 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

Strange, I've been doing it in Ada for 15+ years and it's been of /great/
assistance there!! ;-)

The problem with floats is when you have literals (and sometimes when you
have equivalence checks), you don't always get quite what you expect and
that would apply when specifying the lower & upper bounds.

/But/ you have that with plain-old-code checks anyway, and this library is
really just about allowing people to replace these tiresome and repetitive
checks with something "automagic".

Given that most of the ranges I'm interested in are real numbers this is a
"must have" in my book.

> > 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.).

Ok, I'll go and dig deeper. It would be nice to be able to say:

   bounded_int<int, 0, 100>::type b;

   std::cout << "first = " << b.first() << "\n"
             << "last = " << b.last() << std::endl;

And get:

first = 0
last = 100

Cheers
-- Martin


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