Boost logo

Boost :

From: Jens Maurer (jmaurer_at_[hidden])
Date: 2000-03-07 05:54:42


Martin Schürch wrote:
> What I found in both areas often very useful are comparison operators
> only with a real. e.g. [a,b] < 3.14.

This is implemented. Real numbers automatically convert to intervals,
so [3,4] < 5 says "true" and [3,4] < 3.5 says "false". Just to show
the usefulness of <boost/operators.hpp> and save a few clock cycles, I
also implemented these comparisons directly, so no conversion is
necessary.
 
> Concept
> 1: [1,100] < [20,60] <-> comparison is "set" - like

Use the provided "interval::contains" member function for that.

> 2: [0,1] <[3,7] <-> Like your interval "<"

I intended my interval class to be a drop-in replacement for "double"
and give sensible results most of the time. That means, my interval "<"
is defined so that all numbers of the first interval must be lower than
the second.

Furthermore, there seem to be applications which are interval-aware,
so there may be other requirements. However, these can be catered for
by additional member functions (since the application knows it's using
an interval anyway).
 
> However there are other situations where the [a,b] interval concept of
> real values are also very useful. And a class name like
> interval does for me exactly imply that. To make the interval class more
> general useful would be JUST GREAT.

Please speak up what else you need. I'm most interested in people
actually trying to *use* this.

> Perhaps there are some ways (e.g. different namespaces, function names
> or traits) where the very general interval class can be
> separated of the
> more specific functionality. Especially comparison is one of the often
> disturbing points. (e.g. in your code : !(I1 < I2) && !(I2
> < I1) does not imply (I1== I2) can lead to problems)

At least it's documented :-) Anyway, is there a useful definition
for interval "<" that does not have the above deficiency? The
"set_less_eq" also has the problem, for example with [1,3] <? [2,4].
Of course we could define a "<" which compares the widths of the
intervals, but this would probably only come in handy for map<>
and set<>. And for these, we can specialized std::less.

> Personally I choose different function names to compare in different
> ways (like set_less_eq, ...) perhaps not very good names.

The question is whether you really need the overloaded operator "<"
to behave differently, or if a different function is enough for you.

The current "interval::contains" is a "set_less_eq", do you also
need a "set_strictly_less"? I doubt it's useful with real numbers.

> Would it be in your interest to transform your interval concept in a
> (multiple) general ones?

Yes, definitely, if things stay in manageable proportions.

Jens Maurer


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