无法修改cython中的集合
Cannot modify set in cython
我想在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()
输出:
set([]) <type 'set'>
set([]) # here i would expect 'set([1])'
我不确定我是否需要deref的东西,但如果没有它,类型就不匹配。有人能解释一下我是如何做到这一点的吗?
AFAICT,您将Python的set
与C++的std::set
混为一谈。后者的方法是insert
,而不是add
(与前者一样)。
如果您将相关行更改为:
deref(s).insert(1)
输出变为:
set([]) <type 'set'>
set([1])
相关文章:
- 处理多个异常集合的C++方法
- 给定n个元素的m个集合.在C++中找到出现在最大集合数中的元素
- 如何将ampl中的集合表示为c++中的向量
- 检查值是否在集合p1和p2中,但不在p3中
- 带过滤器的现代迭代c++集合
- 如何将结构插入到集合中并打印集合的成员
- 集合上的输出迭代器:assign和increment迭代器
- 如何将函数集合传递给客户端类,以便将它们当作客户端类本身的成员使用
- 实现一个在集合上迭代的模板函数
- 尝试使用集合函数时出现分段错误
- 互斥指针的集合
- c++找不到具有相同哈希的无序集合元素
- python集合的C++等价物是什么.计数器
- 如何在C++中递归地按相反顺序打印集合
- Python 集合.计数器,如何避免重复查找
- 如何写向量的无序向量集,即unordered_set<向量<向量<int>>集合?
- 从具有自定义排序的向量创建集合
- 显示字符串的集合和子集
- 重载运算符的范围是什么?它是否会影响作为类成员的集合的插入函数?
- 无法修改cython中的集合