来自多个命名空间的 Cython 包装运算符<<
Cython wrapping operator<< from multiple namespaces
如何在Cython中包装操作符>> overload ?
//LIB.h
namespace LIB
{
class Point
{
friend std::istream &operator >> (std::istream &in, Point &pt)
bool operator == (const Point &pos) const
...
}
}
已经有一个声明为namespace "LIB":
的命名空间,那么我如何处理std::命名空间?
#LIB.pxd
cdef extern from "LIB.h" namespace "LIB":
cdef cppclass Point:
#friend std::istream &operator >> (std::istream &in, Point &pt)
bint operator == (const Point &pos) const
...
这里它解释了多个cdef extern块是可能的,但我不知道这将如何工作,因为我不能重新定义类。
我认为最简单的解决方案是假装Cython operator<<
是std::istream
忘记朋友的东西的方法。然后,c++编译器将对这些片段进行分类。所以这里似乎是一个工作的解决方案(它编译,但我没有去所有的方式来测试它):
这是我的LIB.h
包装文件:
#include <iostream>
namespace LIB {
class Point {
friend std::istream &operator << (std::istream &in, Point);
};
}
Cython包装器应该如下所示:
cdef extern from "LIB.h" namespace "LIB":
cdef cppclass Point:
pass
cdef extern from "<iostream>" namespace "std":
cdef cppclass istream:
istream &operator << (Point)
istream cin
编译器接受以下文件:
cimport lib
def foo():
cdef lib.Point bla
lib.cin << bla
供参考,我用:
编译cython --cplus bla.pyx
g++ `python-config --cflags` bla.cpp -c
相关文章:
- 如何在c++17中制作一个模板包装器/装饰器
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- std::vector的包装器,使数组的结构看起来像结构的数组
- 呼叫运营商<<临时
- 如何在c++迭代器类型中包装std::chrono
- 是否可以用"iostream"包装现有的TCP/OOpenSSL会话
- 用pybind11包装C++抽象类时出错
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 为左值和右值的包装器实现C++范围
- <<操作员在下面的行中工作
- C结构,其指针将被包装在unique_ptr中
- 如何包装第三方DLL在R中使用
- 在类型和包装器之间reinterpret_cast是否安全<Type>?
- 将 N-arg 函数包装到另一个函数中
- 元组由 Swig 生成的 Python 包装器返回,用于C++向量
- 包装一个对象并假装它是一个 int
- 使用 Python Extension API 包装复杂C++类
- 外壳包装器句柄/执行交互式命令管道C++ UNIX
- 包装C++类时不完整的类型 GLFWwindow
- 将函数包装器转换为 std::function