Stefan Behnel wrote:
> Hi Dag,
> 
> given that I'm really far from a C++ expert, I'll try to keep my comments
> at a meta-level.
> 
> Dag Sverre Seljebotn wrote:
>> Ahh; the missing piece: Iterators are nothing special in C++. There's 
>> absolutely *no* concept of an iterator in the language. It's just a set 
>> of conventions.
> 
> Ah, thanks, didn't know that. But that doesn't mean they don't exist. It's
> perfectly ok to support only the common conventions, and if users need
> more, help them getting there, but without impacting the language itself.

I'd love to write "for item in some_cpp_col" eventually, I just think 
the basics should be considered first.

> I don't feel a need to hold the gun when users shoot their own foot. If
> they want to, the language should try not to get in their way (in the worst
> case, you can always go and define a header file with wild macros), but it
> should not lead them there, either.
> 
> There is no use in /integrating/ C++ into Cython. I think the idea is more
> to make the sane parts of C++ easy to use and interface with. Side effects
> on arbitrary operators that are visible from Cython code do not fall into
> that category, IMHO. After all, you will read the Cython code and expect it
> to make sense, even if you do not know that there is some wild C++ operator
> overloading trickery going on in the background.

Thanks for summing up my sentiments so nicely :-) We agree here.

My current stance is therefore that  I think we should *not* try to make 
sense of what C++ declarations would mean in Cython, but rather make it 
easy to write Cythonic wrappers for C++ code.

But then you need to be able to call the operators in C++ somehow, to 
create the wrapper, as there often is no other way of calling them. The 
problem is that C++ is so powerful and people do use that power.

So my/current thoughts (though Robert and Danilo are calling the shots) 
is along the lines of allowing inline C++ code. The declared interface 
must be Cythonic, but you can use C++ in the bridge in the C++. Ugly but 
effective.

Thus the ++/-- problem can be solved like this (a bit verbose, but 
syntax could perhaps be improved):

cdef extern "C++" class SomeIterator:

      # expose C++ only operation as Cython-only method call
     cdef inline SomeIterator movenext(self):
         return inline_cpp("++self")

     cdef inline SomeIterator moveprev(self):
         return inline_cpp("--self")

     cdef inline double __next__(self):
         return inline_cpp("*self++")

and so on. Obviously one could improve syntax to make it less verbose, 
provide defaults for operators etc.

(Some are left, like the conversion operators, copy constructors, 
operator=, etc., which must still be handled case-by-case)

-- 
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to