Created
November 15, 2016 22:10
-
-
Save vittorioromeo/77d4c6ab2287c3cb9d18d6ed28e53ea4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <utility> | |
struct root | |
{ | |
template <typename TNode, typename... TNodes> | |
void start(TNode& n, TNodes&... ns) & | |
{ | |
n.execute(ns...); | |
} | |
}; | |
template <typename TParent> | |
struct node_then | |
{ | |
using this_type = node_then<TParent>; | |
TParent _p; | |
node_then(TParent&& p) : _p{std::move(p)} | |
{ | |
} | |
auto execute() & | |
{ | |
} | |
template <typename TNode, typename... TNodes> | |
auto execute(TNode& n, TNodes&... ns) & | |
{ | |
n.execute(ns...); | |
} | |
auto then() && | |
{ | |
return node_then<this_type>{std::move(*this)}; | |
} | |
auto wait_all() &&; | |
template <typename... TNodes> | |
auto start(TNodes&... ns) & | |
{ | |
_p.start(*this, ns...); | |
} | |
}; | |
template <typename TParent> | |
struct node_wait_all | |
{ | |
using this_type = node_wait_all<TParent>; | |
TParent _p; | |
node_wait_all(TParent&& p) : _p{std::move(p)} | |
{ | |
} | |
template <typename TNode, typename... TNodes> | |
auto execute(TNode& n, TNodes&... ns) & | |
{ | |
([&] { ([&] { n.execute(ns...); })(); })(); | |
} | |
auto then() && | |
{ | |
return node_then<this_type>{std::move(*this)}; | |
} | |
template <typename... TNodes> | |
auto start(TNodes&... ns) & | |
{ | |
_p.start(*this, ns...); | |
} | |
}; | |
template <typename TParent> | |
auto node_then<TParent>::wait_all() && | |
{ | |
return node_wait_all<this_type>{std::move(*this)}; | |
} | |
int main() | |
{ | |
auto a = node_then<root>(root{}).wait_all().then().then(); | |
a.start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment