This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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]

Re: Is std::tr1::unordered_map supposed to be working yet?


Hi Chris,
Thanks for your reply. My responses are below.
Best, Paul
On Thu, 18 Aug 2005 08:56 pm, random@bubblescope.net wrote:
> Paul C. Leopardi wrote:
> >Hi,
> >Two related questions.
> >
> >1. Is the difference in interface between __gnu_cxx::hash_map and
> >std::tr1::unordered_map documented anywhere? Does the fact that I can't
> > find any such gcc - specific documentation mean that
> > std::tr1::unordered_map is a trivial drop-in replacement for
> > __gnu_cxx::hash_map ?
>
> Unfortunatly it's not. There isn't explicit differences documented
> either. Documentation for tr1::unordered_map is contained in
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1745.pdf
>
> If you get a copy of the complete g++ source code, then look in
> libstdc++-v3/testsuite/tr1/6_containers/ you'll find the testsuite for
> the unordered containers, which should at least show the basics of how
> they work, although I'll admit not documented.

Thanks. I took a look at the documentation for TR1 and the source code. The 
tests don't look like they test std::tr1::unordered_map< K, T >, where K is a 
user defined class. All the tests look like they use std::string for K.
So maybe std::tr1::unordered_map< K, T > is not supposed to work?

AFAICT, since I have a user defined key class K, I need to define my own 
hash< K > class. I did this and now have a strange compilation error message.

> >2. I've been trying to use std::tr1::unordered_map as a replacement for
> >__gnu_cxx::hash_map, with gcc version 4.0.2 20050728 (prerelease), and
> > have encountered errors. Is this mailing list the correct place to check
> > to see if I am using std::tr1::unordered_map correctly, and to check that
> > it should work with gcc version 4.0.2 20050728 (prerelease)?
>
> I believe it is, although it's fairly new, so don't be too suprised if
> you don't get too many replies :) Unfortunatly, as I say, it's not
> designed as a drop-in replacement. It would definatly be advisable to
> move toward using it however, as except in extreme cases bug reports for
> __gnu_cxx::hash_map are being ignored, and it's going to be phased out
> in the not-too-distant future. Any problems with tr1::unordered_map have
> a much better change of being fixed :)

The code looks like:
...
template< typename T > struct hash {
 inline size_t operator()(T val) const {
 return 0;
 }
};
template< const index_t LO, const index_t HI > class hash< index_set<LO,HI> > 
{
 public: typedef index_set<LO,HI> index_set_t;
 inline size_t operator()(index_set_t val) const {
 return val.hash_fn();
 }
};
template< typename Scalar_T, 
          const index_t LO = DEFAULT_LO, const index_t HI = DEFAULT_HI > class 
framed_multi : public 
clifford_algebra< Scalar_T, index_set<LO,HI>, framed_multi<Scalar_T,LO,HI> >, 
private 
std::tr1::unordered_map< index_set<LO,HI>, Scalar_T, hash<index_set<LO,HI> > > 
{
...

The strange compilation error message is:
/usr/local/gcc/gcc-4.0-20050728/lib/gcc/x86_64-suse-linux/4.0.2/../../../../include/c++/4.0.2/tr1/hashtable: 
In copy constructor âstd::tr1::hashtable<Key, Value, Allocator, ExtractKey, 
Equal, H1, H2, H, RehashPolicy, cache_hash_code, mutable_iterators, 
unique_keys>::hashtable(const std::tr1::hashtable<Key, Value, Allocator, 
ExtractKey, Equal, H1, H2, H, RehashPolicy, cache_hash_code, 
mutable_iterators, unique_keys>&) [with Key = 
glucat::index_set<-0x00000000000000020, 32>, Value = std::pair<const 
glucat::index_set<-0x00000000000000020, 32>, double>, Allocator = 
std::allocator<std::pair<const glucat::index_set<-0x00000000000000020, 32>, 
double> >, ExtractKey = Internal::extract1st<std::pair<const 
glucat::index_set<-0x00000000000000020, 32>, double> >, Equal = 
std::equal_to<glucat::index_set<-0x00000000000000020, 32> >, H1 = 
glucat::hash<glucat::index_set<-0x00000000000000020, 32> >, H2 = 
Internal::mod_range_hashing, H = Internal::default_ranged_hash, RehashPolicy 
= Internal::prime_rehash_policy, bool cache_hash_code = false, bool 
mutable_iterators = true, bool unique_keys = true]â:
/usr/local/gcc/gcc-4.0-20050728/lib/gcc/x86_64-suse-linux/4.0.2/../../../../include/c++/4.0.2/tr1/unordered_map:59:   
instantiated from here
/usr/local/gcc/gcc-4.0-20050728/lib/gcc/x86_64-suse-linux/4.0.2/../../../../include/c++/4.0.2/tr1/hashtable:1046: 
error: no matching function for call to 
âstd::tr1::hashtable<glucat::index_set<-0x00000000000000020, 32>, 
std::pair<const glucat::index_set<-0x00000000000000020, 32>, double>, 
std::allocator<std::pair<const glucat::index_set<-0x00000000000000020, 32>, 
double> >, Internal::extract1st<std::pair<const 
glucat::index_set<-0x00000000000000020, 32>, double> >, 
std::equal_to<glucat::index_set<-0x00000000000000020, 32> >, 
glucat::hash<glucat::index_set<-0x00000000000000020, 32> >, 
Internal::mod_range_hashing, Internal::default_ranged_hash, 
Internal::prime_rehash_policy, false, true, 
true>::m_allocate_node(Internal::hash_node<std::pair<const 
glucat::index_set<-0x00000000000000020, 32>, double>, false>*&)â
compilation terminated due to -Wfatal-errors.


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