[C++-sig] constructor wrappers?

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Thu May 30 00:05:42 CEST 2002


Would something like the following be possible/desirable?

struct any
{
  any(int a=0, int b=0, int c=0) { ... }
};

any any_from_python_list_or_tuple(PyObject* list_or_tuple)
{
  // extract between 0 and 3 int from a list or tuple and use to construct
  // an object any_instance.
  return any_instance;
}

BOOST_PYTHON_MODULE_INIT(any)
{
  boost::python::module this_module("any");

  this_module.add(
    boost::python::class_<any>("any")
      .def_init(any_from_python_list_or_tuple)
  );

}

I guess what I am after is an equivalent of the thin wrappers for member
functions, some easy-to-use flexible mechanism for "customizing" constructors
when they are exposed to Python.

Thanks,
        Ralf


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com





More information about the Cplusplus-sig mailing list