Commit 193dc29a authored by scoder's avatar scoder

Merge pull request #399 from insertinterestingnamehere/assignment

Enable overloading the assignment operator.
parents c39b0766 7a1de56a
......@@ -2547,7 +2547,7 @@ supported_overloaded_operators = cython.declare(set, set([
'+', '-', '*', '/', '%',
'++', '--', '~', '|', '&', '^', '<<', '>>', ',',
'==', '!=', '>=', '>', '<=', '<',
'[]', '()', '!',
'[]', '()', '!', '='
]))
def p_c_simple_declarator(s, ctx, empty, is_type, cmethod_flag,
......
# tag: cpp
"""
PYTHON setup.py build_ext --inplace
PYTHON -c "from assignment_overload import test; test()"
"""
######## setup.py ########
from distutils.core import setup
from Cython.Build import cythonize
setup(ext_modules=cythonize("*.pyx", language='c++'))
######## assign.cpp ########
class wrapped_int {
public:
long long val;
wrapped_int() { val = 0; }
wrapped_int(long long val) { this->val = val; }
wrapped_int &operator=(const wrapped_int &other) {
this->val = other.val;
return *this;
}
};
######## assign.pxd ########
cdef extern from "assign.cpp" nogil:
cppclass wrapped_int:
long long val
wrapped_int()
wrapped_int(long long val)
wrapped_int& operator=(const wrapped_int &other)
######## assignment_overload.pyx ########
from assign cimport wrapped_int
def test():
cdef wrapped_int a=wrapped_int(2), b=wrapped_int(3)
a = b
assert &a != &b
assert a.val == b.val
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment