Mistake on this page?
Report an issue in GitHub or email us
Public Member Functions | Protected Types | Protected Member Functions
SafeBool< T > Class Template Reference

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

#include <SafeBool.h>

Inheritance diagram for SafeBool< T >:
base

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) {
}

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

Member Typedef Documentation

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

void invalidTag ( ) const
protectedinherited

Nonimplemented call, use to disallow conversion between unrelated types.

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.

void trueTag ( ) const
protectedinherited

Special member function that indicates a true value.

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

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.