Boost logo

Boost :

From: Anton Gluck (gluc_at_[hidden])
Date: 2000-11-29 00:33:46


Dave,

It's rather amazing how there is always some new problem cropping up. I'm
now trying to wrap a function that returns a pointer to a
std::valarray<int>. I wrote a to_python for this:

PyObject* to_python(const std::valarray<int>* a)
{
    return to_python(*a);
}

But I'm getting these errors:

d:\py_cpp/extclass.h(280) : error C2665: 'py_extension_class_converters' :
none of the 18 overloads can convert parameter 1 from type 'struct
py::Type<class std::valarray<int> >'
        D:\cluster\glue.cpp(153) : see reference to function template
instantiation 'struct _object *__cdecl py::to_python(const class
std::valarray<int> &)' being compiled
d:\py_cpp/extclass.h(280) : error C2228: left of '.to_python' must have
class/struct/union type
        D:\cluster\glue.cpp(153) : see reference to function template
instantiation 'struct _object *__cdecl py::to_python(const class
std::valarray<int> &)' being compiled

The offending line 153 is the line "return to_python(*a);" from above. I
have written several other to_pythons, but didn't have that problem yet;
on the other hand, the return type had never been from std.

I thought the problem might be that std::valarray<int> is not a PyObject,
so I tried wrapping it like this:

py::ClassWrapper<std::valarray<int>> valarray_class(ClusterForPy,
"valarray");

but got these errors:

D:\cluster\glue.cpp(345) : error C2146: syntax error : missing ',' before
identifier 'valarray_class'
D:\cluster\glue.cpp(345) : error C2065: 'valarray_class' : undeclared
identifier
D:\cluster\glue.cpp(345) : error C2143: syntax error : missing '>' before
';'

I also tried this:

py::ClassWrapper<std::valarray> valarray_class(ClusterForPy, "valarray");

These were the errors:

D:\cluster\glue.cpp(345) : error C2514: 'py::ClassWrapper<class
std::valarray,class py::HeldInstance<class std::valarray> >' : class has
no constructors
D:\cluster\glue.cpp(345) : error C2262: 'valarray_class' : cannot be
destroyed

I'm now thinking of creating a convenience class that internally deals
with std::valarray and provides a getItem() to access the array elements
from Python. Does that sound reasonable?

Thanks again,

Toni


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk