Boost logo

Boost :

From: Lutz Kettner (kettner_at_[hidden])
Date: 2000-11-29 15:16:14


Hi Danny,

> I just wrote a little helper class that allows to define operator< for
> my own classes in a special way so that I can write
>
> if( a < b < c ) ...
>
> Of course it can't work with build-in types and that's why I'm not
> sure if this helper class should better be locked away and someone
> should lose the key or if it could be helpful to increase readability.

Lose the key ;-) It works of course with builtin
types, such as bool or int (automatic conversion from
bool expression (... < ...) to int.) And the result is
probably not what you mean. Here is the snippet doing it.

Ciao,
Lutz

#include <iostream.h>

int main() {
    bool f = false;
    bool t = true;

    if ( t < f < t)
        cout << "true" << endl;
    else
        cout << "false" << endl;

    int i = -3;
    int j = -2;
    int k = -1;
    if ( i < j < k)
        cout << "true" << endl;
    else
        cout << "false" << endl;
    return 0;
}

-- 
Lutz Kettner 
----------------------------------------------------------------------
UNC Computer Science                       email: kettner_at_[hidden]
CB 3175, Sitterson Hall                    phone: (919) 962-1700 x7759
Chapel Hill, NC 27599-3175, USA            fax:   (919) 962-1799
----------------------------------------------------------------------

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