This commit is contained in:
ZY4N
2024-12-22 16:58:40 +01:00
parent 2704814de2
commit db8db8f9d7
161 changed files with 17102 additions and 0 deletions

63
include/util/function.hpp Executable file
View File

@@ -0,0 +1,63 @@
#pragma once
#include <tuple>
#include <concepts>
namespace ztu {
template<typename F, typename R, typename... Args>
concept callable = std::same_as<std::invoke_result_t<F, Args...>, R>;
template<typename T>
concept runnable = callable<T, void>;
template<typename T, typename R>
concept supplier = callable<T, R>;
template<typename T, typename... Args>
concept consumer = callable<T, void, Args...>;
template<typename T, typename... Args>
concept predicate = callable<T, bool, Args...>;
template<typename>
struct function_meta;
template<typename R, typename... Args>
struct function_meta<R(*)(Args...)> {
using ret_t = R;
using args_t = std::tuple<Args...>;
static constexpr bool is_const = false;
};
template<class C, typename R, typename... Args>
struct function_meta<R(C::*)(Args...)> {
using class_t = C;
using ret_t = R;
using args_t = std::tuple<Args...>;
static constexpr bool is_const = false;
};
template<class C, typename R, typename... Args>
struct function_meta<R(C::*)(Args...) const> {
using class_t = C;
using ret_t = R;
using args_t = std::tuple<Args...>;
static constexpr bool is_const = true;
};
namespace function {
template<typename F>
using class_t = typename function_meta<F>::class_t;
template<typename F>
using ret_t = typename function_meta<F>::ret_t;
template<typename F>
using args_t = typename function_meta<F>::args_t;
template<typename F>
constexpr bool is_const_v = function_meta<F>::is_const;
}
}