On Fri, Nov 5, 2010 at 6:12 PM, Martin Albrecht
<martinralbre...@googlemail.com> wrote:
> Hi there,
>
> in the Sage library we cannot write the following C++ code:
>
>  Class a = Class()
>
> since Cython turns the statement
>
>  cdef Class a = Class()
>
> into
>
>  Class a
>  a = Class()
>
> which only works when there is a copy constructor. In the Sage library we
> sometimes use the follow construct in order to work around this Cython vs. C++
> incompatibility:
>
>  Class a
>  Construct<Class>(&a)
>
> For example check the PolyBoRi wrapper and the NTL wrapper. There are also
> variants of this called Construct_p<Class>(&a, one_parameter) and so forth.
>
> I'm wrapping CryptoMiniSat at the moment (a general purpose (!) SAT solver
> which one this year's SAT Race). When I try to use this construct in my
> wrapper I get a complaint from g++ that Construct wasn't  defined in the
> scope; yet I cannot see what we are doing special in the PolyBoRi or NTL
> wrapper which would have an affect on that. Also searching online for this
> construction also returned nothing of interest as far as I can tell, mainly
> because one is overwhelmed with C++ constructor introductions. Thus, my
> question: does any of you C++ gurus now where this thing is defined and what I
> have to do (or not to do) in order to use it?

If heap-allocated instances are fast enough, you can use the much
easier C++ support (recently merged into Sage):

   cdef Class *a = new Class()
   del a

What we use in Sage is probably buried in some .h file. I think the
official term is "placement new" where we allocate a chunk of the
Python object struct to hold the data.

- Robert

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to