Jackson Hoy Loper wrote:
> lol... good trick! thanks!
>
> it depends on STL having provided a copy constructor, of course... but
> they always do, so life is good. god, the STL is so weird...
Actually, this is a given -- IIRC,
SomeClass a = something();
is just syntax candy for
SomeClass a(something());
When you call collection.begin(), it actually returns the iterator by
value, and the only way it is ever going to get into a stack variable is
by having a copy constructor called.
If you still want to have a look at improving Cython in this area, like
you indicated initially, adding C++ "new" and "delete" natively to the
Cython language would be a good place to start, and removing much need
for some hacks :-) Something like
cimport cython
def f():
cdef MyClass* pobj = cython.new(MyClass, ctor_arg_1, ctor_arg_2)
... do stuff ...
cython.delete(pobj)
wouldn't be too hard to implement. (Have a look at
TransformBuiltinMethods in ParseTreeTransforms.py to have a taste. You
would need to intercept those two methods and replace them by CppNewNode
and CppDeleteNode which you would need to add in Nodes.py. The "sizeof"
and "address" functions does similar things; the former takes in a type
as one of the arguments and the latter returns a pointer, so much of
what you'd need is contained in those).
> you all have very much made my life better :). i'd be happy to write
> something up on using STL with cython... is there a nice
> out-of-the-way place to put something like that?
Add a page in the Tips and Tricks section on wiki.cython.org.
--
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev