ScummVM API documentation
safe-bool.h
1 
27 #ifndef COMMON_SAFE_BOOL_H
28 #define COMMON_SAFE_BOOL_H
29 
30 namespace Common {
31  namespace impl {
32  template <typename T>
33  struct no_base {};
34 
35  template <typename T>
36  struct safe_bool_impl {
37  typedef T *TP; // workaround to make parsing easier
38  TP stub;
39  typedef TP safe_bool_impl::*type;
40  };
41  }
42 
55  template <typename DerivedT, typename BaseT = impl::no_base<DerivedT> >
56  struct SafeBool : BaseT {
57  private:
59  typedef typename impl_t::type bool_type;
60 
61  public:
62  operator bool_type() const {
63  return static_cast<const DerivedT *>(this)->operator_bool() ?
64  &impl_t::stub : nullptr;
65  }
66 
67  operator bool_type() {
68  return static_cast<DerivedT *>(this)->operator_bool() ?
69  &impl_t::stub : 0;
70  }
71  };
73 } // End of namespace Common
74 
75 #endif
Definition: safe-bool.h:36
Definition: safe-bool.h:33
Definition: algorithm.h:29
Definition: safe-bool.h:56