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:
parent
0e61d039c9
commit
c6319d68c3
Notes:
sideshowbarker
2024-07-17 02:56:25 +09:00
Author: https://github.com/shannonbooth Commit: https://github.com/SerenityOS/serenity/commit/c6319d68c3 Pull-request: https://github.com/SerenityOS/serenity/pull/22946 Reviewed-by: https://github.com/trflynn89 ✅
1 changed files with 37 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue