C++ – How ubiquitous is hash_map

ccompiler-constructionportability

The hash_map and hash_set headers aren't included in the C++ standard yet, but they're available as extensions with all the compilers I've used lately.

I'm wondering how much I can rely on these in real code without sacrificing portability. I'm working on tools projects that need to run on a host of architectures and compilers, including:

  • Linux (x86_64, AMD/Intel): GCC, Intel, Portland Compilers
  • AIX (Power): GCC, xlC
  • Cray XT Series (AMD): GCC, Portland, Pathscale Compilers
  • IBM Blue Gene Series (Power): xlC, GCC
  • SGI Altix (Itanium): Intel compilers
  • Windows: Not really a priority, but feel free to provide useful answers.

I realize some of these are pretty exotic, but that's not the point. What are your experiences with STL extensions across multiple platforms and compilers? Are they ubiquitous yet? Would you use them in your project?

Best Answer

I would probably look for the boost equivelant and use that. At least they have some pressure from their users to be platform independent. I can't imagine what would happen if you filed a bug against GCC and Intel compilers and told them to reconcile their differences on how hash_map was implemented. At best you would be able to get them to talk to each other. Suppose you even acheived that, then you've only fixed how Intel and GCC compilers are different. Good luck getting everyone else together and solving the problem within a few years.

At least with boost you know any differences across platforms are being worked out by one organization..

EDIT The boost equivalent is apparently unordered set or unordered map. (thanks Head Geek)