Boost logo

Boost :

From: John Torjo (john.lists_at_[hidden])
Date: 2003-08-21 07:44:44


Why macro, and not the straightforward:

template< class first_type, class second_type>
bool operator^( const first_type & first, const second_type & second) {
    bool f = first;
    bool s = second;
    return f ^ s;
}

struct B
{
    operator bool() const { return true; }
    B operator!() const { return B(); }
};

#include <iostream>
using namespace std;
int main()
{
    B a, b;

    // Oops...
    cout << ( a != b ) << endl;
    cout << ( a ? !b : !!b ) << endl;

    // Works, but long, ugly syntax and repeating 'b':
    cout << ( a ? !static_cast<bool>(b) : static_cast<bool>(b) ) << endl;

    // Cool?
    cout << (( a ^ b )) << endl;
}


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