boost variant static_visitor problem picking correct function
Posted
by Steve
on Stack Overflow
See other posts from Stack Overflow
or by Steve
Published on 2010-05-12T19:19:44Z
Indexed on
2010/05/12
19:24 UTC
Read the original article
Hit count: 175
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;
}
};
© Stack Overflow or respective owner