Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
template<typename A, typename M>
auto fmap(M map, expression_r<A> const& e)
using B = decltype(map(std::declval<A>()));
using Out = expression_r<B>;
if (auto* o = get_as_add(e))
return Out(add_op<B>(o->rands() | transformed(map)));
if (auto* o = get_as_mul(e))
return Out(mul_op<B>(o->rands() | transformed(map)));
if (auto* i = get_as_cst(e)) return Out(*i);
if (auto* v = get_as_var(e)) return Out(*v);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment