boost variant static_visitor problem picking correct function
- by Steve
I'm sure I'm having a problem with template resolution here, but I'm not sure why I'm having the problem. I have a static visitor I'm passing to boost variant where i've had to do template specialization for certain cases. The case for everything except for MyClass should throw in the static_visitor below. Unfortunately, when the visitor is applied to pull a MyClass out, it selects the most generic case rather than the exact match. I would type each case explicitly, but that will be rather long. So, why is the compiler resolving the most generic case over the exact match, and is there anyway to fix it
template<>
class CastVisitor<MyClass>:public boost::static_visitor<MyClass>
{
public:
template<typename U>
MyClass operator()(const U & i) const
{
throw std::exception("Unable to cast");
}
MyClass operator()(const MyClass& i)
{
return i;
}
};