Boost logo

Boost :

From: Guillaume Melquiond (gmelquio_at_[hidden])
Date: 2002-09-02 01:02:42

On Sun, 1 Sep 2002, Douglas Paul Gregor wrote:

> On Sun, 1 Sep 2002, Sylvain Pion wrote:
> > Having the comparison operators return something else than bool can probably be
> > somewhat confusing and risky. It all depends if there is a clearly defined
> > logic over these tri-state types. I have not followed the boost::tribool
> > discussions in detail, but this might be a possible connection.
> 'tribool' would give a clearly-defined logic for 3-state boolean values.

Yes, tribool would provide quite a nice way to deal with comparisons,
since they need to mathematically return a tri-state value. Unfortunately,
at the time the comparison policy was designed, boost::tribool hadn't made
its way through to the boost mailing-list.

> It's semantics correspond to the default Comparison policy
> (compare_certainly).

If I clearly understand what you mean, I need to disagree. The
compare_certainly policy has been conceived to return a boolean value (the
comparisons only answer "true" when the result is precisely "true").

If you need a tri-state behavior, the policy is compare_full. With this
policy, the library returns "true" or "false" when it is sure it is the
correct result of a comparison. When the result is "maybe", a
function-object is used.

> When I post my review of the interval library
> (tomorrow or early Tuesday EST), I intend to provide an analysis of the
> interface if it were to use 'tribool' return values for comparisons,
> because this is _extremely_ important in my domain (static analysis) where
> the interval library could be extremely useful.

At present, the library do not allow to specify the return type of the
comparisons operator. It had been considered; but for lack of a convincing
tri-state boolean at that time, this additional complexity was not

If it was to be included (the rest of this review will say it), a tribool
comparison policy could be defined by:

  struct maybe_behavior {
    typedef tribool return_type; // it's what the current library does
                                 // not allow
    tribool operator() () { return tribool::maybe; }

  typedef compare_full<T, maybe_behavior> my_compare;


Boost list run by bdawes at, gregod at, cpdaniel at, john at