[Cython] libcpp.string operators

Brent Pedersen bpederse at gmail.com
Tue Apr 19 22:45:55 CEST 2011

hi, i have been using a stub for the c++ <string> in a lot of my work.
i decided to have a go at doing a proper string.pxd, pasted here:


other than the operators, it's mostly implemented with tests. but when
i try the operators
with this test:

def test_equal_operator(char *a, char *b):
    >>> test_equal_operator("asdf", "asdf")
    cdef string s = string(a)
    cdef string t = string(b)
    cdef bint same = t == s
    return same

and this declaration in the pxd:

    bint operator==(string&, string&)

i get the error below. any ideas what i'm doing wrong?

=== Got errors: ===
152:23: Invalid types for '==' (string, string)

ERROR: runTest (__main__.CythonRunTestCase)
compiling (cpp) and running cpp_stl_string
Traceback (most recent call last):
  File "runtests.py", line 569, in run
  File "runtests.py", line 400, in runCompileTest
    self.test_directory, self.expect_errors, self.annotate)
  File "runtests.py", line 546, in compile
    self.assertEquals(None, unexpected_error)
AssertionError: None != u"152:23: Invalid types for '==' (string, string)"

More information about the cython-devel mailing list