Created
June 6, 2014 13:10
-
-
Save donkaban/20ebe3bedf74cfa55ff6 to your computer and use it in GitHub Desktop.
extended lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum class lambda_state {DELETE,EXECUTE,PAUSED,DIRECT,ASYNC}; | |
template<typename T> class method; | |
template <typename Res, typename... Args> class method<Res(Args...)> | |
{ | |
public: | |
using F = std::function<Res(Args...)>; // functor | |
using R = typename std::result_of<F(Args...)>::type; // result type | |
using L = std::function<void(R)>; // result lambda | |
method() : | |
func([](...){}) | |
{} | |
method(const F &f, lambda_state s = lambda_state::DIRECT) : | |
func(f), | |
state(s) | |
{} | |
template<typename ... A> R operator() (A && ... args) {return func(args ...);} | |
template<typename ... A> void operator() (A && ... args, const L & lambda) | |
{ | |
state = lambda_state::EXECUTE; | |
resLambda = lambda; | |
} | |
void remove() {state = lambda_state::DELETE;} | |
void pause() {state = lambda_state::PAUSED;} | |
void unpause() {state = lambda_state::DIRECT;} | |
private: | |
lambda_state state ; | |
F func {}; | |
R result {}; | |
L resLambda {}; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment