【问题标题】:How to use unordered_map in Android?如何在 Android 中使用 unordered_map?
【发布时间】:2013-03-10 19:55:51
【问题描述】:

我正在尝试使用在 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 无法识别...而且我不知道如何找到这些信息。

【问题讨论】:

    标签: android c++ c++11 hashmap unordered-map


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      如果您不想要/不需要 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/ 文件夹内。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-08-17
        • 2014-01-17
        • 1970-01-01
        相关资源
        最近更新 更多