-
Notifications
You must be signed in to change notification settings - Fork 1
Struct __DelegateAnyCT
AdamFull edited this page Aug 10, 2021
·
8 revisions
Implementation of global compile-time delegates. More...
#include <EasyDelegateAnyCTImpl.hpp>
| Name | |
|---|---|
| template <_Enumerator eBase,class _LabbdaFunction > void |
attach(_LabbdaFunction && lfunc) Attaches the passed method to the User defined enumeration key. |
| template <_Enumerator eBase,class... Args> void |
attach(Args &&... args) Creates a connection with the method and the enumerator. |
| template <_Enumerator eBase> void |
detach() Breaks a connection between the method and the enumerator. |
| template <class ... Args> void |
execute(Args &&... args) Executes the delegate for the specified enumerator. |
| template <_Enumerator eBase,class... Args> auto |
eval(Args &&... args) Evaluates the delegate on the specified enumerator and returns the value. |
template <class _Enumerator >
struct EasyDelegate::__DelegateAnyCT;Implementation of global compile-time delegates. Not working for now.
Template Parameters:
- _Enumerator Enumerator class
template <_Enumerator eBase,
class _LabbdaFunction >
static inline void attach(
_LabbdaFunction && lfunc
)Attaches the passed method to the User defined enumeration key.
Parameters:
- lfunc
Template Parameters:
- eEnum User defined enumeration key
- _LabbdaFunction Lambda object
template <_Enumerator eBase,
class... Args>
static inline void attach(
Args &&... args
)Creates a connection with the method and the enumerator.
Parameters:
- args
Template Parameters:
- eBase User defined enumeration key
- Args Templated std::tuple arguments
template <_Enumerator eBase>
static inline void detach()Breaks a connection between the method and the enumerator.
Template Parameters:
- eBase User defined enumeration key
template <class ... Args>
static inline void execute(
Args &&... args
)Executes the delegate for the specified enumerator.
Parameters:
- args Delegate arguments
Template Parameters:
- eEnum User defined enumeration key
- Args Templated std::tuple arguments
template <_Enumerator eBase,
class... Args>
static inline auto eval(
Args &&... args
)Evaluates the delegate on the specified enumerator and returns the value.
Parameters:
- args Delegate arguments
Template Parameters:
- eEnum User defined enumeration key
- Args Templated std::tuple arguments
Return: SignatureDesc<_Signature>::return_type auto eval(Args&&... args)
#include <iostream>
#include "EasyDelegate.hpp"
using namespace EasyDelegate;
// An important note. You cannot use TDelegateAny and TDelegateAnyCT at the
// same time due to some technical problems. The same is the case with the
// enumerator. When the problem is resolved, this will be indicated in the update.
// If you want use multiple enums, start new enum with higher index
enum class EEnumerator
{
EIntDelegate = 100,
EBoolDelegate
};
//This declarations should be in cpp file
DeclareDelegateFuncCompileTime(EEnumerator, EEnumerator::EIntDelegate, int(int, int, bool))
DeclareDelegateFuncCompileTime(EEnumerator, EEnumerator::EBoolDelegate, bool(bool, bool))
int foo(int x, int y, bool ts)
{
return ts ? x : y;
}
class Foo
{
public:
bool foo(bool ts, bool fs)
{
return ts && fs;
}
};
int main()
{
//Attaching function to abstract global delegate container
TDelegateAnyCT<EEnumerator>::attach<EEnumerator::EIntDelegate>(&foo);
//Calling function
auto iresult = TDelegateAnyCT<EEnumerator>::eval<EEnumerator::EIntDelegate>(50, -50, false);
TDelegateAnyCT<EEnumerator>::detach<EEnumerator::EIntDelegate>();
//Class example
Foo boo;
//Attach class method to delegate container
TDelegateAnyCT<EEnumerator>::attach<EEnumerator::EBoolDelegate>(&boo, &Foo::foo);
auto bresult = TDelegateAnyCT<EEnumerator>::eval<EEnumerator::EBoolDelegate>(true, true);
TDelegateAnyCT<EEnumerator>::detach<EEnumerator::EBoolDelegate>();
//And with lambda function
TDelegateAnyCT<EEnumerator>::attach<EEnumerator::EBoolDelegate>([&](bool b, bool n)
{
return boo.foo(b, n) || b;
});
auto lresult = TDelegateAnyCT<EEnumerator>::eval<EEnumerator::EBoolDelegate>(true, false);
TDelegateAnyCT<EEnumerator>::detach<EEnumerator::EBoolDelegate>();
std::cout << lresult << std::endl;
return 0;
}