如何在Android中使用unordered_map?

Jon*_*rin 6 c++ android unordered-map hashmap c++11

我正在尝试使用在Android NDK中定义的hash_map,但我收到了"弃用警告":

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]
Run Code Online (Sandbox Code Playgroud)

由于"unordered_map"存在于gnu-libstdc ++/4.6/include /以及gnu-libstdc ++/4.6/include/tr1 /中,我相信有一种方法可以使用它.

关键是我找不到它.以下哪一项是正确的(如果有的话):

#include <tr1/unordered_map.h>

#include <unordered_map>
Run Code Online (Sandbox Code Playgroud)

然后,如何使用它?__gnu_cxx :: unordered_map无法识别...我不知道如何找到这些信息.

小智 5

如果您不想/需要C++ 11支持,您可以使用STLPort中的一个:

// Here we are referencing the stlport one:
#include <unordered_map>
...
std::tr1::unordered_map<int, int> test;
Run Code Online (Sandbox Code Playgroud)

这是因为STLPort 在tr1名称空间中定义了unordered_map,但STLPort标头不在任何/ tr1 /文件夹中.


Jon*_*rin 2

我最终找到了一种方法,在我的 Android 项目中添加 C++11 支持。当我们知道时很容易,但我花了一些时间才弄清楚。STLPort 和 Boost 都不需要。一旦集成了 C++11,我就可以使用“ unordered_map ”,如下所示:

#include <unordered_map>
...
std::unordered_map<int, int> test;
Run Code Online (Sandbox Code Playgroud)

我创建了一个新问题来解释如何在 Android 中启用 C++11支持。