geode/loader/include/Geode/modify/Traits.hpp

69 lines
1.8 KiB
C++
Raw Normal View History

2022-07-30 12:24:03 -04:00
#pragma once
#include <Geode/meta/common.hpp>
2022-10-30 14:59:20 -04:00
#include <type_traits>
2022-07-30 12:24:03 -04:00
namespace geode::modifier {
2022-10-30 14:59:20 -04:00
template <class FunctionType>
struct MemberFunc {
template <class Class>
using with = FunctionType Class::*;
};
template <class FunctionType>
struct ConstMemberFunc {
template <class Class>
using with = FunctionType Class::*;
};
// why
template <class Return, class... Parameters>
struct ConstMemberFunc<Return(Parameters...)> {
using FunctionType = Return(Parameters...) const;
template <class Class>
using with = FunctionType Class::*;
};
template <class FunctionType>
struct StaticFunc {
using type = FunctionType*;
};
2022-07-30 12:24:03 -04:00
2022-10-30 14:59:20 -04:00
using ::geode::core::meta::always_false;
2022-07-30 12:24:03 -04:00
2022-10-30 14:59:20 -04:00
/**
* The ~unevaluated~ function that gets the appropriate
* version of a function type from its return, parameters, and classes.
*
* nvm its no more unevaluated
*/
template <class FunctionType, class Class>
constexpr auto substitute(typename MemberFunc<FunctionType>::template with<Class> function) {
return function;
}
2022-07-30 12:24:03 -04:00
2022-10-30 14:59:20 -04:00
template <class FunctionType, class Class>
constexpr auto substitute(typename ConstMemberFunc<FunctionType>::template with<Class> function
) {
return function;
}
2022-07-30 12:24:03 -04:00
2022-10-30 14:59:20 -04:00
template <class FunctionType>
constexpr auto substitute(typename StaticFunc<FunctionType>::type function) {
return function;
}
2022-07-30 12:24:03 -04:00
2022-10-30 14:59:20 -04:00
/**
* An UUID system that generates an unique comparable
* value for every instance. Internally used for comparing member
* function pointers.
*/
template <auto a>
2022-12-12 10:42:56 -05:00
struct FunctionUUID {
2022-10-30 14:59:20 -04:00
private:
constexpr static void function() {}
2022-07-30 12:24:03 -04:00
2022-10-30 14:59:20 -04:00
public:
2022-12-12 10:42:56 -05:00
constexpr static inline void (*value)() = &FunctionUUID::function;
2022-10-30 14:59:20 -04:00
};
2022-07-30 12:24:03 -04:00
}