Hello!
I want to wrap with boost.python a C++ class "DataCube" which has overloaded
the operator=.
The constructor DataCube::DataCube(double x) allocates huge amounts of memory
and fills it with x's.
The DataCube::operator=(double x) just overwrites the already allocated memory
with x's.
No
Generally how that situation is handled on the Python side is to use the
container emulation API, so that assigning all values would look like this to a
user of your class:
data[:] = 42.
To do this, you just need to write a small c++ wrapper to expose the
__setitem__(self, key, value) function
Thank you, William.
The __setitem__ emulation is definitely a better idea than the assign function,
as the class is actually a container type.
But still I am looking for a way to allow the simple "data=42." syntax with the
same result, because it would best copy the C++ syntax.
Hans
- U
Hans Roessler wrote:
But still I am looking for a way to allow the simple "data=42." syntax with the
same result, because it would best copy the C++ syntax.
Would it, really ? I think it would be extremely confusing, if it would
work. But it doesn't. "a = b" doesn't assign to an object, but