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

67 lines
1.6 KiB
C++
Raw Normal View History

2022-07-30 12:24:03 -04:00
#pragma once
#include <type_traits>
#include <Geode/meta/common.hpp>
namespace geode::modifier {
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-10-13 04:31:23 -04:00
using ::geode::core::meta::always_false;
2022-07-30 12:24:03 -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;
}
template <class FunctionType, class Class>
constexpr auto substitute(typename ConstMemberFunc<FunctionType>::template with<Class> function) {
return function;
}
template <class FunctionType>
constexpr auto substitute(typename StaticFunc<FunctionType>::type function) {
return function;
}
/**
* An UUID system that generates an unique comparable
* value for every instance. Internally used for comparing member
* function pointers.
*/
template <auto a>
struct function_uuid {
private:
constexpr static void function() {}
public:
constexpr static inline void(*value)() = &function_uuid::function;
};
}