I need the unordered_map and tree classes ( described in GNU libstdc++ ), but neither of these libraries provides both:

 // работает только при LLVM library #include <unordered_map> // работает только при GNU library #include <ext/pb_ds/assoc_container.hpp> 

How can this problem be solved?

  • And where did you get the tree and what structure is meant by this? I do not remember this in the standard libraries, and there are a lot of different trees. - D-side
  • Found on the GNU GCC website: gcc.gnu.org/onlinedocs/libstdc++/ext/pb_ds/… - AivanF.
  • So this is a trie , not a tree . But this is still not a standard container. What do you need? Search tree? - D-side
  • @ D-side yes, PATRICIA tree. - AivanF.

1 answer 1

unordered_map lies in unordered_map . All C ++ 0x-compatible compilers.

tree (like the trie mentioned in the comments) is not a standard type and can easily not exist at all . Therefore, you will have to either take an external implementation (which is preferable for portability) (prefix tree is a popular thing, look for it), or use a compiler-specific hacks, which is bad, but can sometimes be justified.

With the help of the preprocessor and macros, you can include a certain header file only in Clang (or in those who pretend it is not very reliable):

 #ifdef __clang__ #include <unordered_map> #endif 

This is not the only way to detect Clang by the preprocessor, but on the list issued by clang -dM -E -xc /dev/null ( taken from the issue of detecting Clang ) it looked most appropriate.

Add macros to other compilers, #else and #elif to taste.