Boost logo

Boost :

Subject: [boost] [type traits] Strange behaviour of comparison operators with pointers
From: Frédéric Bron (frederic.bron_at_[hidden])
Date: 2011-06-18 06:23:00


The following code gives a compile time error (g++ and msvc):
        int const lhs=1;
        int* rhs=0;
        lhs == rhs;
But the following code gives no error:
        int const lhs=0;
        int* rhs=0;
        lhs == rhs;
because a const int with 0 value is a valid null pointer!

Then there is no way to predict if it is possible to compare lhs and
rhs based only on their types. The general rule is that it is not
possible so that this is what I propose to use for the type trait
extension detecting the possibility to call comparison operators on
given types.

Frédéric


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