[C++-sig] Default argument and return policies
Joel de Guzman
djowel at gmx.co.uk
Fri Sep 6 04:33:16 CEST 2002
Hi,
No, you're not doing anything wrong.
Whoops.... Call policies for the default function generators
are not implemented yet. Ok, I'll get this working as soon
as possible. Shouldn't be difficult to implement. I'll keep
you posted.
Pardon the confusion.
--Joel
----- Original Message -----
From: "Brian McCandless" <bmccandl at llnl.gov>
>
> I have a function that uses default arguments and also needs a call policy.
> But I was not able to get this to work. I last grabbed the code from
> CVS yesterday.
> Am I doing something wrong or is this an omission in the library?
>
> Here is my example:
>
> #include <boost/python/class.hpp>
> #include <boost/python/return_value_policy.hpp>
> #include <boost/python/manage_new_object.hpp>
> #include <boost/python/module_init.hpp>
> #include <boost/python/def.hpp>
>
> using namespace boost::python;
>
> struct Data {
> Data(double d) : val(d) {}
> double val;
> };
>
> Data* makeData1(double f, double d = 1.0) {
> return new Data(f * d);
> }
>
> Data makeData2(double f, double d = 1.0) {
> return Data(f * d);
> }
>
> BOOST_PYTHON_FUNCTION_GENERATOR(makeData1_stubs, makeData1, 1, 2)
> BOOST_PYTHON_FUNCTION_GENERATOR(makeData2_stubs, makeData2, 1, 2)
>
> BOOST_PYTHON_MODULE_INIT(defaults)
> {
> // works, but you have to pass in two arguments
> def("makeData1", makeData1,
> return_value_policy<manage_new_object>());
>
> // works with default arguments as expected.
> def("makeData2", makeData2, makeData2_stubs());
>
> #if 0
> // Does not compile!
> def("makeData1_with_defaults", makeData1, makeData1_stubs(),
> return_value_policy<manage_new_object>());
> #endif
>
> class_<Data> data("Data", args<double>());
> data.def_readwrite("val", &Data::val);
> }
>
>
> --
> Brian McCandless bmccandl at llnl.gov 925/424-2690
>
>
>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
>
More information about the Cplusplus-sig
mailing list