-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy patharrayutils.hpp
48 lines (40 loc) · 1.86 KB
/
arrayutils.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#include "System/Object.hpp"
#include "System/Type.hpp"
namespace Lapiz::ArrayUtils {
template<typename T>
requires(std::is_convertible<T, System::Object*>::value || std::is_arithmetic<T>::value)
static inline void box_array(ArrayW<System::Object*> arr, int index, T val) {
if constexpr (std::is_pointer_v<T>) arr[index] = val;
else arr[index] = il2cpp_functions::value_box(classof(T), &val);
}
template <typename First, typename... Rest>
requires(std::is_convertible<First, System::Object*>::value || std::is_arithmetic<First>::value)
static inline void box_array(ArrayW<System::Object*> arr, int index, First& first, Rest&... rest) {
if constexpr (std::is_pointer_v<First>) arr[index] = first;
else arr[index] = il2cpp_functions::value_box(classof(First), &first);
box_array(arr, ++index, rest...);
}
template <typename First, typename... Rest>
requires(std::is_convertible<First, System::Object*>::value || std::is_arithmetic<First>::value)
static inline void box_array(ArrayW<System::Object*> arr, First& first, Rest&... rest) {
box_array(arr, 0, first, rest...);
}
template<typename... Targs>
static inline ArrayW<System::Object*> box_array(Targs&... rest) {
auto res = ArrayW<System::Object*>(sizeof...(rest));
box_array(res, rest...);
return res;
}
template<typename T, typename... Targs>
static void inline SetIndexType(ArrayW<System::Type*> arr, int index) {
arr[index] = csTypeOf(T);
if constexpr (sizeof...(Targs) > 0) SetIndexType<Targs...>(arr, ++index);
}
template<typename... Targs>
static inline ArrayW<System::Type*> TypeArray() {
auto res = ArrayW<System::Type*>(sizeof...(Targs));
if constexpr (sizeof...(Targs) > 0) SetIndexType<Targs...>(res, 0);
return res;
}
}