safe_bool.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Utils_safe_bool_
18 #define HH_SENF_Utils_safe_bool_ 1
19 
20 // Custom includes
21 #include <senf/autoconf.hh>
22 
23 //#include "safe_bool.mpp"
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 
26 namespace senf {
27 
28 #ifdef SENF_CXX11_ENABLED
29 
30  template <typename T>
31  class comparable_safe_bool
32  {
33  public:
34  explicit operator bool() const;
35  };
36 
37  template <typename T>
38  class safe_bool : public comparable_safe_bool<T> {};
39 
40 #else
41 
48  {
49  protected:
50  typedef void (safe_bool_base::*bool_type)() const;
52 
53  // Just here to make them protected ...
54 
59  };
60 
65  template <typename T>
67  : public safe_bool_base
68  {
69  public:
70  operator bool_type() const;
71  bool operator !() const;
72 
73  protected:
75  };
76 
121  template <typename T>
122  class safe_bool : public comparable_safe_bool<T> {};
123 
124  template <typename T, typename U>
125  void operator==(const safe_bool<T>& lhs,const safe_bool<U>& rhs);
126 
127  template <typename T,typename U>
128  void operator!=(const safe_bool<T>& lhs,const safe_bool<U>& rhs);
129 
130 #endif
131 
132 }
133 
134 //-/////////////////////////////////////////////////////////////////////////////////////////////////
135 #include "safe_bool.cci"
136 //#include "safe_bool.ct"
137 #include "safe_bool.cti"
138 //#include "safe_bool.mpp"
139 #endif
140 
141 
142 // Local Variables:
143 // mode: c++
144 // fill-column: 100
145 // c-file-style: "senf"
146 // indent-tabs-mode: nil
147 // ispell-local-dictionary: "american"
148 // compile-command: "scons -u test"
149 // comment-column: 40
150 // End:
void operator!=(const safe_bool< T > &lhs, const safe_bool< U > &rhs)
void(safe_bool_base::* bool_type)() const
Definition: safe_bool.hh:50
safe_bool_base & operator=(const safe_bool_base &)
Mixin class for safe boolean conversion support.
Definition: safe_bool.hh:122
internal safe_bool base class
Definition: safe_bool.hh:47
void this_type_does_not_support_comparisons() const
Mixin class for safe bool conversion support (comparable classes)
Definition: safe_bool.hh:66
void operator==(const safe_bool< T > &lhs, const safe_bool< U > &rhs)