DxLibEx
coordinate_operator_bool_helper.hpp
Go to the documentation of this file.
1 #ifndef DXLE_INC_BASIC_TYPES_COORDINATE_OPERATOR_BOOL_HELPER_HPP_
2 #define DXLE_INC_BASIC_TYPES_COORDINATE_OPERATOR_BOOL_HELPER_HPP_
7 namespace dxle {
8  namespace detail {
9  //operator bool
10  //1. operator bool
11  //2. operator != (nullptr)
12  //3. default constector + operator !=
13 
14  template <
15  typename T,
16  bool has_operator_bool = !std::is_scalar<T>::value && is_castable<T, bool>::value,
17  bool has_operator_notequal_to_zero = has_operator_notequal_to_zero<const T>::value,
18  bool is_compareable_with_default_ctor = std::is_default_constructible<T>::value && has_operator_notequal_to_this<T>::value
19  >
21  //1. operator bool
22  template<typename T, bool has_operator_notequal_to_zero, bool is_compareable_with_default_ctor>
23  struct operator_bool_helper_impl<T, true, has_operator_notequal_to_zero, is_compareable_with_default_ctor> {
24  DXLE_CONSTEXPR bool operator()(const T& first, const T& second) const DXLE_NOEXCEPT_IF_EXPR(static_cast<bool>(first)) {
25  return static_cast<bool>(first) || static_cast<bool>(second);
26  }
27  DXLE_CONSTEXPR bool operator()(const T& first, const T& second, const T& third) const DXLE_NOEXCEPT_IF_EXPR(static_cast<bool>(first)) {
28  return static_cast<bool>(first) || static_cast<bool>(second) || static_cast<bool>(third);
29  }
30  };
31  //2. operator != (nullptr)
32  template<typename T, bool is_compareable_with_default_ctor>
33  struct operator_bool_helper_impl<T, false, true, is_compareable_with_default_ctor> {
34  DXLE_CONSTEXPR bool operator()(const T& first, const T& second) const DXLE_NOEXCEPT_IF_EXPR(first != 0) {
35  return first != 0 || second != 0;
36  }
37  DXLE_CONSTEXPR bool operator()(const T& first, const T& second, const T& third) const DXLE_NOEXCEPT_IF_EXPR(first != 0) {
38  return first != 0 || second != 0 || third != 0;
39  }
40  };
41  //3. default constector + operator !=
42  template<typename T>
43  struct operator_bool_helper_impl<T, false, false, true> {
44  DXLE_CONSTEXPR bool operator()(const T& first, const T& second) const DXLE_NOEXCEPT_IF_EXPR(first != T{}) {
45  return first != T{} || second != T{};
46  }
47  DXLE_CONSTEXPR bool operator()(const T& first, const T& second, const T& third) const DXLE_NOEXCEPT_IF_EXPR(first != T{}) {
48  return first != T{} || second != T{} || third != T{};
49  }
50  };
51 
52  template<typename T, enable_if_t<std::is_arithmetic<T>::value, nullptr_t> = nullptr>
53  DXLE_CONSTEXPR inline bool operator_bool_helper(const T& first, const T& second)
55  {
56  return dxle::detail::operator_bool_helper_impl<T>()(first, second);
57  }
58  template<typename T, enable_if_t<std::is_arithmetic<T>::value, nullptr_t> = nullptr>
59  DXLE_CONSTEXPR inline bool operator_bool_helper(const T& first, const T& second, const T& third)
61  {
62  return dxle::detail::operator_bool_helper_impl<T>()(first, second, third);
63  }
64  }
65 }
66 #endif //DXLE_INC_BASIC_TYPES_COORDINATE_OPERATOR_BOOL_HELPER_HPP_
DXLE_CONSTEXPR bool operator()(const T &first, const T &second) const DXLE_NOEXCEPT_IF_EXPR(static_cast< bool >(first))
#define DXLE_CONSTEXPR
Definition: suffix.hpp:21
DXLE_CONSTEXPR bool operator_bool_helper(const T &first, const T &second) DXLE_NOEXCEPT_IF_EXPR(dxle
Definition: cast_if.hpp:12
DXLE_CONSTEXPR bool operator()(const T &first, const T &second) const DXLE_NOEXCEPT_IF_EXPR(first !=0)
#define DXLE_NOEXCEPT_IF_EXPR(EXPR)
Definition: suffix.hpp:110
DXLE_CONSTEXPR bool operator()(const T &first, const T &second, const T &third) const DXLE_NOEXCEPT_IF_EXPR(first !=0)
DXLE_CONSTEXPR bool operator()(const T &first, const T &second, const T &third) const DXLE_NOEXCEPT_IF_EXPR(static_cast< bool >(first))