-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adapt_boost_variant: how to say 'any sub-type of a variant'? #31
Comments
Hi Andrzej, Read the comment for XTL_FALL_THROUGH in config.h. Right now it is enabled, Yuriy On Mon, Feb 8, 2016 at 3:50 PM, Andrzej Krzemieński <
|
Ok, so my example doesn't do what I intended. But my question still remains: is there a way to say "match Case (C<TankC>(), match_anything) The use case is this: in case I get |
of course, just use the wildcard pattern _ #include <mach7/patterns/primitive.hpp> using mch::_; Case(C(), _) ... Alternatively, Case allows specifying less arguments than subjects in which Btw, I started moving headers, just haven't finished yet. Yuriy On Tue, Feb 9, 2016 at 2:37 AM, Andrzej Krzemieński <
|
The following program does not compile, even after using the wildcard pattern. I get an error about ambiguous class template instantiation ( -- Andrzej #include <boost/variant.hpp>
#include <Mach7/code/type_switchN-patterns-xtl.hpp>
#include <Mach7/code/adapters/boost/adapt_boost_variant.hpp>
#include <Mach7/code/patterns/constructor.hpp>
#include <mach7/code/patterns/primitive.hpp>
struct TankA {};
struct TankB {};
struct TankC {};
struct Load1 {};
struct Load2 {};
typedef boost::variant<TankA, TankB, TankC> Tank;
typedef boost::variant<Load1, Load2> Load;
int interact(Tank const& tank, Load const& load)
{
using mch::C;
using mch::_;
Match(tank, load)
{
Case (C<TankA>(), C<Load1>())
return 61;
Case (C<TankA>(), C<Load2>())
return 62;
Case (C<TankB>(), C<Load1>())
return 71;
Case (C<TankB>(), C<Load2>())
return 72;
Case (C<TankC>(), _)
return 0;
Otherwise()
return -1;
}
EndMatch
}
int main()
{
assert (interact(TankC(), Load1()) == 0);
} |
For variant, that is the right header, other headers would only assume On Tue, Feb 9, 2016 at 12:28 PM, Andrzej Krzemieński <
|
Code compiles with Clang, so I guess it is an MSVC-specific issue. Not sure yet why. As to static_assert, I remember now I added it deliberately because some of the patterns might have commas in them without being wrapped into ( and ). Preprocessor would then treat them as separate arguments, so it was more useful to have the compiler assert when the number of patterns was not matching the number of subjects. |
Ok. Can you give me some background then? Sub-type matching works when the correct unambiguous specialization of |
I am also experiencing similar problems with GCC. |
I am trying to do a type switch on two variants, as per the example below. My intention is to match the case where the left-hand object 'tank' has the sub-type
TankC
and the right-hand side object 'load' has any type. I managed to achieve the effect by listing two labels one immediately after the other, but I guess there must be a more direct way of expressing this?The text was updated successfully, but these errors were encountered: