[C++-sig] Wrapping functions with lvalue arguments

Baptiste Lepilleur gaiacrtn at free.fr
Sun Jan 16 09:29:59 CET 2005


I believe boost::python::implicitly_convertible<...>() is what you are
looking for. Check the reference doc, it has a example very similar to you
case.

Baptiste.

----- Original Message ----- 
From: "Wagner Bruna" <wbruna at yahoo.com>
To: <c++-sig at python.org>
Sent: Sunday, January 16, 2005 5:23 AM
Subject: [C++-sig] Wrapping functions with lvalue arguments


> Hello,
>
> I'm trying to wrap some C++ functions that take some
> arguments by non-const reference. I didn't want to
> return a tuple in this particular case (mainly because
> there'll be a lot of variables), so I tried to build a
> "holder" object to store the primitive type and pass
> it as an lvalue. Something like:
>
> void my_function(int & value);
>
> struct IntHolder {
>   int obj;
>   operator int&() {
>     return obj;
>   }
> };
>
> (in theory, the implicit conversion would allow me to
> wrap and use my_function directly)
>
> But I couldn't find a way to wrap the conversion
> operator to int&. I also tried a free function
> returning int&, and a wrapped int member, without
> sucess. What I found really strange was, although I
> could wrap my_function(int&) without problems, I
> couldn't find any way to actually pass an lvalue int
> into it.
>
> [...]
>
> But is there a better (or "less hacking") way to make
> this "holder" object? And are there better
> alternatives to deal with functions that must return
> by reference?
>
> Thanks in advance,
> Wagner
>
> pdf: FWIW, I'm using Boost.Python from release 1.32.0,
> and Visual C++ 6.




More information about the Cplusplus-sig mailing list