我想用c++标记一组无符号整数,并在Python中修改它:
%load_ext Cython
%load_ext cythonmagic
%%cython
# distutils: language = c++
from libcpp.set cimport set as cpp_set
from cython.operator cimport dereference as deref
def modify_test_data():
cdef (cpp_set[int])* s = new cpp_set[int]()
print deref(s), type(deref(s))
deref(s).add(1)
print deref(s)
modify_test_data()
输出:
^{2}$我不确定我是否需要deref的东西,但是没有它,类型就不匹配了。有人能解释一下我是怎么做到这一点的吗?在
AFAICT,您将python的^ {< CD1>}与C++的^ a1}合并。后者的方法是}(与前者一样)。在
insert
,而不是{如果将相关行更改为:
输出变成:
^{pr2}$相关问题 更多 >
编程相关推荐