Compare two variant with boost static_visitor
        Posted  
        
            by 
                Zozzzzz
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Zozzzzz
        
        
        
        Published on 2012-11-03T22:07:21Z
        Indexed on 
            2012/11/03
            23:00 UTC
        
        
        Read the original article
        Hit count: 256
        
I started to use the boost library a few days ago so my question is maybe trivial. I want to compare two same type variants with a static_visitor. I tried the following, but it don't want to compile.
struct compare:public boost::static_visitor<bool>
{
    bool operator()(int& a, int& b) const
    {
        return a<b;
    }
    bool operator()(double& a, double& b) const
    {
        return a<b;
    }
};
int main()
{
    boost::variant<double, int > v1, v2;
    v1 = 3.14;
    v2 = 5.25;
    compare vis;
    bool b = boost::apply_visitor(vis, v1,v2);
    cout<<b;
    return 0;
}
Thank you for any help or suggestion!
© Stack Overflow or respective owner