|
Subject:
|
Question on Hashmap
|
|
Posted By:
|
alothman
|
Post Date:
|
5/25/2006 10:21:35 PM
|
Hello!
First, I would like to express my appreciation for the contents of chapter 23 (it's great!)
I would like to know what's the proper way to instantiate a hashmap, where the Compare parameter should maintain its default value, but the Hash function is other than DefaultHash<Key>
template<typename Key, typename T, typename Compare = std::equal_to<Key>, typename Hash = DefaultHash<Key> > class hashmap { //... };
I only need the Hash parameter changed.
Must I do something like:
hashmap<int, string, std::equal_to<int>, MidSquare<int> > hash1?
Second question: Since "count" is only used to check whether an element exists, would there be any consequence in using bool as a return type instead of size_type for the count method?
Thank you, A. Alothman
|
|
Reply By:
|
klep
|
Reply Date:
|
9/3/2006 2:13:05 AM
|
Unfortunately, you'd have to specify the first three arguments to use a non-default value for the fourth. The STL classes have this same drawback -- you'll sometimes find yourself looking up and providing the default for one argument just so that you can change the following one.
Scott
---- Scott J. Kleper Author, "Professional C++" (Wrox, 2005)
|
|