Delegate.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * Delegate.h
8  *
9  ****/
10 
15 #pragma once
16 
17 #include <functional>
18 using namespace std::placeholders;
19 
24 template <typename> class Delegate; /* undefined */
25 
28 template <typename ReturnType, typename... ParamTypes>
29 class Delegate<ReturnType(ParamTypes...)> : public std::function<ReturnType(ParamTypes...)>
30 {
31  using StdFunc = std::function<ReturnType(ParamTypes...)>;
32 
33 public:
34  using StdFunc::function;
35 
36  Delegate() = default;
37 
42  template <class ClassType>
43  Delegate(ReturnType (ClassType::*m)(ParamTypes...), ClassType* c)
44  : StdFunc([m, c](ParamTypes... params) -> ReturnType { return (c->*m)(params...); })
45  {
46  }
47 };
48 
Delegate(ReturnType(ClassType::*m)(ParamTypes...), ClassType *c)
Delegate a class method.
Definition: Delegate.h:43
Delegate class, encapsulates a std::function Added constructor template implements lambda callback wh...
Definition: Delegate.h:24