Mbed OS Reference
Loading...
Searching...
No Matches
SafeBool< T > Class Template Reference

Safe conversion of objects in boolean context. More...

#include <SafeBool.h>

Inheritance diagram for SafeBool< T >:
base FunctionPointerWithContext< GattReadAuthCallbackParams * > FunctionPointerWithContext< GattWriteAuthCallbackParams * > FunctionPointerWithContext< const DiscoveredService * > FunctionPointerWithContext< const DiscoveredCharacteristic * > FunctionPointerWithContext< OnEventsToProcessCallbackContext * >

Public Member Functions

 operator BoolType_t () const
 Bool operator implementation, derived class must provide a bool toBool() const function. More...
 

Protected Types

typedef void(base::* BoolType_t) () const
 The bool type is a pointer to method that can be used in boolean context. More...
 

Protected Member Functions

void invalidTag () const
 Nonimplemented call, use to disallow conversion between unrelated types. More...
 
void trueTag () const
 Special member function that indicates a true value. More...
 

Detailed Description

template<typename T>
class SafeBool< T >

Safe conversion of objects in boolean context.

Classes wanting evaluation of their instances in boolean context must derive publicly from this class rather than implementing the easy to misuse operator bool().

Descendant classes must implement the function bool toBool() const to enable the safe conversion in boolean context.

Template Parameters
TType of the derived class
class A : public SafeBool<A> {
public:
// boolean conversion
bool toBool() const {
}
};
class B : public SafeBool<B> {
public:
// boolean conversion
bool toBool() const {
}
};
A a;
B b;
// will compile
if(a) {
}
// compilation error
if(a == b) {
}
Safe conversion of objects in boolean context.

Definition at line 113 of file common/SafeBool.h.

Member Typedef Documentation

◆ BoolType_t

typedef void(base::* BoolType_t) () const
protectedinherited

The bool type is a pointer to method that can be used in boolean context.

Definition at line 50 of file common/SafeBool.h.

Member Function Documentation

◆ operator BoolType_t()

operator BoolType_t ( ) const

Bool operator implementation, derived class must provide a bool toBool() const function.

Definition at line 119 of file common/SafeBool.h.

◆ invalidTag()

void invalidTag ( ) const
protectedinherited

Nonimplemented call, use to disallow conversion between unrelated types.

◆ trueTag()

void trueTag ( ) const
protectedinherited

Special member function that indicates a true value.

Definition at line 60 of file common/SafeBool.h.