Is hash_map part of the STL?

94,396

Solution 1

The STL has hash_map, but the C++ Standard Library does not.

Due to a common misconception, you may think of the C++ Standard Library as "the STL", or of parts of your toolchain's implementation of the C++ Standard Library as "an STL implementation".

It is not.

It is also a great shame that both MSVC++ and GCC (which implement hash_map as a compiler-specific extension), place it in the std namespace, which is not only highly misleading, but also illegal per the standard. *sigh*

C++11 has introduced std::unordered_map, which is not dissimilar.

Solution 2

Quoting Wikipedia (emphasis added):

From the STL page:

The Standard Template Library (STL) is a software library partially included in the C++ Standard Library.

...and then from the hash_map page

In the C++ programming language, hash_map is the name of a hashed associative container in the Standard Template Library. It is provided by several implementors, such as the GNU C++ compiler and Microsoft's Visual C++. It is not part of the C++ Standard Library, but the C++ Technical Report 1 contains the very similar container unordered_map, which will be included in the upcoming C++0x standard.

So in short,

  • YES it's part of the STL.
  • But it IS NOT part of the standard library.
  • But it is supported by several very popular implementations.

Solution 3

Yes, hash_map is part of the STL. However, it is not part of C++03's standard library.

Solution 4

hash_map is a part of STL, but not a part of Standard C++(C++11). And there is a similar implementation of hash_map named "std::unordered_map" in standard C++: http://www.cplusplus.com/reference/unordered_map/unordered_map/

Currently, GNU C++ and MSVC++ have implemented hash_map for compiler extension, as well as Boost. Meanwhile, SGI has its own implementation for hash_map. You can refer to http://www.sgi.com/tech/stl/hash_map.html for details.

Share:
94,396
Jake
Author by

Jake

Updated on July 20, 2022

Comments

  • Jake
    Jake almost 2 years

    Quick question...Is hash_map part of the STL?

  • forsvarir
    forsvarir about 13 years
    @razlebe: you couldn't just say yes or no?
  • razlebe
    razlebe about 13 years
    @forsvarir: Of course, but quoting wikipedia lends my answer some credibility. ;)
  • Tony Delroy
    Tony Delroy about 13 years
    Importantly, knowing it's only moderately portable, if you choose to use it anyway then do check your compiler docs to find out which header and namespace it's in - it probably isn't a simple #include <hash_map> / std::hash_map<a, b> x, though it won't be much harder....
  • Alexandre C.
    Alexandre C. about 13 years
    There is no such thing as a STL standard.
  • fredoverflow
    fredoverflow about 13 years
    Really? I couldn't find hash_map in the C++0x FDIS. Do you have any evidence to support your claim?
  • Alexandre C.
    Alexandre C. about 13 years
    @forsvarir: it's difficult here. OP's question must be answered by "yes", but OP's intended question should be answered by "no"...
  • Fred Nurk
    Fred Nurk about 13 years
    @AlexandreC.: There is no STL standard from ISO, ANSI, etc., but there's no reason not to consider the STL documentation (e.g. at sgi.com) as its de facto standard.
  • forsvarir
    forsvarir about 13 years
    @Alexandre C.: Sorry, mild work banter (I work with razelbe)... it can be difficult to get a straight answer out of him sometimes :)
  • James Kanze
    James Kanze about 13 years
    @Alexandre C: Or rather there are several, depending on your definition of STL.
  • Lightness Races in Orbit
    Lightness Races in Orbit about 13 years
    @FredOverflow: Despite your misconception, there is only one STL.
  • Lightness Races in Orbit
    Lightness Races in Orbit about 13 years
    Even "partially included" is misleading, as it implies a verbatim copy and an ongoing dynamic identicality, neither of which are accurate.
  • razlebe
    razlebe about 13 years
    @Tomalak Geret'kal - Entirely woolly, I agree. But then so is the definition of the term STL, as demonstrated by the lack of concensus across the answerers here.
  • razlebe
    razlebe about 13 years
    @Tomalak Geret'kal: Thanks. :)
  • Lightness Races in Orbit
    Lightness Races in Orbit about 13 years
    @razlebe: There is only one definition of the term STL, even if most C++ programmers for whatever reason stubbornly refuse to accept it! :)
  • James Kanze
    James Kanze about 13 years
    @Tomalak Geret'kal: The meaning of words is determined by a consensus among the users. Regretfully, in the case of STL, there isn't really a consensus, and we have to consider that it has several different meanings, depending on who is using it. (The usage I prefer is that STL is the library defined at sgi.com/tech/stl, in which case, it contains hash_map. But not everyone uses the word in this way, so unless you know the author, you have to ask what they mean by it.
  • fredoverflow
    fredoverflow about 13 years
    @Tomalak: That's technically correct. Still, I think that Jake is not even aware of the STL and actually meant the C++ standard library.
  • Lightness Races in Orbit
    Lightness Races in Orbit about 13 years
    @FredOverflow: I agree. Yet another reason why the continued misuse of the term is dangerous and silly.
  • Lightness Races in Orbit
    Lightness Races in Orbit about 13 years
    @JamesKanze: I have decided the meaning of the word based on its technical and historical accuracy, and you shall follow me according to the word of Tomalak. This jovial response brought to you by the fact that you nevertheless prefer the proper meaning.
  • James Kanze
    James Kanze about 13 years
    @Tomalak Geret'kal Who says? :-) Seriously, who has the authority to say. The meaning of a word is determined by a consensus among the users and listeners. As is apparent from the comments here, there is no consensus with regards to STL.
  • Lightness Races in Orbit
    Lightness Races in Orbit about 13 years
    @JamesKanze: History, logic and me. ;) Most of the lack of consensus, frankly, is driven by ignorance (and I mean that with the greatest of respect) because several high-profile authors have unfortunately chosen an inaccurate term and so learning institutions have taught wrongly. Yes, I say "wrongly" because they are causing the problem, not falling into the trap that it causes.
  • James Kanze
    James Kanze about 13 years
    @Tomalak You (nor any other single person) can decide on the meaning of a word; meanings are established by a consensus. If it is just you and I discussing things together, we have a consensus---I know a couple of other people who agree with it as well (e.g. Bjarne Stroustrup). In an open forum like this, we have to take into account the consensus of the entire community, and regretfully, in the case of STL, there isn't one, so we have to be more explicit in order to be sure of being understood.
  • Lightness Races in Orbit
    Lightness Races in Orbit about 13 years
    @JamesKanze: I have decided that the meaning of the word should reflect what the word means. I have decided that everyone will follow this no matter what. It will be written into law at the next available opportunity. Thanks for playing.
  • James Kanze
    James Kanze about 13 years
    @Tomalak Geret'kal: I agree that ignorance may have been one of the root causes for the lack of consensus to begin with, but the current situation is that there is a lack of consensus, even among very intelligent and very competent people. So we have to take that into account if we want to communicate effectively.
  • Lightness Races in Orbit
    Lightness Races in Orbit about 13 years
    @JamesKanze: It's possible to communicate effectively by always using the most logical, correct and accurate term, assuming the audience has not been blinded by the ignorance, and then bash them over the head with the truth if they look confused. Every time. It might be a bit irritating, but after a few hundred years only the correct term will be used. Let's start now!