safe_bool.cti
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 
14 /** \file
15  \brief safe_bool inline template implementation */
16 
17 //#include "safe_bool.ih"
18 
19 // Custom includes
20 
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
23 
24 #ifdef SENF_CXX11_ENABLED
25 
26 template <typename T>
27 prefix_ senf::comparable_safe_bool<T>::operator bool()
28  const
29 {
30  return static_cast<const T*>(this)->boolean_test();
31 }
32 
33 #else
34 
35 template <typename T>
36 prefix_ senf::comparable_safe_bool<T>::operator bool_type()
37  const
38 {
39  return (static_cast<const T*>(this))->boolean_test()
40 // ? &safe_bool_base::this_type_does_not_support_comparisons : 0;
41  ? &comparable_safe_bool<T>::this_type_does_not_support_comparisons : 0;
42 }
43 
44 template <typename T>
45 prefix_ bool senf::comparable_safe_bool<T>::operator!()
46  const
47 {
48  return ! (static_cast<const T*>(this))->boolean_test();
49 }
50 
51 template <typename T>
52 prefix_ senf::comparable_safe_bool<T>::~comparable_safe_bool()
53 {}
54 
55 template <typename T, typename U>
56 prefix_ void senf::operator==(const safe_bool<T>& lhs, const safe_bool<U>& rhs)
57 {
58  lhs.this_type_does_not_support_comparisons();
59 }
60 
61 template <typename T, typename U>
62 prefix_ void senf::operator!=(const safe_bool<T>& lhs, const safe_bool<U>& rhs)
63 {
64  lhs.this_type_does_not_support_comparisons();
65 }
66 
67 #endif
68 
69 //-/////////////////////////////////////////////////////////////////////////////////////////////////
70 #undef prefix_
71 
72 
73 // Local Variables:
74 // mode: c++
75 // fill-column: 100
76 // c-file-style: "senf"
77 // indent-tabs-mode: nil
78 // ispell-local-dictionary: "american"
79 // compile-command: "scons -u test"
80 // comment-column: 40
81 // End: