IceShard
1
A personal game engine project, with development focused on 2D/2.5D games.
Toggle main menu visibility
Loading...
Searching...
No Matches
core
public
ice
concept
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
8
namespace
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
47
namespace
detail::internal::static_unit_tests
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
ice::BoolType
Definition
enum_bools.hxx:18
ice::detail::internal::static_unit_tests
Definition
enum_bools.hxx:48
ice::detail::internal::static_unit_tests::FailTest
FailTest
Definition
enum_bools.hxx:50
ice::detail::internal::static_unit_tests::FailTest::On
@ On
Definition
enum_bools.hxx:50
ice::detail::internal::static_unit_tests::FailTest::Off
@ Off
Definition
enum_bools.hxx:50
ice
SPDX-License-Identifier: MIT.
Definition
array.hxx:12
ice::operator!
constexpr auto operator!(T left) noexcept -> T
Definition
enum_bools.hxx:40
ice::u8
std::uint8_t u8
Definition
types.hxx:24
ice::BoolLogic
Definition
enum_bools.hxx:13
ice::BoolLogic::IsEnabled
static constexpr bool IsEnabled
Definition
enum_bools.hxx:14
types.hxx
Generated by
1.18.0