[C++-SIG] Const-correctness with PythonExtensionBase/PythonExtension<T>
Steve Harris
sharris at primus.com
Sun May 14 20:42:18 CEST 2000
Perhaps this topic has been covered before, but I just ran into it
while working on my first Python extension module using CXX.
Why are none of the virtual methods on PythonExtensionBase const? For
a particular example, consider PythonExtensionBase::sequence_length(),
defined as
virtual int sequence_length();
It seems that the signature should be more like
virtual int sequence_length() const;
to permit it to be called on a const PythonExtension<T>
instance. Additionally, the PythonExtension::add_varargs_method() and
friends should be able to receive a pointer to a const member
function.
I've dug into the add_varargs_method() function far enough to see that
we'd need a second map of function pointers to the const ones. Some
reworking would be required in there. But it seems like it should be
possible to make certain member functions const so that if you're
calling your Python-bound types from C++, you could still respect the
const semantics we know and love.
Yes, Python doesn't understand the distinction between const and
non-const variable, but our C++ binding should. If this debate is
already over, please point me to that discussion. If it's just a
current oversight in want of implementation improvement, then I'd like
to help with that.
--
Steven E. Harris
Primus Knowledge Solutions, Inc.
http://www.primus.com
More information about the Cplusplus-sig
mailing list