geode/loader/include/Geode/meta/function.hpp

37 lines
986 B
C++
Raw Normal View History

2022-07-30 12:24:03 -04:00
#ifndef GEODE_CORE_META_FUNCTION_HPP
#define GEODE_CORE_META_FUNCTION_HPP
#include "callconv.hpp"
#include "common.hpp"
#include "tuple.hpp"
#include <type_traits>
namespace geode::core::meta {
/* The Geode Function class wraps functions with unconventional
* calling conventions (how ironic).
*/
template <class Func, template <class, class...> class Conv>
class Function {
static_assert(always_false<Func>, "Not a valid function pointer!");
};
template <class Ret, class... Args, template <class, class...> class Conv>
class Function<Ret(Args...), Conv> {
private:
using MyConv = Conv<Ret, Args...>;
private:
void* addr;
public:
template <class Pointer>
2022-10-30 14:59:20 -04:00
Function(Pointer const& addr) : addr(reinterpret_cast<void*>(addr)) {}
2022-07-30 12:24:03 -04:00
decltype(auto) operator()(Args... all) const {
return MyConv::invoke(addr, all...);
}
};
}
#endif /* GEODE_CORE_META_FUNCTION_HPP */