Alex Rivera | Logout

Skipping a C++ template parameter

Asked 2009-08-14T04:21:07.397
14

A C++ hash_map has the following template parameters:

template<typename Key, typename T, typename HashCompare, typename Allocator>

How can I specify a Allocator without specifying the HashCompare?

This won't compile :(

hash_map<EntityId, Entity*, , tbb::scalable_allocator>
Edit
Report

1 Answer

4

If the has map type has some public typedef for the HashCompare template parameter, you could write a meta function that uses a vanilla hash map type to get the std comparator. Something like this:

template< typename Key, typename T, typename Allocator>
struct hash_map_type {
  typedef typename hash_map<Key,T>::key_compare key_compare;
  typedef mash_map<Key,T,key_compare,Allocator> result_t;
};

typedef hash_map_type<int,string,my_allocator>::result_type my_hash_map;

This, however, depends on something like the above hash_map<Key,T>::key_compare being accessible.

answered 2009-08-14T09:10:47.193

Your Answer