IceShard 1
A personal game engine project, with development focused on 2D/2.5D games.
Loading...
Searching...
No Matches
base.hxx
Go to the documentation of this file.
1
3
4#pragma once
5#include <ice/types.hxx>
7#include <ice/constants.hxx>
8#include <ice/workarounds.hxx>
9#include <ice/build/build.hxx>
10#include <ice/assert_core.hxx>
11#include <ice/utility.hxx>
12#include <ice/hash.hxx>
13
17
18#include <ice/error.hxx>
19#include <ice/error_codes.hxx>
20
21#include <algorithm>
22#include <cstring>
23#include <utility>
24#include <bit>
25
27namespace ice
28{
29
30 using std::min;
31 using std::max;
32 using std::abs;
33
34 using std::swap;
35 using std::move;
36 using std::forward;
37 using std::exchange;
38 using std::memcpy;
39 using std::memset;
40 using std::addressof;
41 using std::bit_cast;
42
51 template<typename T, ice::u32 Size>
52 constexpr auto count(T const (&)[Size]) noexcept -> ice::u32
53 {
54 return Size;
55 }
56
68 template<typename T, typename U = T> requires (std::convertible_to<U, T>)
69 constexpr auto value_or_default(T value, U default_value) noexcept -> T = delete;
70
71 template<typename T, typename U = T> requires (std::convertible_to<U*, T*>)
72 constexpr auto value_or_default(T* value, U* default_value) noexcept -> T*
73 {
74 return value != nullptr ? value : default_value;
75 }
76
77 template<typename T, typename U = T> requires (std::convertible_to<U, T> && std::is_arithmetic_v<T>)
78 constexpr auto value_or_default(T value, U&& default_value) noexcept -> T
79 {
80 return value != nullptr ? value : static_cast<T>(ice::forward<U>(default_value));
81 }
82
83 template<typename T>
84 using clear_type_t = std::remove_pointer_t<std::remove_reference_t<std::remove_cv_t<T>>>;
85
86 template<typename T>
88
91 template<typename T>
92 constexpr auto to_const(T* value) noexcept -> T const*
93 {
94 return const_cast<T const*>(value);
95 }
96
98 template<typename T, typename = void>
99 constexpr bool is_type_complete = false;
100
101 template<typename T>
102 constexpr bool is_type_complete<T, std::void_t<decltype(sizeof(T))>> = true;
103
119 template<typename Member>
121 {
123 static constexpr ice::u8 member_type = 0;
124 };
125
126 template<typename Class, typename Ret, typename... Args>
127 struct member_info<Ret(Class::*)(Args...)>
128 {
129 static constexpr ice::u8 member_type = 1;
130
132 using class_type = Class;
133
135 using result_type = Ret;
136
138 static constexpr ice::u8 argument_count = sizeof...(Args);
139
141 using argument_types = std::tuple<Args...>;
142 };
143
144 template<typename Class, typename Ret, typename... Args>
145 struct member_info<Ret(Class::*)(Args...) noexcept>
146 {
147 static constexpr ice::u8 member_type = 1;
148
149 using class_type = Class;
150 using result_type = Ret;
151
152 static constexpr ice::u8 argument_count = sizeof...(Args);
153 using argument_types = std::tuple<Args...>;
154 };
155
156 template<typename Class, typename Value>
157 struct member_info<Value Class::*>
158 {
159 static constexpr ice::u8 member_type = 2;
160
162 using class_type = Class;
163
165 using result_type = Value;
166 };
167
168 template<typename Member>
170
171 template<typename Member>
173
174 template<typename Member, ice::u64 Idx>
175 using member_arg_type_t = std::tuple_element_t<Idx, typename member_info<Member>::argument_types>;
176
177 template<typename Member>
179
180 template<typename Member>
182
183} // namespace ice
Root namespace for all APIs part of the IceShard engine project.
Definition array.hxx:12
typename member_info< Member >::result_type member_result_type_t
Definition base.hxx:172
std::remove_pointer_t< std::remove_reference_t< std::remove_cv_t< T > > > clear_type_t
Definition base.hxx:84
constexpr bool is_type_complete
Compile-time check returning true or false depending if a types definition is considered complete.
Definition base.hxx:99
typename member_info< Member >::class_type member_class_type_t
Definition base.hxx:169
constexpr bool is_method_member_v
Definition base.hxx:178
constexpr auto value_or_default(T value, U default_value) noexcept -> T=delete
Utility function to check "truthienes" of a value and return its value or a provided default if consi...
constexpr auto to_const(T *value) noexcept -> T const *
Adds const property to the value protion of the given pointer type.
Definition base.hxx:92
constexpr auto count(T const (&)[Size]) noexcept -> ice::u32
Utility function to access number of elements of a typed C array.
Definition base.hxx:52
std::uint32_t u32
Definition types.hxx:26
std::tuple_element_t< Idx, typename member_info< Member >::argument_types > member_arg_type_t
Definition base.hxx:175
clear_type_t< T > clean_type
Definition base.hxx:87
constexpr bool is_field_member_v
Definition base.hxx:181
std::uint8_t u8
Definition types.hxx:24
static constexpr ice::u8 argument_count
Definition base.hxx:152
std::tuple< Args... > argument_types
Definition base.hxx:153
static constexpr ice::u8 member_type
Definition base.hxx:147
static constexpr ice::u8 argument_count
Number of arguments.
Definition base.hxx:138
Ret result_type
Return type.
Definition base.hxx:135
Class class_type
Class type.
Definition base.hxx:132
static constexpr ice::u8 member_type
Definition base.hxx:129
std::tuple< Args... > argument_types
Tuple of all arguments types.
Definition base.hxx:141
Class class_type
Class type.
Definition base.hxx:162
Value result_type
Field type.
Definition base.hxx:165
static constexpr ice::u8 member_type
Definition base.hxx:159
Compile-time utility type to access various information about C++ type members.
Definition base.hxx:121
static constexpr ice::u8 member_type
Category of the passed Member type. (1 => method, 2 => field, 0 => invalid / not a member type).
Definition base.hxx:123