Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active March 30, 2017 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/669852cc2433cefc7ba961dad56bdd82 to your computer and use it in GitHub Desktop.
Save deque-blog/669852cc2433cefc7ba961dad56bdd82 to your computer and use it in GitHub Desktop.
std::string print_infix_op_bad(op<add_tag, std::string> const& e)
{
return boost::algorithm::join(e.rands(), " + ");
}
std::string with_parens(std::string const& s)
{
return std::string("(") + s + ")";
}
std::string print_infix_op_bad(op<mul_tag, std::string> const& e)
{
return boost::algorithm::join(e.rands() | transformed(with_parens), " * ");
}
std::string print_infix_bad(expression_r<std::string> const& e)
{
if (auto* o = get_as_add(e)) return print_infix_op_bad(*o);
if (auto* o = get_as_mul(e)) return print_infix_op_bad(*o);
if (auto* i = get_as_cst(e)) return std::to_string(*i);
if (auto* v = get_as_var(e)) return *v;
throw_missing_pattern_matching_clause();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment