Wrox Programmer Forums
|
BOOK: Professional C++
This is the forum to discuss the Wrox book Professional C++ by Nicholas A. Solter, Scott J. Kleper; ISBN: 9780764574849
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 25th, 2006, 10:21 PM
Registered User
 
Join Date: Oct 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Question on Hashmap

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


 
Old September 3rd, 2006, 02:13 AM
Authorized User
 
Join Date: Oct 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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)





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to loop through a HashMap in XSL? sunilnk XSLT 6 April 10th, 2017 04:09 AM
jsp need to store data in hashtable or hashmap kotaiah JSP Basics 0 October 14th, 2006 01:48 AM
To sort a hashmap using its keys and/or values Mr. Ram Java Basics 1 June 1st, 2006 11:19 PM
HashMap mudit_12 Intro Programming 0 March 3rd, 2005 12:46 AM
HashMap freezotic BOOK: Beginning Java 2 6 March 26th, 2004 04:27 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.