如何在Android中使用unordered_map?

7
我正在尝试使用在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]

由于 "unordered_map" 存在于 gnu-libstdc++/4.6/include/ 和 gnu-libstdc++/4.6/include/tr1/ 中,所以我相信可以使用它。

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

#include <tr1/unordered_map.h>

#include <unordered_map>

那么,如何使用它呢?__gnu_cxx::unordered_map没有被识别... 我不知道如何查找这些信息。

2个回答

5

如果您不想或不需要C++11支持,则可以使用STLPort提供的功能:

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

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


2

我最终通过在我的Android项目中添加C++11支持找到了一种方法。一旦集成了C++11,就不需要STLPort或Boost。使用"unordered_map"如下所示:

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

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接