static assert to protect against misguided equality comparison
This commit is contained in:
parent
3db676fa32
commit
6a7f325ecf
1 changed files with 13 additions and 0 deletions
|
|
@ -54,6 +54,7 @@
|
||||||
#define LIB_BOOL_CHECKABLE_H
|
#define LIB_BOOL_CHECKABLE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <boost/static_assert.hpp>
|
||||||
|
|
||||||
namespace lib {
|
namespace lib {
|
||||||
|
|
||||||
|
|
@ -117,6 +118,18 @@ namespace lib {
|
||||||
return !(obj.*isValid)();
|
return !(obj.*isValid)();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** safety guard: when this comparison kicks in, the compiler
|
||||||
|
* is about to use an implicit bool conversion on both sides to
|
||||||
|
* perform an equality test. This is most likely not what you want.
|
||||||
|
* Define an explicit equality comparison in the class using BoolCheckable!
|
||||||
|
*/
|
||||||
|
friend bool
|
||||||
|
operator== (BoolCheckable const&, BoolCheckable const&)
|
||||||
|
{
|
||||||
|
BOOST_STATIC_ASSERT (false && sizeof(T) );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue