Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cdef extern from "XY.h":
- cdef cppclass _XY:
- vector[double] getVector() except +
- cdef class XY:
- cdef _XY _this
- ...
- def getVector():
- return self._this.getVector()
- cdef extern from "<utility>" namespace "std":
- vector[double] move(vector[double]) # Cython has no function templates
- def getVector():
- return move(self._this.getVector())
- # distutils: language = c++
- cdef extern from * namespace "polyfill":
- """
- namespace polyfill {
- template <typename T>
- inline typename std::remove_reference<T>::type&& move(T& t) {
- return std::move(t);
- }
- template <typename T>
- inline typename std::remove_reference<T>::type&& move(T&& t) {
- return std::move(t);
- }
- } // namespace polyfill
- """
- cdef T move[T](T)
- # distutils: language = c++
- cdef extern from *:
- """
- #include <iostream>
- #define PRINT() std::cout << __PRETTY_FUNCTION__ << std::endl
- struct Test {
- Test() { PRINT(); }
- ~Test() { PRINT(); }
- Test(const Test&) { PRINT(); }
- Test(Test&&) { PRINT(); }
- Test& operator=(const Test&) { PRINT(); return *this; }
- Test& operator=(Test&&) { PRINT(); return *this; }
- };
- void f(const Test&) { PRINT(); }
- void f(Test&&) { PRINT(); }
- """
- cdef cppclass Test:
- pass
- cdef void f(Test)
- from move cimport move
- cdef Test t1, t2
- print("# t1 = t2")
- t1 = t2
- print("# t1 = move(t2)")
- t1 = move(t2)
- print("# f(t1)")
- f(t1)
- print("# f(move(t1))")
- f(move(t1))
- print("# f(move(move(t1)))")
- f(move(move(t1)))
- print("# f(move(move(move(t1))))")
- f(move(move(move(t1))))
- $ python3 -c "import test"
- Test::Test()
- Test::Test()
- # t1 = t2
- Test& Test::operator=(const Test&)
- # t1 = move(t2)
- Test& Test::operator=(Test&&)
- # f(t1)
- void f(const Test&)
- # f(move(t1))
- void f(Test&&)
- # f(move(move(t1)))
- void f(Test&&)
- # f(move(move(move(t1))))
- void f(Test&&)
- Test::~Test()
- Test::~Test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement