By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 901 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

replace std::map with <ext/hash_map>

P: n/a
g
hello!

I wanna replace an std::map<std::string,Services*>
with hash_map.How I will do this?

any link with examples?

transactions.insert(std::pair<std::string,Services *>("Aservice",new
xxxx));
transactions.insert(std::pair<std::string,Services *>("Vservice",new
fffff));
transactions.insert(std::pair<std::string,Services *>("Rservice",new
ttt));
...............

how I should replace this with hash_map?

thanks for any help.

Apr 20 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
g wrote:
I wanna replace an std::map<std::string,Services*>
with hash_map.How I will do this?
What's "hash_map"? There is no such standard construct (yet, anyway).
any link with examples?
Have you tried Google?
transactions.insert(std::pair<std::string,Services *>("Aservice",new
xxxx));
transactions.insert(std::pair<std::string,Services *>("Vservice",new
fffff));
transactions.insert(std::pair<std::string,Services *>("Rservice",new
ttt));
...............

how I should replace this with hash_map?


It depends entirely what 'hash_map' exposes and what interface it has.
Do you think that knowing what "hash_map" is a prerequisite here? It's
not. Does it comply with the requirements for an associative container?
If it does, you probably need to use 'hash_map::value_type' instead of
'std::pair'. Maybe it's the same thing. Maybe not. Have you actually
tried compiling to see if it fails? If yes, where does it fail and with
what error message? If not, why not?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 20 '06 #2

P: n/a
In article <e2**********@news.datemas.de>,
"Victor Bazarov" <v.********@comAcast.net> wrote:
g wrote:
I wanna replace an std::map<std::string,Services*>
with hash_map.How I will do this?


What's "hash_map"? There is no such standard construct (yet, anyway).


Fwiw, when (not if) it becomes standard, the likely name is
std::unordered_map.

-Howard
Apr 20 '06 #3

P: n/a
g
hi !
I am googling but I haven't found something......

I wanna use the gnu/sgi extension

this code doesn't compile,it's from my std::map
transactions.insert(std::pair<std::string,Services *>("Aservice",new
xxxx));

I want to convert it to hash_map.....

hash_map<std::string,Services*,hash<std::string>> transactions;

this is the correct declaration?

Apr 20 '06 #4

P: n/a
In article <11**********************@t31g2000cwb.googlegroups .com>,
"g" <ge*******@yahoo.com> wrote:
hash_map<std::string,Services*,hash<std::string>> transactions;


Try:

hash_map<std::string,Services*,hash<std::string> > transactions;
^
space

Fwiw, that will be fixed in C++0X too... :-)

-Howard
Apr 20 '06 #5

P: n/a
On Thu, 20 Apr 2006 21:01:31 GMT Howard Hinnant
<ho************@gmail.com> waved a wand and this message magically
appeared:
hash_map<std::string,Services*,hash<std::string> > transactions;
^
space

Fwiw, that will be fixed in C++0X too... :-)


What will it look like in C++0X? I do find that '<some type<different
type> >' syntax a bit ugly.

--
http://www.munted.org.uk

Take a nap, it saves lives.
Apr 20 '06 #6

P: n/a
In article <20********************************@munted.org.uk> ,
Alex Buell <al********@munted.org.uk> wrote:
On Thu, 20 Apr 2006 21:01:31 GMT Howard Hinnant
<ho************@gmail.com> waved a wand and this message magically
appeared:
hash_map<std::string,Services*,hash<std::string> > transactions;
^
space

Fwiw, that will be fixed in C++0X too... :-)


What will it look like in C++0X? I do find that '<some type<different
type> >' syntax a bit ugly.


Sorry for the abbreviated message. My impression is that:

some_template<some_other_template<some_type> > my_object;

will be equivalent to:

some_template<some_other_template<some_type>> my_object;

But that's just my personal (and rushed) interpretation.

My latest factual information is that:

http://www.open-std.org/jtc1/sc22/wg...005/n1757.html

has been adopted into the C++0X working draft (which should be publicly
available in a few more days).

-Howard
Apr 21 '06 #7

P: n/a
g
thanks for your comments.

I still have a problem:

_gnu_cxx::hash_map<std::string,Services*, __gnu_cxx::hash<std::string>
transactions


transactions["CreateUser"]=new CreateUser;

the compiler give me this :

error: expected unqualified-id before '[' token

how to deal with?

thanks

Apr 21 '06 #8

P: n/a
g wrote:
thanks for your comments.

I still have a problem:

_gnu_cxx::hash_map<std::string,Services*, __gnu_cxx::hash<std::string>
transactions

Does your code include a ';' here? or was this a typo?

transactions["CreateUser"]=new CreateUser;

the compiler give me this :

error: expected unqualified-id before '[' token

how to deal with?

See above. Also I assume you have the appropriate includes.

Jeff Flinn
Apr 21 '06 #9

P: n/a
g
>Does your code include a ';' here? or was this a typo?

yes it does include ;.

I use <ext/hash_map>

Apr 21 '06 #10

P: n/a
g
please is there any link with examples?

Apr 21 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.