我有一个类似的C++类型:
template <typename T>
class Vector {
struct Iterator {
};
};
Run Code Online (Sandbox Code Playgroud)
在C++中我可以使用Iteratoras Vector<int>::Iterator.
如何将它包装起来以便从Nim中使用它?c2nim发出
type Vector[T] {.importcpp...} = object
type Iterator[T] {.importcpp...}
Run Code Online (Sandbox Code Playgroud)
因为nim没有嵌套类型,所以不会编译,Vector<T>::Iterator<T>而是会生成而不是Vector<T>::Iterator.
我可以在Nim中使用非嵌套类型:
type VectorIterator[T] {.importcpp: "Vector::Iterator".}
var v : VectorIterator[cint]
Run Code Online (Sandbox Code Playgroud)
而这自然会产生Vector::Iterator<int>,这是错误的(它应该是Vector<int>::Iterator).
有没有办法改变导入规范以产生正确的输出?
我想听一个事件流,然后根据收到的事件有条件地停止收听.
总之,我想用:
var subscription = stream.listen((event) {
if (f(event)) {
doStuff();
subscription.cancel();
} else {
doOtherStuff();
}
});
Run Code Online (Sandbox Code Playgroud)
这显然不起作用; subscription在创建侦听器之前不存在,从而导致错误.
我该怎么做呢?