简体   繁体   中英

How to use unordered_map in Android?

I am trying to use a hash_map, defined in the Android NDK, but I get a "deprecation warning":

ndk/sources/cxx-stl/gnu-libstdc++/4.6/include/ext/../backward/backward_warning.h:33:2:
error: #warning This file includes at least one deprecated or antiquated header which may 
be removed without further notice at a future date. Please use a non-deprecated interface 
with equivalent functionality instead. For a listing of replacement headers and 
interfaces, consult the file backward_warning.h. To disable this warning use -Wno-
deprecated. [-Werror=cpp]

And since "unordered_map" is present in gnu-libstdc++/4.6/include/ and also in gnu-libstdc++/4.6/include/tr1/, I believe that there is a way to use it.

The point is that I cannot find it. Which of the following is the right one (if any):

#include <tr1/unordered_map.h>

#include <unordered_map>

And then, how to use it? __gnu_cxx::unordered_map is not recognized... and I don't know how to find this information.

In case you don't want/need C++11 support, you can use the one from the STLPort using:

// Here we are referencing the stlport one:
#include <unordered_map>
...
std::tr1::unordered_map<int, int> test;

That's because STLPort defines unordered_map inside tr1 namespace, but the STLPort header is not inside any /tr1/ folder.

I eventually found a way by adding C++11 support in my Android project. Pretty easy when we know it, but I took some time to figure it out. Neither STLPort nor Boost were needed. Once C++11 was integrated, I could use " unordered_map " as follows:

#include <unordered_map>
...
std::unordered_map<int, int> test;

I created a new question to explain how to enable C++11 support in Android here .

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