Boost logo

Boost Users :

Subject: Re: [Boost-users] [variant] declaring recursive variants (Jerry Jeremiah)
From: ÇÇ־ǿ (qiaozhiqiang_at_[hidden])
Date: 2011-11-17 00:43:39


binary '==' : no operator found which takes a left-hand operand of type 'const T2'
and T2=config_iter
 

so you need bool config_iter::operator == (const config_iter & other) const;

struct config_iter
{
        config_iter(const config::iterator iter) : iter_(iter) {}
        operator config::iterator() const { return iter_; }
        config::iterator operator() () const { return iter_; }

//////ADD THIS//////////////////////
        bool operator == (const config_iter & other) const
        {
                return iter_ == other.iter_;
        }
//////ADD THIS//////////////////////

protected:
        config::iterator iter_;
};

//////// SEE HERE ///////////////////////////////////
1>.\boost\variant\variant.hpp(781): error: binary '==' : no operator found which takes a left-hand operand of type 'const T2' (or there is no acceptable conversion)
//////// SEE HERE ///////////////////////////////////

1> .\boost\blank.hpp(58): could be 'bool boost::operator ==(const boost::blank &,const boost::blank &)'
1> while trying to match the argument list '(const T2, const T2)'
1> .\boost\variant\variant.hpp(763) : see reference to function template instantiation 'bool boost::detail::variant::equal_comp::operator ()<T>(const T &,const T &) const' being compiled
1> with
1> [
1> T=T2
1> ]
1> .\boost\variant\variant.hpp(832) : see reference to function template instantiation 'bool boost::detail::variant::comparer<Variant,Comp>::operator ()<const T>(const T &) const' being compiled
1> with
1> [
1> Variant=boost::variant<std::string,long double,config_iter>,
1> Comp=boost::detail::variant::equal_comp,
1> T=T2
1> ]
1> .\boost\variant\detail\visitation_impl.hpp(130) : see reference to function template instantiation 'bool boost::detail::variant::invoke_visitor<Visitor>::internal_visit<const T>(T &,int)' being compiled
1> with
1> [
1> Visitor=boost::detail::variant::comparer<boost::variant<std::string,long double,config_iter>,boost::detail::variant::equal_comp>,
1> T=T2
1> ]
1> .\boost\variant\detail\visitation_impl.hpp(173) : see reference to function template instantiation 'bool boost::detail::variant::visitation_impl_invoke_impl<Visitor,VoidPtrCV,T>(int,Visitor &,VoidPtrCV,T *,boost::mpl::true_)' being compiled
1> with
1> [
1> Visitor=boost::detail::variant::invoke_visitor<boost::detail::variant::comparer<boost::variant<std::string,long double,config_iter>,boost::detail::variant::equal_comp>>,
1> VoidPtrCV=const void *,
1> T=T2
1> ]
1> .\boost\variant\detail\visitation_impl.hpp(256) : see reference to function template instantiation 'bool boost::detail::variant::visitation_impl_invoke<Visitor,VoidPtrCV,T2,NoBackupFlag>(int,Visitor &,VoidPtrCV,T *,NoBackupFlag,int)' being compiled
1> with
1> [
1> Visitor=boost::detail::variant::invoke_visitor<boost::detail::variant::comparer<boost::variant<std::string,long double,config_iter>,boost::detail::variant::equal_comp>>,
1> VoidPtrCV=const void *,
1> NoBackupFlag=boost::variant<std::string,long double,config_iter>::has_fallback_type_,
1> T=T2
1> ]
1> .\boost\variant\variant.hpp(1776) : see reference to function template instantiation 'bool boost::detail::variant::visitation_impl<first_which,first_step,Visitor,VoidPtrCV,boost::variant<T0_,T1,T2>::has_fallback_type_>(const int,const int,Visitor &,VoidPtrCV,boost::mpl::false_,NoBackupFlag,Which *,step0 *)' being compiled
1> with
1> [
1> Visitor=boost::detail::variant::invoke_visitor<boost::detail::variant::comparer<boost::variant<std::string,long double,config_iter>,boost::detail::variant::equal_comp>>,
1> VoidPtrCV=const void *,
1> T0_=std::string,
1> T1=long double,
//////// SEE HERE ///////////////////////////////////
1> T2=config_iter,
//////// SEE HERE ///////////////////////////////////
1> NoBackupFlag=boost::variant<std::string,long double,config_iter>::has_fallback_type_,
1> Which=first_which,
1> step0=first_step
1> ]

// test program with config_iter and indentifier // doesn't compile if identifier::operator==() is in the program

 #include <boost/variant.hpp> #include <iterator> #include <string> #include <vector> #include <list> #include <map>

struct config_iter;

typedef boost::variant<std::string
                      ,long double
                      ,config_iter
> var;
typedef std::vector<var> value;
typedef std::map<std::string,value> message; typedef std::map<std::string,message> config;

struct config_iter
{
    config_iter(const config::iterator iter) : iter_(iter) {}
    operator config::iterator() const { return iter_; }
    config::iterator operator() () const { return iter_; }
protected:
    config::iterator iter_;
};

struct identifier
{
    identifier()
    : name_(""), version_({0})
    {
        // std::cout << "identifier::identifier()" << std::endl;
    }
    identifier(const std::string & name, const value & version)
    : name_(name), version_(version)
    {
        // std::cout << "identifier::identifier(" << name << "," << version << ")" << std::endl;
    }
    bool operator == (const identifier & other) const
    {
        return name_ == other.name_ && version_ == other.version_;
    }
private:
    // updated by constructor
    std::string name_;
    value version_;
};

int main()
{
    return 0;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net