BLE_API

Embed: (wiki syntax)

« Back to documentation index

SafeBool< T > Class Template Reference

SafeBool< T > Class Template Reference

template class SafeBool use CRTP to made boolean conversion easy and correct. More...

#include <SafeBool.h>

Inherits SafeBool_::base.

Public Member Functions

 operator BoolType_t () const
 Bool operator implementation, derived class has to provide bool toBool() const function.

Protected Types

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

Protected Member Functions

void invalidTag () const
 Non implemented call, use to disallow conversion between unrelated types.
void trueTag () const
 Member function which indicate true value.

Detailed Description

template<typename T>
class SafeBool< T >

template class SafeBool use CRTP to made boolean conversion easy and correct.

Derived class should implement the function bool toBool() const to make this work. Inheritance should be public.

Template Parameters:
TType of the derived class
 class A : public SafeBool<A> {
 public:

      // boolean conversion
      bool toBool() {

      }
 };

 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 95 of file SafeBool.h.


Member Typedef Documentation

typedef void(base::* BoolType_t)() const [protected, inherited]

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

Definition at line 35 of file SafeBool.h.


Member Function Documentation

void invalidTag (  ) const [protected, inherited]

Non implemented call, use to disallow conversion between unrelated types.

operator BoolType_t (  ) const

Bool operator implementation, derived class has to provide bool toBool() const function.

Definition at line 100 of file SafeBool.h.

void trueTag (  ) const [protected, inherited]

Member function which indicate true value.

Definition at line 45 of file SafeBool.h.