[Cython] libcpp.string operators

Brent Pedersen bpederse at gmail.com
Wed Apr 20 02:22:14 CEST 2011


On Tue, Apr 19, 2011 at 6:08 PM, Brent Pedersen <bpederse at gmail.com> wrote:
> On Tue, Apr 19, 2011 at 2:45 PM, Brent Pedersen <bpederse at gmail.com> wrote:
>> 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:
>>
>> https://gist.github.com/929604
>>
>> 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")
>>    True
>>    """
>>    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&)
>
>
> it seems:
>
>        bint operator==(string&)
>
> is the correct syntax. i had copied the stuff from vector.pxd
>
>>
>> i get the error below. any ideas what i'm doing wrong?
>> thanks,
>> -brent
>>
>>
>>
>>
>>
>> === 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
>>    self.runCompileTest()
>>  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)"
>>
>

i updated the gist with the operators, didn't do iterators.
https://gist.github.com/929604


More information about the cython-devel mailing list