[Cython] wrapping c++

Neal Becker ndbecker2 at gmail.com
Tue Mar 4 22:28:15 CET 2008


Robert Bradshaw wrote:

> On Mar 4, 2008, at 9:07 AM, Stefan Behnel wrote:
> 
>> Neal Becker wrote:
>>> Stefan Behnel wrote:
>>>
>>>> William Stein wrote:
>>>>> cdef extern from "":
>>>>>     void DEFINE_SET "#define SET(a,b,c) a[b]=c; //"()
>>>>>     void SET(intvec, int, int)
>>>>> DEFINE_SET()
>>>>>
>>>>> The key thing is the evil dirty trick to define a SET macro
>>>>> directly in
>>>>> Cython.
>>>>
>>>> "Evil" and "dirty" were exactly the two words that came to my mind
>>>> before I even got to reading your own comment on this. :)
>>>>
>>>> I would really put something like this into an external header
>>>> file, and
>>>> just declare "SET()" as being external...
>>>>
>>> Any thoughts on what it would take to support a non-evil
>>> implementation?
>>
>> The above is ok, except that I wouldn't write something like this
>> into a
>> Cython file. You will likely need a header file for a couple of low-
>> level
>> things anyway, so I would just create one with the "#define" above and
>> keep the 'cdef extern from "theheader.h"' for the "SET()" function
>> (read:
>> macro).
> 
> 
> I've been thinking about adding C++ operator support to Cython. I'm
> not sure of the best syntax to use for this, but it should be
> possible to tell Cython that a certain type has overloaded operators,
> and also to be able to specify a specific function to use for such
> operators (for example, this would be useful in numpy for fast
> indexing of arrays--one would define a macro that does the dirty work
> and it would be like the PEX a{i,j}.
> 
> - Robert

Is operator the real issue here?  In the std::vector example, there is 'at',
which does (almost) the same thing as operator[].  My problem is that
both 'at' and 'operator[]' return int&, and to use them you need to
say 'at[i]=j', which I don't know how to do in cython (except for the macro
version above,  or to write additional wrapper code in more c++ headers).



More information about the Cython-dev mailing list