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
26namespace ice
27{
28
29 using std::min;
30 using std::max;
31 using std::abs;
32
33 using std::swap;
34 using std::move;
35 using std::forward;
36 using std::exchange;
37 using std::memcpy;
38 using std::memset;
39 using std::addressof;
40 using std::bit_cast;
41
42 template<typename T, ice::u32 Size>
43 constexpr auto count(T const (&)[Size]) noexcept -> ice::u32
44 {
45 return Size;
46 }
47
48 template<typename T, typename U = T> requires (std::convertible_to<U, T>)
49 constexpr auto value_or_default(T value, U default_value) noexcept -> T = delete;
50
51 template<typename T, typename U = T> requires (std::convertible_to<U*, T*>)
52 constexpr auto value_or_default(T* value, U* default_value) noexcept -> T*
53 {
54 return value != nullptr ? value : default_value;
55 }
56
57 template<typename T, typename U = T> requires (std::convertible_to<U, T> && std::is_arithmetic_v<T>)
58 constexpr auto value_or_default(T value, U&& default_value) noexcept -> T
59 {
60 return value != nullptr ? value : static_cast<T>(ice::forward<U>(default_value));
61 }
62
63 template<typename T>
64 using clear_type_t = std::remove_pointer_t<std::remove_reference_t<std::remove_cv_t<T>>>;
65
66 template<typename T>
68
69 template<typename T>
70 constexpr auto to_const(T* value) noexcept -> T const*
71 {
72 return const_cast<T const*>(value);
73 }
74
75 template<typename T, typename = void>
76 constexpr bool is_type_complete = false;
77
78 template<typename T>
79 constexpr bool is_type_complete<T, std::void_t<decltype(sizeof(T))>> = true;
80
81
82 template<typename Member>
84 {
85 static constexpr ice::u8 member_type = 0;
86 };
87
88 template<typename Class, typename Ret, typename... Args>
89 struct member_info<Ret(Class::*)(Args...)>
90 {
91 static constexpr ice::u8 member_type = 1;
92 using class_type = Class;
93 using result_type = Ret;
94
95 static constexpr ice::u8 argument_count = sizeof...(Args);
96 using argument_types = std::tuple<Args...>;
97 };
98
99 template<typename Class, typename Ret, typename... Args>
100 struct member_info<Ret(Class::*)(Args...) noexcept>
101 {
102 static constexpr ice::u8 member_type = 1;
103 using class_type = Class;
104 using result_type = Ret;
105
106 static constexpr ice::u8 argument_count = sizeof...(Args);
107 using argument_types = std::tuple<Args...>;
108 };
109
110 template<typename Class, typename Value>
111 struct member_info<Value Class::*>
112 {
113 static constexpr ice::u8 member_type = 2;
114 using class_type = Class;
115 using result_type = Value;
116 };
117
118 template<typename Member>
120
121 template<typename Member>
123
124 template<typename Member, ice::u64 Idx>
125 using member_arg_type_t = std::tuple_element_t<Idx, typename member_info<Member>::argument_types>;
126
127 template<typename Member>
129
130 template<typename Member>
132
133} // namespace ice
SPDX-License-Identifier: MIT.
Definition array.hxx:12
typename member_info< Member >::result_type member_result_type_t
Definition base.hxx:122
std::remove_pointer_t< std::remove_reference_t< std::remove_cv_t< T > > > clear_type_t
Definition base.hxx:64
constexpr bool is_type_complete
Definition base.hxx:76
typename member_info< Member >::class_type member_class_type_t
Definition base.hxx:119
constexpr bool is_method_member_v
Definition base.hxx:128
constexpr auto value_or_default(T value, U default_value) noexcept -> T=delete
constexpr auto to_const(T *value) noexcept -> T const *
Definition base.hxx:70
constexpr auto count(T const (&)[Size]) noexcept -> ice::u32
Definition base.hxx:43
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:125
clear_type_t< T > clean_type
Definition base.hxx:67
constexpr bool is_field_member_v
Definition base.hxx:131
std::uint8_t u8
Definition types.hxx:24
static constexpr ice::u8 argument_count
Definition base.hxx:106
std::tuple< Args... > argument_types
Definition base.hxx:107
static constexpr ice::u8 member_type
Definition base.hxx:102
static constexpr ice::u8 argument_count
Definition base.hxx:95
Ret result_type
Definition base.hxx:93
Class class_type
Definition base.hxx:92
static constexpr ice::u8 member_type
Definition base.hxx:91
std::tuple< Args... > argument_types
Definition base.hxx:96
Class class_type
Definition base.hxx:114
Value result_type
Definition base.hxx:115
static constexpr ice::u8 member_type
Definition base.hxx:113
Definition base.hxx:84
static constexpr ice::u8 member_type
Definition base.hxx:85