Boost logo

Boost :

Subject: Re: [boost] [review][constrained_value] Review ofConstrainedValueLibrary begins today
From: Stjepan Rajko (stjepan.rajko_at_[hidden])
Date: 2008-12-08 21:09:15


On Mon, Dec 8, 2008 at 6:22 PM, Stjepan Rajko <stjepan.rajko_at_[hidden]> wrote:
> On Mon, Dec 8, 2008 at 4:39 PM, Robert Kawulak <robert.kawulak_at_[hidden]> wrote:
>
>> Maybe the requirement could be loosened if I find a generic way to implement the
>> bounds inclusion test which always returns false for NaN. Currently, to test x
>> for inclusion in a closed range [lower, upper], we have:
>>
>> !(x < lower) && !(upper < x)
>>
>
> But as the NaN case illustrates, !(x < lower) && !(upper < x) is not
> the same as (lower <= x) && (x <= upper). If I'm using a bounded
> type, I would want the latter. In non-numerical settings, and with
> custom comparisons, the two might have nothing to do with each other.
> I think bounded_value should *always* use the test (and invariant)
>
> compare(lower, x) && compare(x, upper).
>
> If you want boundaries excluded, use < for compare. If you want them
> included, use <=. If the type doesn't offer <=, use "<(a, b) || ==(a,
> b)".
>

OK, now I am getting both hasty and brain-dead. "!<(b,a)", as you
have it, is a perfectly fine comparison for many cases. <(a,b) ||
==(a,b) might work better for the NaN problem, but not for others.

Stjepan


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