PLCnext API Documentation 25.0.2.69
LambdaFunctor.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
7#include "Arp/Base/Core/Detail/DelegateFunctorBase.hxx"
8#include "Arp/Base/Core/Exception.hpp"
9
10namespace Arp::Base::Core
11{
12
14
15template <typename T> class LambdaFunctor;
16
18template<class R, class ...A>
19class LambdaFunctor<R(A...)> : public DelegateFunctorBase<LambdaFunctor<R(A...)>>
20{
21public: // typedefs/usings
22 using Function = std::function<R(A...)>;
23
24public: // construction/destruction
25 LambdaFunctor(const Function& f)
26 : function(f)
27 {
28 }
29
30 LambdaFunctor(Function&& f)
31 : function(f)
32 {
33 }
34
35public: // static operations
36 template<class ...Args>
37 static R Invoke(IDelegateFunctor* pFunctor, Args... args)
38 {
39 auto* pThis = dynamic_cast<LambdaFunctor*>(pFunctor);
40 return std::invoke(pThis->function, args...);
41 }
42
43protected: // overridden operations
44 bool EqualsTo(const LambdaFunctor& /*other*/)override
45 {
46 throw Exception(String::Format("Equality operation is not supported by lambda expressions or std::function."));
47 }
48
49private: // fields
50 Function function;
51};
52
54
55} // end of namespace Arp::Base::Core
static String Format(const String &format, const Args &... args)
Formats the format string using the .NET/Python syntax with the given variadic arguments.
Definition: String.inl:18