PLCnext API Documentation 25.0.2.69
LambdaFunctor.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
8#include "Arp/System/Core/Impl/DelegateFunctorBase.hxx"
9#include "Arp/System/Core/Exception.hpp"
10
11namespace Arp { namespace System { namespace Core { namespace Impl
12{
13
15
16template <typename T> class LambdaFunctor;
17
19// class LambdaFunctor is implemented completely implicite inline to avoid
20// code bloat in commonly used Core classe and therefore reduce compile time
21template<class R, class ...A>
22class LambdaFunctor<R(A...)> : public DelegateFunctorBase<LambdaFunctor<R(A...)>>
23{
24public: // typedefs/usings
25 using Function = std::function<R(A...)>;
26
27public: // construction/destruction
28 LambdaFunctor(const Function& f) : function(f) {}
29 LambdaFunctor(Function&& f) : function(f) {}
30 LambdaFunctor(const LambdaFunctor& arg) = default;
31 LambdaFunctor& operator=(const LambdaFunctor& arg) = default;
32 virtual ~LambdaFunctor(void)noexcept = default;
33
34public: // static operations
35 template<class ...Args>
36 static R Invoke(void* pArg, Args&& ... args)
37 {
38 LambdaFunctor* pThis = static_cast<LambdaFunctor*>(pArg);
39 return pThis->function(std::forward<Args>(args)...);
40 }
41
42protected: // overidden operations
43 bool Equals(const LambdaFunctor& /*other*/)override
44 {
45 throw Exception("Equality operation is not supported by lamda expressions or std::function.");
46 }
47
48private: // fields
49 Function function;
50};
51
53
54}}}} // end of namespace Arp::System::Core::Impl
@ Equals
Start recording if TriggerVariable1 is equal to TriggerVariable2.
Root namespace for the PLCnext API