[C++-sig] Re: boost::optional from python

David Abrahams dave at boost-consulting.com
Fri Sep 10 18:22:26 CEST 2004


"Neal D. Becker" <ndbecker2 at verizon.net> writes:

> I have C++ functions that take boost::optional arguments.  How best to call
> them from python?
>
> Consider:
>
> int F (boost::optional<int>& o);
>
> It would be most natural to be able to (from python)
>
> i = F(None)
> j = F(2)
>
> I'm guessing I could register a converter from T -> boost::optional<T>? 
> Still, how does this handle None?

This is a bit odd.  You want to get a mutable lvalue from Python when
you pass None?  What should happens when F writes into o?  Same goes
for 2, for that matter.  ints are immutable in Python.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com




More information about the Cplusplus-sig mailing list