Files CCore/inc/gadget/NegBool.h CCore/src/gadget/NegBool.cpp
NegBool is a simple proxy class, designed to return a logically negative value.
class NegBool
{
bool nok;
public:
NegBool(bool nok_=false) : nok(nok_) {}
bool operator ! () const { return nok; }
};
Assume you have a function with a logically negative return value:
bool func() { bool nok; .... return nok; }
When you check the result of the function you will have a code like this:
if( func() ) // not clear way to express a error case { // handle failure }
You can use the class NegBool to warp the return value:
NegBool func() { bool nok; .... return nok; }
Then you have the following code, logically the same as above:
if( !func() ) // using operator ! to express a error case { // handle failure }