templates - c++ map finding value and associated key -


i develop 1 program in c++ in have find key in stl map using values. values assigned key 5 tuples (srcip,port,destip,port,srcno)

now want check in map whether there key assosiated values. trying this.

but showing error wrong number of template argument. note(in program in pair key->value) value consist of tuple of 5 variable.

template<class t> struct map_data_compare : public std::binary_function<typename t::value_type,typename t::mapped_type,bool> { public: bool operator() (typename t::value_type &pair,typename t::mapped_type i) { return pair.second == i; } }   class values { private: std::string c_addr; int c_port; std::string s_addr; int s_port; int c_id;  public: values(std::string,int,std::string,int,int); void printvalues(); };   values :: values(std::string caddr,int cport,std::string saddr,int sport,int cid) { c_addr=caddr; c_port=cport; s_addr=saddr; s_port=sport; c_id=cid; }  void values::printvalues() { cout << c_addr<<":" <<c_port<<":" << s_addr <<":" <<s_port << ":"<<c_id  <<endl; }    //in main      {      typedef std::map<int, values> itemstype;     itemstype items;       values connection (inet_ntoa(clientaddr.sin_addr),ntohs(clientaddr.sin_port),inet_ntoa(servaddr.sin_addr),ntohs(servaddr.sin_port),clientid);        std::map<std::int,values>::iterator = std::find_if( items.begin(), items.end(), std::bind2nd(map_data_compare<itemstype>(),connection));      if ( != items.end() )     {     assert( connection == it->second);     std::cout << "found index:" << it->first << " values:" << it->second << std::endl;     }     else     {     std::cout << "did not find index values:" << connection <<endl;     } 

i develop 1 program in c++ in have find key in stl map using values.

that's not maps meant for. if need kind of access, recommend boost.bimap


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -