Skip to content

Instantly share code, notes, and snippets.

Last active January 29, 2017 14:31
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
template<typename Tag>
std::set<id> join_sets(op<Tag, std::set<id>> const& op)
std::set<id> out;
for (auto r: op.rands())
out.insert(r.begin(), r.end());
return out;
std::set<id> dependencies_alg(expression_r<std::set<id>> const& e)
if (auto* o = get_as_add(e)) return join_sets(*o);
if (auto* o = get_as_mul(e)) return join_sets(*o);
if (auto* v = get_as_var(e)) return {*v};
return {};
std::set<id> dependencies(expression const& e)
return cata<std::set<id>>(dependencies_alg, e);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment