简体   繁体   中英

Using unordered_map of C++0x

I am using an unordered_map which is included as: #include <unordered_map> and the program is compiled as follows: g++ Test.cc -std=gnu++0x -o test Am I using the unordered_map of TR1 or that of C++0x. Or is it both the same?

I believe gcc puts their TR1 headers in <tr1/unordered_map> , so you should be getting the C++11 version. But they are very similar.

GCC has tr1 headers in tr1 subdirectory. Plus there is the tr1 namespace.

#include <tr1/unordered_map>
...
std::tr1::unordered_map<...>(...);

So unless you specifically did these things or did a similar "using" you've got the std ones.

The implementations are split but they are rather similar. There were just enough differences (initializer_list, comparison ops) to make maintenance of one file with all the conditionals and macros a pain.

This depends very much on the particular compiler version. For instance, GCC 4.4 basically just had some macro switches for your -std=c++0x option to do the namespace labelling appropriately, but would always end up pulling the actual code from tr1_impl/unordered_map , while GCC 4.6 has two entirely separate implementations, one in tr1/unordered_map.h and one in bits/unordered_map.h -- and the respective base class implementations in .../hashtable.h do in fact differ; the C++0x version has std::forward s everywhere etc.

Short answer: It depends.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM