1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-05 21:34:57 +00:00

AK: Introduce EquivalentFunctionType

This allows you to get the type from a function from some given
callable 'T'.

Co-Authored-By: Ali Mohammad Pur <mpfard@serenityos.org>
This commit is contained in:
Shannon Booth 2024-01-26 22:41:45 +13:00 committed by Tim Flynn
parent 0e61d039c9
commit c6319d68c3

View File

@ -636,6 +636,42 @@ struct __InvokeResult<F, Args...> {
template<typename F, typename... Args>
using InvokeResult = typename __InvokeResult<F, Args...>::type;
template<typename Callable>
struct EquivalentFunctionTypeImpl;
template<template<typename> class Function, typename T, typename... Args>
struct EquivalentFunctionTypeImpl<Function<T(Args...)>> {
using Type = T(Args...);
};
template<typename T, typename... Args>
struct EquivalentFunctionTypeImpl<T(Args...)> {
using Type = T(Args...);
};
template<typename T, typename... Args>
struct EquivalentFunctionTypeImpl<T (*)(Args...)> {
using Type = T(Args...);
};
template<typename L>
struct EquivalentFunctionTypeImpl {
using Type = typename EquivalentFunctionTypeImpl<decltype(&L::operator())>::Type;
};
template<typename T, typename C, typename... Args>
struct EquivalentFunctionTypeImpl<T (C::*)(Args...)> {
using Type = T(Args...);
};
template<typename T, typename C, typename... Args>
struct EquivalentFunctionTypeImpl<T (C::*)(Args...) const> {
using Type = T(Args...);
};
template<typename Callable>
using EquivalentFunctionType = typename EquivalentFunctionTypeImpl<Callable>::Type;
}
#if !USING_AK_GLOBALLY
@ -651,6 +687,7 @@ using AK::Detail::Conditional;
using AK::Detail::CopyConst;
using AK::Detail::declval;
using AK::Detail::DependentFalse;
using AK::Detail::EquivalentFunctionType;
using AK::Detail::FalseType;
using AK::Detail::IdentityType;
using AK::Detail::IndexSequence;