[C++-sig] wrapping operator=

2009-05-25 Thread Hans Roessler
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

Re: [C++-sig] wrapping operator=

2009-05-25 Thread William Ladwig
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

Re: [C++-sig] wrapping operator=

2009-05-25 Thread Hans Roessler
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

Re: [C++-sig] wrapping operator=

2009-05-25 Thread Stefan Seefeld
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