Mach7
Mach7 copied to clipboard
Case macro using C++17 structured bindings.
Discussion in #67 and https://github.com/solodon4/Mach7/blob/master/code/test/unit/example04-smart-ptr.cpp notes that binding a reference from a smart pointer is unwieldy due to poor language support for proxies.
It seems that being able to unpack directly into the target variables via structured bindings would make for a much cleaner solution.
Are there any major hurdles in the existing implementation to doing this?
(and I guess this is off-topic from the issue title, but addresses the same problem of binding references)
Alternatively, an LCase
, that looked something like this:
LCase(C<A>([](vars,bound,from,a){body}));
Instead of like:
Case(C<A> (vars,bound,from,a)) body;
Regarding the 2nd note: there were other attempts at using lambdas for pattern matching of which I was aware at the time, but decided not to go that direction. Main reason - lambdas are still functions and you get control inversion with them. When I put return inside Case statement I would like to be returning from the function I'm in, not a callback used for syntactic purposes. I also saw performance numbers of those attempts at the time and it was a definite no go in comparison to the performance the current switch gives you.
Regarding structured bindings - yes, i'm planning to exploit them, just didn't have time to play around with options. Structured bindings were inspired by this library among other things :)
Forgot to mention in the previous post. If you don't particularly care about performance, you might want to look at Simple, Extensible C++ Pattern Matching Library - it uses lambdas for syntactic sugar and doesn't use any macros AFAIK. The author had presentation at CppCon 2015 I believe, you might want to check his talk for details.