From: Pearu Peterson (boost_at_[hidden])
Date: 2001-04-22 14:37:31


Hi!

Is there a way to overload from_python functions defined by class_builder?
To be specific, consider for example

        do_it_yourself_converters.cpp

with the following (and only the following) addition:

  IndexingSet(int i) { /* ... */ }; // as a public constructor in
                                    // IndexingSet

The objective is to have the following Python session:
>>> s = IndexingSet()
>>> s.add(4)
(which would normally result TypeError: int)

My plan was to provide the following from_python function:

IndexingSet from_python(PyObject * o, python::type<const IndexingSet &>)
{
  if (PyInt_Check(o))
    return IndexingSet(PyInt_AS_LONG(o));
  return from_python(o, python::type<IndexingSet &>());
}

but then the compiler complains about 'new declaration' and 'ambiguates
old declaration' of this from_python function.

Is there any other way to jump in into the chain of from_python functions
that is generated by class_builder?

I do know that the alternative is to wrap IndexingSet with another class
that defines add(int). But having my own from_python function for
IndexingSet would simplify the wrapping considerably (as it does in the
MillerIndex case, for example).

Thanks,
        Pearu