How to use make_default with keyword expression

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to use make_default with keyword expression

Johan Råde-2
The following code works fine:

     using namespace boost::python;

     class X {};

     X* make_X(int n, float f) { return new X; }

     BOOST_PYTHON_MODULE(Test)
     {
         class_<X>("X")
         .def(
             "__init__",
             make_constructor(&make_X)
             //,(arg("n"), arg("f") = 1.0f)
         );
     }

But if I uncomment the commented line, then the code does not compile.
How do I fix that?

_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Reply | Threaded
Open this post in threaded view
|

Re: How to use make_default with keyword expression

Johan Råde-2
Stupid me, the header should be "How to use make_constructor with
keyword expression".

_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Reply | Threaded
Open this post in threaded view
|

Re: How to use make_default with keyword expression

Johan Råde-2
In reply to this post by Johan Råde-2
On 2/19/2012 9:46 AM, Johan Råde wrote:

> The following code works fine:
>
> using namespace boost::python;
>
> class X {};
>
> X* make_X(int n, float f) { return new X; }
>
> BOOST_PYTHON_MODULE(Test)
> {
> class_<X>("X")
> .def(
> "__init__",
> make_constructor(&make_X)
> //,(arg("n"), arg("f") = 1.0f)
> );
> }
>
> But if I uncomment the commented line, then the code does not compile.
> How do I fix that?

I figured out how to do it:

     using namespace boost::python;

     class X {};

     X* make_X(int n, float f) { return new X; }

     BOOST_PYTHON_MODULE(X)
     {
         class_<X>("X")
         .def(
             "__init__",
             make_constructor(
                 &make_X,
                 default_call_policies(),
                 (arg("n"), arg("f") = 1.0f)
             )
         );
     }

_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Reply | Threaded
Open this post in threaded view
|

Re: How to use make_default with keyword expression

Johan Råde-2
In reply to this post by Johan Råde-2
The documentation of boost::python::make_constructor should be fixed.
It shows the synopsis:

     template <class T, class ArgList, class Generator>
     object make_constructor();

     template <class ArgList, class Generator, class Policies>
     object make_constructor(Policies const& policies);

This is obviously not correct.

_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig
Reply | Threaded
Open this post in threaded view
|

Re: How to use make_default with keyword expression

Ralf Grosse-Kunstleve
Thanks for pointing this out.
Fixed with boost svn trunk revision 77124.
Ralf

On Sun, Feb 19, 2012 at 2:18 AM, Johan Råde <[hidden email]> wrote:
The documentation of boost::python::make_constructor should be fixed.
It shows the synopsis:

   template <class T, class ArgList, class Generator>
   object make_constructor();

   template <class ArgList, class Generator, class Policies>
   object make_constructor(Policies const& policies);

This is obviously not correct.


_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig


_______________________________________________
Cplusplus-sig mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/cplusplus-sig