5#include <Common/assertion.h>
6#include <Common/exceptions.h>
23#define PH_DECLARE_RULE_OF_5_MEMBERS_NO_DTOR(ClassType)\
25 ClassType(const ClassType& other);\
26 ClassType(ClassType&& other) noexcept;\
27 ClassType& operator = (const ClassType& rhs);\
28 ClassType& operator = (ClassType&& rhs) noexcept
33#define PH_DEFINE_RULE_OF_5_MEMBERS_NO_DTOR(ClassType)\
34 ClassType::ClassType() = default;\
35 ClassType::ClassType(const ClassType& other) = default;\
36 ClassType::ClassType(ClassType&& other) noexcept = default;\
37 ClassType& ClassType::operator = (const ClassType& rhs) = default;\
38 ClassType& ClassType::operator = (ClassType&& rhs) noexcept = default
43#define PH_DEFINE_INLINE_RULE_OF_5_MEMBERS_NO_DTOR(ClassType)\
44 inline ClassType() = default;\
45 inline ClassType(const ClassType& other) = default;\
46 inline ClassType(ClassType&& other) noexcept = default;\
47 inline ClassType& operator = (const ClassType& rhs) = default;\
48 inline ClassType& operator = (ClassType&& rhs) noexcept = default
52#define PH_DECLARE_RULE_OF_5_MEMBERS(ClassType)\
53 PH_DECLARE_RULE_OF_5_MEMBERS_NO_DTOR(ClassType);\
58#define PH_DEFINE_RULE_OF_5_MEMBERS(ClassType)\
59 PH_DEFINE_RULE_OF_5_MEMBERS_NO_DTOR(ClassType);\
60 ClassType::~ClassType() = default
64#define PH_DEFINE_INLINE_RULE_OF_5_MEMBERS(ClassType)\
65 PH_DEFINE_INLINE_RULE_OF_5_MEMBERS_NO_DTOR(ClassType);\
66 inline ~ClassType() = default
125template<
typename Target,
typename Source>
128 static_assert(std::is_trivially_copyable_v<Source>);
129 static_assert(std::is_trivially_copyable_v<Target>);
131 static_assert(
sizeof(Source) ==
sizeof(Target),
132 "Source and Target must have the same size");
134 if constexpr(std::is_same_v<Source, Target>)
140#if __cpp_lib_bit_cast
141 return std::bit_cast<Target>(source);
144 std::memcpy(&target, &source,
sizeof(Source));
156 return std::endian::native == std::endian::big;
158 static_assert(
sizeof(int) >
sizeof(
char));
160 constexpr int i = 0x07;
161 return reinterpret_cast<const char*
>(&i)[0] !=
'\x07';
165template<CEnum EnumType>
168 using ValueType = std::underlying_type_t<EnumType>;
169 return static_cast<ValueType
>(enumValue);
172template<CEnum EnumType>
178template<CEnumWithSizeInfo EnumType>
184template<
typename T, T VALUE>
217inline constexpr T& mutable_cast(
const T& value)
noexcept
219 return const_cast<T&
>(value);
223inline constexpr T* mutable_cast(
const T* value)
noexcept
225 return const_cast<T*
>(value);
229inline constexpr T* mutable_cast(T* value)
noexcept
235inline void mutable_cast(
const T&&) =
delete;
238template<
typename TypeInVariant,
typename VariantType, std::
size_t D_INDEX = 0>
239inline constexpr std::size_t variant_index_of() noexcept
241 if constexpr(D_INDEX == std::variant_size_v<VariantType>)
243 static_assert(D_INDEX < std::variant_size_v<VariantType>,
244 "`TypeInVariant` must be one of the types in variant.");
246 else if constexpr(std::is_same_v<std::variant_alternative_t<D_INDEX, VariantType>, TypeInVariant>)
252 return variant_index_of<TypeInVariant, VariantType, D_INDEX + 1>();
256template<
typename TypeInVariant,
typename InVariantType>
257inline constexpr std::size_t variant_index_of(
const InVariantType& )
noexcept
259 using VariantType = std::remove_cvref_t<InVariantType>;
261 return variant_index_of<TypeInVariant, VariantType>();
The root for all renderer implementations.
Definition EEngineProject.h:6
constexpr auto enum_size()
Definition utility.h:179
T & ref_access(T &ref)
Definition utility.h:97
std::string enum_to_string(const EnumType enumValue)
Definition utility.h:173
consteval bool is_big_endian()
Definition utility.h:153
Target bitwise_cast(const Source &source)
Definition utility.h:126
T * ptr_access(T *const ptr)
Access a target's member consistently using . or -> operators. Note that these functions treat smart ...
Definition utility.h:78
constexpr auto enum_to_value(const EnumType enumValue)
Definition utility.h:166