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 "Misc/EngineVersionComparison.h"
16#include "Mcro/FunctionTraits.h"
17#include "Mcro/Void.h"
18#include "Mcro/Tuples.h"
19
20namespace Mcro::Delegates
21{
22 using namespace Mcro::FunctionTraits;
23 using namespace Mcro::Tuples;
24
25 /**
26 * @brief
27 * Infer a delegate type from an input function signature and a list of captures.
28 *
29 * The resulting delegate signature will trim the "Captures" from the input function signature. This is used in
30 * `From` overloads to allow binding functions with extra arguments to a delegate which has fewer (as the vanilla
31 * Unreal delegates API allows to do so)
32 */
33 template <CFunctionLike Function, typename... Captures>
34 using TInferredDelegate = TDelegate<
38 >,
39 FDefaultDelegateUserPolicy
40 >
41 ;
42
43 /** @brief Constraint given type to a dynamic delegate class */
44 template <typename T>
46 requires() { typename std::decay_t<T>::ThreadSafetyMode; }
47 && CDerivedFrom<std::decay_t<T>, TScriptDelegate<typename std::decay_t<T>::ThreadSafetyMode>>
48 ;
49
50 /** @brief Constraint given type to a dynamic multicast delegate class */
51 template <typename T>
53 requires() { typename std::decay_t<T>::ThreadSafetyMode; }
54 && CDerivedFrom<std::decay_t<T>, TMulticastScriptDelegate<typename std::decay_t<T>::ThreadSafetyMode>>
55 ;
56
57 template <typename>
59
60 template <CDynamicDelegate Dynamic>
61 struct TDynamicMethodPtr_Struct<Dynamic>
62 {
63#if UE_VERSION_OLDER_THAN(5, 8, 0)
64 using Type = typename Dynamic::template TMethodPtrResolver<FDeclareOnly>::FMethodPtr;
65#else
66 // UE 5.8 added a leading `bool bConst` non-type parameter to TMethodPtrResolver.
67 using Type = typename Dynamic::template TMethodPtrResolver<false, FDeclareOnly>::FMethodPtr;
68#endif
69 };
70
71 template <CDynamicMulticastDelegate Dynamic>
76
77 /** @brief Get the native function pointer type compatible with given dynamic (multicast) delegate */
78 template <typename Dynamic>
80
81 template <typename>
83
84 template <CDynamicDelegate Dynamic>
85 struct TDynamicSignature_Struct<Dynamic>
86 {
88 };
89
90 template <CDynamicMulticastDelegate Dynamic>
95
96 /**@brief Get the native function signature type compatible with given dynamic (multicast) delegate */
97 template <typename Dynamic>
99
100 template <typename>
101 struct TNative_Struct {};
102
103 template <CDynamicDelegate Dynamic>
104 struct TNative_Struct<Dynamic>
105 {
106 using Type = TDelegate<TDynamicSignature<Dynamic>, FDefaultDelegateUserPolicy>;
107 };
108
109 template <CDynamicMulticastDelegate Dynamic>
110 struct TNative_Struct<Dynamic>
111 {
112 using Type = TMulticastDelegate<TDynamicSignature<Dynamic>, FDefaultDelegateUserPolicy>;
113 };
114
115 /** @brief Map the input dynamic (multicast) delegate to a conceptually compatible native (multicast) delegate type */
116 template<typename Dynamic>
118}
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:45
Constraint given type to a dynamic multicast delegate class.
Definition Traits.h:52
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:117
typename TDynamicSignature_Struct< std::decay_t< Dynamic > >::Type TDynamicSignature
Get the native function signature type compatible with given dynamic (multicast) delegate.
Definition Traits.h:98
TDelegate< TFunctionFromTypes< TFunction_Return< Function >, TTypesTrimEnd< sizeof...(Captures), TFunction_Arguments< Function > > >, FDefaultDelegateUserPolicy > TInferredDelegate
Infer a delegate type from an input function signature and a list of captures.
Definition Traits.h:34
typename TDynamicMethodPtr_Struct< std::decay_t< Dynamic > >::Type TDynamicMethodPtr
Get the native function pointer type compatible with given dynamic (multicast) delegate.
Definition Traits.h:79
typename Detail::TFunctionFromTypes_Struct< Return, std::decay_t< TypeList > >::Type TFunctionFromTypes
Compose a function type from a tuple of arguments and a return type.
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 TFunctionTraits< std::decay_t< T > >::Arguments TFunction_Arguments
Shorthand for getting a list representing the function arguments.
typename TTypesTrimEnd_Struct< Count, T >::Type TTypesTrimEnd
Definition Templates.h:179
Templating utilities for manipulating TTuples.
Definition Tuples.h:24
typename Dynamic::template TMethodPtrResolver< false, FDeclareOnly >::FMethodPtr Type
Definition Traits.h:67
TFunction_Signature< TDynamicMethodPtr< Dynamic > > Type
Definition Traits.h:87
TDelegate< TDynamicSignature< Dynamic >, FDefaultDelegateUserPolicy > Type
Definition Traits.h:106