MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Traits.h
Go to the documentation of this file.
1/** @noop License Comment
2 * @file
3 * @copyright
4 * This Source Code is subject to the terms of the Mozilla Public License, v2.0.
5 * If a copy of the MPL was not distributed with this file You can obtain one at
6 * https://mozilla.org/MPL/2.0/
7 *
8 * @author David Mórász
9 * @date 2025
10 */
11
12#pragma once
13
14#include "CoreMinimal.h"
15#include "Mcro/FunctionTraits.h"
16#include "Mcro/Void.h"
17#include "Mcro/Tuples.h"
18
19namespace Mcro::Delegates
20{
21 using namespace Mcro::FunctionTraits;
22 using namespace Mcro::Tuples;
23
24 /**
25 * @brief
26 * Infer a delegate type from an input function signature and a list of captures.
27 *
28 * The resulting delegate signature will trim the "Captures" from the input function signature. This is used in
29 * `From` overloads to allow binding functions with extra arguments to a delegate which has fewer (as the vanilla
30 * Unreal delegates API allows to do so)
31 */
32 template <CFunctionLike Function, typename... Captures>
33 using TInferredDelegate = TDelegate<
36 TTrimEnd<sizeof...(Captures), TFunction_Arguments<Function>>
37 >,
38 FDefaultDelegateUserPolicy
39 >
40 ;
41
42 /** @brief Constraint given type to a dynamic delegate class */
43 template <typename T>
45 requires() { typename std::decay_t<T>::ThreadSafetyMode; }
46 && CDerivedFrom<std::decay_t<T>, TScriptDelegate<typename std::decay_t<T>::ThreadSafetyMode>>
47 ;
48
49 /** @brief Constraint given type to a dynamic multicast delegate class */
50 template <typename T>
52 requires() { typename std::decay_t<T>::ThreadSafetyMode; }
53 && CDerivedFrom<std::decay_t<T>, TMulticastScriptDelegate<typename std::decay_t<T>::ThreadSafetyMode>>
54 ;
55
56 template <typename>
58
59 template <CDynamicDelegate Dynamic>
60 struct TDynamicMethodPtr_Struct<Dynamic>
61 {
62 using Type = typename Dynamic::template TMethodPtrResolver<FDeclareOnly>::FMethodPtr;
63 };
64
65 template <CDynamicMulticastDelegate Dynamic>
70
71 /** @brief Get the native function pointer type compatible with given dynamic (multicast) delegate */
72 template <typename Dynamic>
74
75 template <typename>
77
78 template <CDynamicDelegate Dynamic>
79 struct TDynamicSignature_Struct<Dynamic>
80 {
82 };
83
84 template <CDynamicMulticastDelegate Dynamic>
89
90 /**@brief Get the native function signature type compatible with given dynamic (multicast) delegate */
91 template <typename Dynamic>
93
94 template <typename>
95 struct TNative_Struct {};
96
97 template <CDynamicDelegate Dynamic>
98 struct TNative_Struct<Dynamic>
99 {
100 using Type = TDelegate<TDynamicSignature<Dynamic>, FDefaultDelegateUserPolicy>;
101 };
102
103 template <CDynamicMulticastDelegate Dynamic>
104 struct TNative_Struct<Dynamic>
105 {
106 using Type = TMulticastDelegate<TDynamicSignature<Dynamic>, FDefaultDelegateUserPolicy>;
107 };
108
109 /** @brief Map the input dynamic (multicast) delegate to a conceptually compatible native (multicast) delegate type */
110 template<typename Dynamic>
112}
These two are the most useful types in the arsenal of the C++ developer. Use these for dummy types or...
Constraint given type to a dynamic delegate class.
Definition Traits.h:44
Constraint given type to a dynamic multicast delegate class.
Definition Traits.h:51
typename TNative_Struct< std::decay_t< Dynamic > >::Type TNative
Map the input dynamic (multicast) delegate to a conceptually compatible native (multicast) delegate t...
Definition Traits.h:111
typename TDynamicSignature_Struct< std::decay_t< Dynamic > >::Type TDynamicSignature
Get the native function signature type compatible with given dynamic (multicast) delegate.
Definition Traits.h:92
TDelegate< TFunctionFromTuple< TFunction_Return< Function >, TTrimEnd< sizeof...(Captures), TFunction_Arguments< Function > > >, FDefaultDelegateUserPolicy > TInferredDelegate
Infer a delegate type from an input function signature and a list of captures.
Definition Traits.h:33
typename TDynamicMethodPtr_Struct< std::decay_t< Dynamic > >::Type TDynamicMethodPtr
Get the native function pointer type compatible with given dynamic (multicast) delegate.
Definition Traits.h:73
typename TFunctionTraits< std::decay_t< T > >::Return TFunction_Return
Shorthand for getting a function return type.
typename TFunctionTraits< std::decay_t< T > >::Signature TFunction_Signature
Shorthand for getting a pur function signature.
typename Detail::TFunctionFromTuple_Struct< Return, std::decay_t< Tuple > >::Type TFunctionFromTuple
Compose a function type from a tuple of arguments and a return type.
typename TFunctionTraits< std::decay_t< T > >::Arguments TFunction_Arguments
Shorthand for getting a tuple representing the function arguments.
Templating utilities for manipulating TTuples.
Definition Tuples.h:24
typename TTrimEnd_Struct< Count, Tuple >::Type TTrimEnd
Disregard the last Count elements of the input tuple.
Definition Tuples.h:195
typename Dynamic::template TMethodPtrResolver< FDeclareOnly >::FMethodPtr Type
Definition Traits.h:62
TFunction_Signature< TDynamicMethodPtr< Dynamic > > Type
Definition Traits.h:81
TDelegate< TDynamicSignature< Dynamic >, FDefaultDelegateUserPolicy > Type
Definition Traits.h:100