This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

hash_map.find() use compiles on 64 bit but not on 32?


the code included below seems to compile fine with gcc 4.1.2 on centos 5.2 on a 64 bit system. it fails to compile on a more or less identical 32 bit bit system. using map instead of hash_map allows it to work on both build platforms, but i'd rather use hash_map. i tried it with 32 bit data types only, avoiding 64 bit ints, but that didn't work any better.

code:
==
#include <list>
#include <ext/hash_map>
#include <iostream>
#include <map>

using namespace __gnu_cxx;
using namespace std;

class object {
public:
object() {;}
object(int32_t a, int32_t b, int32_t c)
: attr1(a), attr2(b), attr3 (c)
{ ; }

int32_t attr1;
int32_t attr2;
int32_t attr3;
};

typedef class object object_t;


class vlist { public: list<object> list_; int foo; };

typedef hash_map <int64_t, vlist *> bucket_t;

// typedef map <int64_t, vlist *> bucket_t;

class hier {
public:
hier(int arg1);
list <int64_t> *makeup_key_list()
{
list <int64_t> *l = new list <int64_t>;
l->push_front((int64_t) 3);
l->push_front((int64_t) 5);
l->push_front((int64_t) 1);
return l;
}

public:
bucket_t buckets_;
int arg1_;
};

//create the map
hier::hier (int arg1)
{
arg1_ = arg1;
// generate keys 1, 3 and 5
list <int64_t> *key_list = makeup_key_list();
list <int64_t>::iterator ki;
for (ki = key_list->begin(); ki != key_list->end(); ki++) {
bucket_t::iterator bi;
vlist *vl;
// build a bucket for each key
bi = buckets_.find(*ki);

if (bi == buckets_.end()) {
vl = new vlist;
buckets_[*ki] = vl;
} else {
vl = bi->second;
}
// fill in the list
int j;
for (j = 0; j < 5; j++) {
object *o = new object (j + *ki * 1000,
j + *ki *10000, j + *ki * 100000);
vl->list_.push_back(*o);
vl->foo = *ki;
}
}
}

int
main (int argc, char **argv)
{
hier *h = new hier(1);
bucket_t::iterator bi;
for (bi = h->buckets_.begin(); bi != h->buckets_.end(); bi++) {
int32_t idx = bi->first;
vlist *vl = bi->second;
int cnt;
list<object>::iterator it;
cout << "Hash key " << idx << ":";
for (cnt = 0, it = vl->list_.begin();
it != vl->list_.end(); it++, cnt++) {
cout << "count: " << cnt << "--" << it->attr1
<< " " << it->attr2 << " " << it->attr3 << endl;
}
}
}
====================================================
errors from compiling on a 32 bit system:
t.cpp: In constructor ‘hier::hier(int)’:
t.cpp:61: error: no matching function for call to ‘__gnu_cxx::hash_map<int, vlist*, __gnu_cxx::hash<int>, std::equal_to<int>, std::allocator<vlist*> >::find(std::_List_iterator<int>&)’
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/hash_map:224: note: candidates are: typename __gnu_cxx::hashtable<std::pair<const _Key, _Tp>, _Key, _HashFcn, std::_Select1st<std::pair<const _Key, _Tp> >, _EqualKey, _Alloc>::iterator __gnu_cxx::hash_map<_Key, _Tp, _HashFcn, _EqualKey, _Alloc>::find(const typename __gnu_cxx::hashtable<std::pair<const _Key, _Tp>, _Key, _HashFcn, std::_Select1st<std::pair<const _Key, _Tp> >, _EqualKey, _Alloc>::key_type&) [with _Key = int, _Tp = vlist*, _HashFcn = __gnu_cxx::hash<int>, _EqualKey = std::equal_to<int>, _Alloc = std::allocator<vlist*>]
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/hash_map:228: note: typename __gnu_cxx::hashtable<std::pair<const _Key, _Tp>, _Key, _HashFcn, std::_Select1st<std::pair<const _Key, _Tp> >, _EqualKey, _Alloc>::const_iterator __gnu_cxx::hash_map<_Key, _Tp, _HashFcn, _EqualKey, _Alloc>::find(const typename __gnu_cxx::hashtable<std::pair<const _Key, _Tp>, _Key, _HashFcn, std::_Select1st<std::pair<const _Key, _Tp> >, _EqualKey, _Alloc>::key_type&) const [with _Key = int, _Tp = vlist*, _HashFcn = __gnu_cxx::hash<int>, _EqualKey = std::equal_to<int>, _Alloc = std::allocator<vlist*>]



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]