IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
enum_bools.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/types.hxx>
6#include <type_traits>
7
8namespace ice
9{
10
11 template<typename T>
12 struct BoolLogic
13 {
14 static constexpr bool IsEnabled = std::is_enum_v<T> && (sizeof(T) == 1);
15 };
16
17 template<typename T>
18 concept BoolType = BoolLogic<T>::IsEnabled && requires(T) {
19 { T::Off } -> std::convertible_to<T>;
20 { T::On } -> std::convertible_to<T>;
21 static_cast<std::underlying_type_t<T>>(T::Off) == 0;
22 static_cast<std::underlying_type_t<T>>(T::On) == 1;
23 };
24
25 // template<ice::BoolType T>
26 // constexpr bool operator==(T left, bool_t right) noexcept
27 // {
28 // auto const left_value = static_cast<std::underlying_type_t<T>>(left);
29 // return left_value == right;
30 // }
31
32 // template<ice::BoolType T>
33 // constexpr bool operator!=(T left, bool_t right) noexcept
34 // {
35 // auto const left_value = static_cast<std::underlying_type_t<T>>(left);
36 // return left_value != right;
37 // }
38
39 template<ice::BoolType T>
40 constexpr auto operator!(T left) noexcept -> T
41 {
42 auto const left_value = static_cast<std::underlying_type_t<T>>(left);
43 return static_cast<T>(!left_value);
44 }
45
46
48 {
49
50 enum class FailTest : ice::u8 { Off, On };
51
52 static_assert(bool(FailTest::Off) == false);
53 static_assert(bool(FailTest::On) == true);
54 static_assert(bool(FailTest::Off) != true);
55 static_assert(bool(FailTest::On) != false);
56 static_assert(bool(!FailTest::Off) == true);
57 static_assert(bool(!FailTest::On) == false);
58
59 } // namespace detail::internal::static_unit_tests
60
61} // namespace ice
Definition enum_bools.hxx:18
Definition enum_bools.hxx:48
FailTest
Definition enum_bools.hxx:50
SPDX-License-Identifier: MIT.
Definition array.hxx:12
constexpr auto operator!(T left) noexcept -> T
Definition enum_bools.hxx:40
std::uint8_t u8
Definition types.hxx:24
Definition enum_bools.hxx:13
static constexpr bool IsEnabled
Definition enum_bools.hxx:14