Are C++11 containers supported by Cython?

落爺英雄遲暮 提交于 2019-12-04 04:22:28

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 now supported unordered_map and unordered_set since 0.20.2.

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

Current cython versions allow them.

Make sure your setup.py contains something like:

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!