c++ - operator== container iterator const and non-const -


i'm trying have eventmanager impossibly fast c++ delegate discussed in article http://blog.coldflake.com/posts/c++-delegates-on-steroids/;

template <typename t, typename r, typename... params> class delegate<r (t::*)(params...) const> { public:     typedef r (t::*func_type)(params...) const;      delegate(func_type func, const t& callee)         : callee_(callee) , func_(func)     {}      r operator()(params... args) const     { return (callee_.*func_)(args...); }      bool operator==(const delegate& other) const     { return (&callee_ == &other.callee_) && (func_ == other.func_); }      bool operator!= (const delegate& other) const     { return !(*this == other); }  private:     const t& callee_;     func_type func_; }; 

and 1 of methods used;

using eventlistenerdelegate = delegate<ieventdataptr>; using eventlistenerlist = std::list<eventlistenerdelegate>;  bool eventmanager::addlistener(const eventlistenerdelegate& eventdelegate, const eventtype& type) {     // find or create entry     eventlistenerlist& eventlistenerlist = m_eventlisteners[type];     (auto = eventlistenerlist.begin(); != eventlistenerlist.end(); ++it)     {         if (eventdelegate == (*it))         {             std::cout <<"attempting double-register delegate" << std::endl;             return false;         }     }     eventlistenerlist.push_back(eventdelegate);     return true; } 

the code failed compile gcc error message;

error: no match 'operator==' (operand types 'const eventlistenerdelegate {aka const delegate<std::shared_ptr<ieventdata> >}' , 'delegate<std::shared_ptr<ieventdata> >')          if (eventdelegate == (*it))                            ^  

what should fix error? thank you.

edit: 2 other specialization templates in code;

//specialization free functions template <typename r, typename... params> class delegate<r (*)(params...)> 

and;

//specialization member functions template <typename t, typename r, typename... params> class delegate<r (t::*)(params...)> 


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -