[C++-sig] Raw member and constructor functions
David Abrahams
dave at boost-consulting.com
Mon Jun 6 04:30:52 CEST 2005
"Studious Apprentice" <apprentice_99 at hotmail.com> writes:
> Hello !
>
> I would like to use raw member functions and a raw constructor. However I
> can only manage to have raw functions to work.
>
> The following code works :
>
> #include <boost/python.hpp>
> #include <boost/python/raw_function.hpp>
> using namespace boost::python;
>
> tuple raw(tuple args, dict kw)
> {
> return make_tuple(args, kw);
> }
>
> BOOST_PYTHON_MODULE(PythonTest)
> {
> def("raw", raw_function(raw));
> }
>
> However this code does not compile with MSVC7.1 and results in "error C2064:
> term does not evaluate to a function taking 2 arguments" :
>
> #include <boost/python.hpp>
> #include <boost/python/raw_function.hpp>
> using namespace boost::python;
>
> class X {
> public:
> object memberraw(tuple args, dict kw)
> {
> return object();
> }
> };
>
> BOOST_PYTHON_MODULE(PythonTest)
> {
> class_<X>("X")
> .def("memberraw", raw_function(&X::memberraw))
> ;
> }
As http://www.boost.org/libs/python/doc/v2/raw_function.html says,
f(tuple(), dict())
must be well-formed where f is the argument to raw_function. That's
clearly not the case here. This might work:
tuple raw(tuple raw, dict kw)
{
extract<X&>(raw[0])().memberraw(raw.slice(1), kw);
}
BOOST_PYTHON_MODULE(PythonTest)
{
class_<X>("X")
.def("memberraw", raw_function(raw))
;
}
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list