Evo C++ Library v0.5.1
Public Member Functions | List of all members
SafeBool< T > Class Template Reference

#include <evo/type.h>

Detailed Description

template<class T>
class evo::SafeBool< T >

Safe bool base class.

This implements "safe" boolean evaluation, without the side-effects of implicit conversions from the bool type.

Template Parameters
TThe deriving type being used.
Example:
#include <evo/type.h>
// Class supporting "safe bool evaluation"
struct Foo : public evo::SafeBool<Foo> {
bool operator!() const
{ return false; }
};
void func() {
const Foo foo;
// Safe bool evaluation -- calls !operator!()
if (foo) {
// ...
}
// Negative bool evaluation -- calls operator!()
if (!foo) {
// ...
}
}

Public Member Functions

 SafeBool ()
 Constructor. More...
 
 operator SafeBoolType () const
 Safe (explicit) evaluation as bool type. More...
 

Constructor & Destructor Documentation

◆ SafeBool()

SafeBool ( )
inline

Constructor.

Member Function Documentation

◆ operator SafeBoolType()

operator SafeBoolType ( ) const
inline

Safe (explicit) evaluation as bool type.

  • This is called when object is directly evaluated as a bool, and is equivalent to: !operator!()
  • See SafeBool

The documentation for this class was generated from the following file: