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 
20 template <typename> class Delegate; /* undefined */
21 
24 template <typename ReturnType, typename... ParamTypes>
25 class Delegate<ReturnType(ParamTypes...)> : public std::function<ReturnType(ParamTypes...)>
26 {
27  using StdFunc = std::function<ReturnType(ParamTypes...)>;
28 
29 public:
30  using StdFunc::function;
31 
32  Delegate() = default;
33 
38  template <class ClassType>
39  Delegate(ReturnType (ClassType::*m)(ParamTypes...), ClassType* c)
40  : StdFunc([m, c](ParamTypes... params) -> ReturnType { return (c->*m)(params...); })
41  {
42  }
43 };
44 
Delegate(ReturnType(ClassType::*m)(ParamTypes...), ClassType *c)
Delegate a class method.
Definition: Delegate.h:39
Definition: Delegate.h:20