2

I'd like to use unordered_set without installing Boost. I tried to add --std=gnu++0x but it is not a recognized option. Does v4.1.2 include unordered_set? If so, how do I get the header file for it?

This is a Centos 4 machine.

WilliamKF
  • 41,123
  • 68
  • 193
  • 295

2 Answers2

3

unordered_set is in the purview of the standard C++ library, not gcc, the compiler (although most programs built using gcc are linked against libstdc++).

The way you generally include it is #include <tr1/unordered_set>. Then, to use it, you must either do a using std::tr1::unordered_set; or qualify the name each time.

The C++ standard version you choose to use doesn't have much effect because that's the language standard, and the availability of standard library constructs is semi-independent.

Borealid
  • 95,191
  • 9
  • 106
  • 122
  • I tried the normal include which is not located by compiler. Does this work for you on v4.1.2? – WilliamKF Jan 28 '12 at 17:07
  • `unordered_set` is in the purview of `libstdc++`, **not** `glibc`. And the `libstdc++` itself is actually *a part of* GCC. So, uhm, it actually has a lot to do with the compiler and nothing to do with `glibc`. –  Jan 28 '12 at 17:52
  • @Fanael I really should have said "the standard library". I'll change that. And you can actually build C++ programs linked against alternate libraries, believe it or not. – Borealid Jan 28 '12 at 17:54
  • @Borealid: I don't believe. But seriously, what's the likelihood of the OP using alternate library and not knowing if and where it has `unordered_set`? –  Jan 29 '12 at 10:12
0

IIRC, gcc-4.2 did not have unordered containers at least not in namespace std. I know -std=c++0x was not in place till around gcc-4.3.

Have you tried this:

#include <tr1/unordered_set>
...
  std::tr1::unordered_set<int> usint;
...

Notice the tr1/ in the header.

Having said that, gcc-4.1 is pretty old. Any chance you could try say gcc-4.5 or 4.6 and use the std container?

emsr
  • 15,539
  • 6
  • 49
  • 62