From 659c168a14347aa8c718dfd472008effed4c90b5 Mon Sep 17 00:00:00 2001 From: HJfod <60038575+HJfod@users.noreply.github.com> Date: Sat, 31 Aug 2024 21:35:41 +0300 Subject: [PATCH] add generic function helpers --- loader/include/Geode/utils/function.hpp | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 loader/include/Geode/utils/function.hpp diff --git a/loader/include/Geode/utils/function.hpp b/loader/include/Geode/utils/function.hpp new file mode 100644 index 00000000..855f1951 --- /dev/null +++ b/loader/include/Geode/utils/function.hpp @@ -0,0 +1,59 @@ +#pragma once + +#include + +namespace geode::utils::function { + namespace detail { + template + struct ImplExtract; + + template + struct ImplExtract { + using Type = R(A...); + using Return = R; + using Args = std::tuple; + static constexpr std::size_t ARG_COUNT = std::tuple_size_v; + }; + template + struct ImplExtract { + using Type = R(A...); + using Return = R; + using Args = std::tuple; + static constexpr std::size_t ARG_COUNT = std::tuple_size_v; + }; + template + struct ImplExtract { + using Type = R(A...); + using Class = C; + using Return = R; + using Args = std::tuple; + static constexpr std::size_t ARG_COUNT = std::tuple_size_v; + }; + template + struct ImplExtract { + using Type = R(A...); + using Class = C; + using Return = R; + using Args = std::tuple; + static constexpr std::size_t ARG_COUNT = std::tuple_size_v; + }; + template + requires requires { &F::operator(); } + struct ImplExtract : public ImplExtract {}; + + template + using Extract = ImplExtract>; + } + + template + using FunctionInfo = detail::Extract; + + template + using Return = typename detail::Extract::Return; + + template + using Args = typename detail::Extract::Args; + + template + using Arg = std::tuple_element_t::Args>; +}