c++ - Cython wrapping operator<< from multiple namespaces -
how can wrap operator >> overload in cython?
//lib.h namespace lib { class point { friend std::istream &operator >> (std::istream &in, point &pt) bool operator == (const point &pos) const ... } } there namespace declared namespace "lib":, how deal std:: namespace?
#lib.pxd cdef extern "lib.h" namespace "lib": cdef cppclass point: #friend std::istream &operator >> (std::istream &in, point &pt) bint operator == (const point &pos) const ... here explains multiple cdef extern blocks possible, don't see how work since cannot redefine class.
i think easiest solution pretend cython operator<< method of std::istream forgetting friend stuff. c++ compiler sort out pieces. here seems working solution (it compiles didn't went way test it):
here lib.h wrapped file:
#include <iostream> namespace lib { class point { friend std::istream &operator << (std::istream &in, point); }; } and cython wrapper should follows:
cdef extern "lib.h" namespace "lib": cdef cppclass point: pass cdef extern "<iostream>" namespace "std": cdef cppclass istream: istream &operator << (point) istream cin then following file accepted compiler:
cimport lib def foo(): cdef lib.point bla lib.cin << bla fyi, compiled with:
cython --cplus bla.pyx g++ `python-config --cflags` bla.cpp -c
Comments
Post a Comment