solodon4 / Mach7

Functional programming style pattern-matching library for C++

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does Mach7 switch on heterogenous interfaces?

akrzemi1 opened this issue · comments

I tested that the library for the support of boost::variant, and the simple example works fine, after I defined all the template specializations as per your example. However, I somehow got the expectation that I should be able to use the switch with two variants, like this:

void test(variant<X, Y, Z> vx, variant<M, N> vm)
{
    var<X> x; var<Y> y; var<Z> z;
    var<M> m; var<N> n;

    Match(vx, vm)
    {
        Case(C<X>(x), C<M>(m)) use(x, m);
        Case(C<Y>(y), C<M>(m)) use(y, m);
        // etc.
    }
    EndMatch
}

This fails to compile with classical meta-programming errors, but before I analyze them in detail, I wanted to check with you if my use case is even supposed to work?

Is Mach7 intended to switch on multiple heterogeneous types? Or is it just a bug in the implementation? Or perhaps my bug?

It was an unfinished experiment. It is supposed to work, just didn't have time to polish it. If you look here:

https://github.com/solodon4/Mach7/blob/master/code/vtblmap4.hpp#L538

you'll see I only provided a single overload for xtl_get, while I needed all the combinations you see below for get. I'll have a look at enabling your case in the evening, but otherwise feel free to add the overloads and try. There were couple of other unfinished things with respect to variants, but I think this one is the only one relevant for multiple arguments.

Thanks. The "double dispatch" works for me now.

OK, made a wider-applicable fix for the issue till I get rid of xtl_get altogether. This one should work properly when you match against non-variant arguments as well. Pull if needed.

BTW, you should be able to write just x instead of C(x) in your case clauses. x is already a pattern that accepts same type since you declared it with var. I should make a note of this and write about in the documentation.