This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
STL question
- To: egcs at cygnus dot com
- Subject: STL question
- From: Alexander Samoilov <spike at Gambit dot Msk dot SU>
- Date: Thu, 24 Sep 1998 12:29:18 +0400 (MSK/MSD)
STL experts!
Could you help me?
The following code compiles ok:
----------------------------------------------
#include <set.h>
#include <map.h>
#include <multimap.h>
#include <list.h>
#include <hash_set.h>
#include <hash_map.h>
struct ltstr {
bool operator() (char* const s1, char* const s2) const {
return strcmp(s1, s2) < 0;
}
};
typedef map<char* const, int, ltstr> hmap;
inline bool cmp(pair<char* const,int> p1, pair<char* const,int> p2)
{
return strcmp(p1.first, p2.first) != 0;
}
int main()
{
hmap ins1, ins2, ins_diff;
insert_iterator<hmap> ii1(ins_diff,ins_diff.begin());
set_difference(ins1.begin(), ins1.end(),
ins2.begin(), ins2.end(),
ii1, cmp);
}
----------------------------------------------------
But if we substitute map for hash_map, the compiler refuses
to compile point-blank:
----------------------------------------------------
#include <set.h>
#include <map.h>
#include <multimap.h>
#include <list.h>
#include <hash_set.h>
#include <hash_map.h>
struct eqstr {
bool operator() (char* const s1, char* const s2) const {
return strcmp(s1, s2) == 0;
}
};
typedef hash_map<char* const, int, hash<char*>, eqstr> hmap;
inline bool cmp(pair<char* const,int> p1, pair<char* const,int> p2)
{
return strcmp(p1.first, p2.first) != 0;
}
int main()
{
hmap ins1, ins2, ins_diff;
insert_iterator<hmap> ii1(ins_diff,ins_diff.begin());
set_difference(ins1.begin(), ins1.end(),
ins2.begin(), ins2.end(),
ii1, cmp);
}
--------------------------------------------------------------
with the following messages:
--------------------------------------------------------------
home/spike/egcs-gas-bin/include/g++/stl_iterator.h: In method `class insert_iterator<hash_map<char *const,int,hash<char *>,eqstr,__default_alloc_template<false,0> > > & insert_iterator<hash_map<char *const,int,hash<char *>,eqstr,__default_alloc_template<f
alse,0> > >::operator =<hmap>(const struct pair<char *const,int> &)':
/home/spike/egcs-gas-bin/include/g++/stl_algo.h:2213: instantiated from `set_difference<__hashtable_iterator<pair<char *const,int>,char *const,hash<char *>,select1st<pair<char *const,int> >,eqstr,__default_alloc_template<false,0> >, __hashtable_iterator
<pair<char *const,int>,char *const,hash<char *>,select1st<pair<char *const,int> >,eqstr,__default_alloc_template<false,0> >, insert_iterator<hash_map<char *const,int,hash<char *>,eqstr,__default_alloc_template<false,0> > >, bool (*)(pair<char *const,int>,
pair<char *const,int>)>(__hashtable_iterator<pair<char *const,int>,char *const,hash<char *>,select1st<pair<char *const,int> >,eqstr,__default_alloc_template<false,0> >, __hashtable_iterator<pair<char *const,int>,char *const,hash<char *>,select1st<pair<ch
ar *const,int> >,eqstr,__default_alloc_template<false,0> >, __hashtable_iterator<pair<char *const,int>,char *const,hash<char *>,select1st<pair<char *const,int> >,eqstr,__default_alloc_template<false,0> >, __hashtable_iterator<pair<char *const,int>,char *c
onst,hash<char *>,select1st<pair<char *const,int> >,eqstr,__default_alloc_template<false,0> >, insert_iterator<hash_map<char *const,int,hash<char *>,eqstr,__default_alloc_template<false,0> > >, bool (*)(pair<char *const,int>, pair<char *const,int>))'
hm1.cc:32: instantiated from here
/home/spike/egcs-gas-bin/include/g++/stl_iterator.h:398: no matching function for call to `hash_map<char *const,int,hash<char *>,eqstr,__default_alloc_template<false,0> >::insert (__hashtable_iterator<pair<char *const,int>,char *const,hash<char *>,select1
st<pair<char *const,int> >,eqstr,__default_alloc_template<false,0> > &, const pair<char *const,int> &)'
/home/spike/egcs-gas-bin/include/g++/stl_hash_map.h:139: candidates are: hash_map<char *const,int,hash<char *>,eqstr,__default_alloc_template<false,0> >::insert<char *const, int, hash<char *>, eqstr, alloc>(const pair<char *const,int> &)
--------------------------------------------------------------
Could you give me some advice how to remedy the situation?
Best regards.
Alexander Samoilov