eggs-cpp / variant

Eggs.Variant is a C++11/14/17 generic, type-safe, discriminated union.
http://eggs-cpp.github.io/variant/
Boost Software License 1.0
137 stars 27 forks source link

Heterogenous multi-visitation ? #22

Closed jcelerier closed 8 years ago

jcelerier commented 8 years ago

Hello,

Is there a way to make multi-visitation with apply() & multiple variant types ?

e.g.

eggs::variant<int, float> v1;
eggs::variant<foo, bar> v2;

struct vis { 
    void operator()(int, foo);
    void operator()(int, bar);
    void operator()(float, foo);
    void operator()(float, bar);
};

eggs::variants::apply(vis{}, v1, v2);

thanks !

tomilov commented 8 years ago

@jcelerier You can do it easily by yourself. Here is an example https://github.com/tomilov/variant/blob/master/include/versatile/visit.hpp#L165 of multivisit function.

K-ballo commented 8 years ago

Is there a way to make multi-visitation with apply() & multiple variant types ?

Yes, exactly as you have written it. Have you run into any issues while trying that snippet?

K-ballo commented 8 years ago

You can do it easily by yourself.

@tomilov Why would he want to do it by himself when the library has provided it since day one? What am I missing here?

tomilov commented 8 years ago

@K-ballo I'm sorry. Moreover I even knew it, but I hastened to write this irrelevant answer. My mistake.

jcelerier commented 8 years ago

damn, yes, this simple example works, but more complex ones don't. I'll try to make a simple reproducible example (if this is not some stupid mistake from my part :) ). Sorry for the noise !