
Modern pattern matching and multimethods for C++ (+faster than visitor pattern) - seansh
CppCon 2014 &quot;Accept no visitors&quot;:
   https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=QhJguzpZOrk<p>Mach7 Library:
   https:&#x2F;&#x2F;github.com&#x2F;solodon4&#x2F;Mach7<p>An example from the slides:<p>struct BoolExp { virtual~BoolExp() {} };
struct VarExp: BoolExp{ std::string name; };
struct ValExp: BoolExp{ boolvalue; };
struct NotExp: BoolExp{ BoolExp* e; };
struct AndExp: BoolExp{ BoolExp* e1; BoolExp* e2; };
struct OrExp: BoolExp{ BoolExp* e1; BoolExp* e2; };<p>....<p>bool eval(Context&amp; ctx, constBoolExp* exp)
{
   var&lt;std::string&gt; name; var&lt;bool&gt; value; var&lt;constBoolExp*&gt; e1, e2;
   Match(exp)
   {
      Case(C&lt;VarExp&gt;(name) ) return ctx[name];
      Case(C&lt;ValExp&gt;(value)) return value;
      Case(C&lt;NotExp&gt;(e1) )   return !eval(ctx, e1);
      Case(C&lt;AndExp&gt;(e1,e2)) return eval(ctx, e1) &amp;&amp; eval(ctx, e2);
      Case(C&lt;OrExp&gt;(e1,e2))  return eval(ctx, e1) || eval(ctx, e2);
   }
   EndMatch
}
======
seansh
Oops, looks like the formatting is messed up... See here:
[http://pastie.org/9684691](http://pastie.org/9684691)

