Mjolnir Core
Core functionality of the Mjolnir API
type.h
Go to the documentation of this file.
1 
7 
8 #pragma once
9 
10 
11 // === DECLARATIONS ===================================================================================================
12 
15 #include <type_traits>
16 
17 #include <concepts>
18 
19 namespace mjolnir
20 {
23 
24 
42 template <typename T_Type, typename T_OtherType, typename... T_TypeList>
43 [[nodiscard]] consteval auto is_any_of() noexcept -> bool;
44 
45 
60 template <std::integral T_Type>
61 [[nodiscard]] constexpr auto signed_to_unsigned(T_Type value) -> EquallySizedUnsignedType<T_Type>;
62 
63 
65 } // namespace mjolnir
66 
67 
68 // === DEFINITIONS ====================================================================================================
69 
70 
71 namespace mjolnir
72 {
73 // --------------------------------------------------------------------------------------------------------------------
74 
75 
76 template <typename T_Type, typename T_OtherType, typename... T_TypeList>
77 [[nodiscard]] consteval auto is_any_of() noexcept -> bool
78 {
79  if constexpr (! std::is_same_v<T_Type, T_OtherType>)
80  {
81  if constexpr (sizeof...(T_TypeList) != 0)
82  return is_any_of<T_Type, T_TypeList...>();
83  else
84  return false;
85  }
86  else
87  return true;
88 }
89 
90 
91 // --------------------------------------------------------------------------------------------------------------------
92 
93 template <std::integral T_Type>
94 [[nodiscard]] constexpr auto signed_to_unsigned(T_Type value) -> EquallySizedUnsignedType<T_Type>
95 {
96  if constexpr (std::is_signed_v<T_Type>)
97  return static_cast<EquallySizedUnsignedType<T_Type>>(value);
98  else
99  return value;
100 }
101 
102 } // namespace mjolnir
Contains some basic definitions and concepts that are frequently needed.
Defines the fundamental data types.
consteval auto is_any_of() noexcept -> bool
Return true if the tested type is identical to any of a list of types.
Definition: type.h:77
constexpr auto signed_to_unsigned(T_Type value) -> EquallySizedUnsignedType< T_Type >
Cast an integer to an equally sized unsigned type.
Definition: type.h:94
typename std::conditional_t< std::is_unsigned_v< T_Type >, T_Type, std::conditional_t< std::is_same_v< T_Type, IPT >, UPT, std::conditional_t< sizeof(T_Type)==1, U8, std::conditional_t< sizeof(T_Type)==2, U16, std::conditional_t< sizeof(T_Type)==4, U32, U64 > >> >> EquallySizedUnsignedType
Unsigned integer type with the same size as the reference type.
Definition: definitions.h:32