mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-22 07:27:59 -05:00
add generic function helpers
This commit is contained in:
parent
db9e2ccb48
commit
659c168a14
1 changed files with 59 additions and 0 deletions
59
loader/include/Geode/utils/function.hpp
Normal file
59
loader/include/Geode/utils/function.hpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
#pragma once
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace geode::utils::function {
|
||||
namespace detail {
|
||||
template <class F>
|
||||
struct ImplExtract;
|
||||
|
||||
template <class R, class... A>
|
||||
struct ImplExtract<R(A...)> {
|
||||
using Type = R(A...);
|
||||
using Return = R;
|
||||
using Args = std::tuple<A...>;
|
||||
static constexpr std::size_t ARG_COUNT = std::tuple_size_v<Args>;
|
||||
};
|
||||
template <class R, class... A>
|
||||
struct ImplExtract<R(*)(A...)> {
|
||||
using Type = R(A...);
|
||||
using Return = R;
|
||||
using Args = std::tuple<A...>;
|
||||
static constexpr std::size_t ARG_COUNT = std::tuple_size_v<Args>;
|
||||
};
|
||||
template <class R, class C, class... A>
|
||||
struct ImplExtract<R(C::*)(A...)> {
|
||||
using Type = R(A...);
|
||||
using Class = C;
|
||||
using Return = R;
|
||||
using Args = std::tuple<A...>;
|
||||
static constexpr std::size_t ARG_COUNT = std::tuple_size_v<Args>;
|
||||
};
|
||||
template <class R, class C, class... A>
|
||||
struct ImplExtract<R(C::*)(A...) const> {
|
||||
using Type = R(A...);
|
||||
using Class = C;
|
||||
using Return = R;
|
||||
using Args = std::tuple<A...>;
|
||||
static constexpr std::size_t ARG_COUNT = std::tuple_size_v<Args>;
|
||||
};
|
||||
template <class F>
|
||||
requires requires { &F::operator(); }
|
||||
struct ImplExtract<F> : public ImplExtract<decltype(&F::operator())> {};
|
||||
|
||||
template <class F>
|
||||
using Extract = ImplExtract<std::remove_cvref_t<F>>;
|
||||
}
|
||||
|
||||
template <class F>
|
||||
using FunctionInfo = detail::Extract<F>;
|
||||
|
||||
template <class F>
|
||||
using Return = typename detail::Extract<F>::Return;
|
||||
|
||||
template <class F>
|
||||
using Args = typename detail::Extract<F>::Args;
|
||||
|
||||
template <std::size_t Ix, class F>
|
||||
using Arg = std::tuple_element_t<Ix, typename detail::Extract<F>::Args>;
|
||||
}
|
Loading…
Reference in a new issue