简体   繁体   English

Cython支持C ++ 11容器吗?

[英]Are C++11 containers supported by Cython?

Cython gives us an easy way to import C++ standard library data structures, eg: Cython为我们提供了一种导入C ++标准库数据结构的简便方法,例如:

  from libcpp.vector cimport vector
    from libcpp.utility cimport pair

But what about newer containers introduced with C++11: std::unordered_map , std::unordered_set etc. Are they supported in the same way? 但是C ++ 11引入的较新的容器呢: std::unordered_mapstd::unordered_set等。它们是否以相同的方式受支持? I could not find the appropriate import statement. 我找不到适当的导入语句。

Current cython versions allow them. 当前的cython版本允许它们。

Make sure your setup.py contains something like: 确保您的setup.py包含以下内容:

ext_module = Extension(
    "foo",
    ["foo.pyx"],
    language="c++",
    extra_compile_args=["-std=c++11"],
    extra_link_args=["-std=c++11"]
)

You can then use 然后,您可以使用

from libcpp.unordered_map cimport unordered_map

like for any other STL class. 就像其他任何STL类一样。

Cython doesn't support them by default, but you could probably create your own interface, following the structure of https://github.com/cython/cython/blob/master/Cython/Includes/libcpp/map.pxd . Cython默认情况下不支持它们,但是您可以按照https://github.com/cython/cython/blob/master/Cython/Includes/libcpp/map.pxd的结构创建自己的界面。

Cython now supported unordered_map and unordered_set since 0.20.2 . 0.20.2开始, Cython现在支持unordered_map和unordered_set。

from libcpp.unordered_map cimport unordered_map
from libcpp.unordered_set cimport unordered_set

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM