[C++-sig] Re: Boost.Python v2: Keywords

David Abrahams dave at boost-consulting.com
Mon Feb 3 21:33:46 CET 2003


Nikolay Mladenov <nickm at sitius.com> writes:

> Ok,
>
> I'll tell you what I did so far:
>
> 1. added constructor keyword::keyword(char const *) and changed the
> arguments of args to detail::keyword.

>   My idea here is to allow args to construct keywords holding values
> while preserving the name only option as well.

> 2. typedefed detail::keyword to arg and defined 2 assignment
> operators to keyword so now it looks like that:
>
>   struct keyword
>   {
>       char const* name;
>       handle?> default_value;
>       keyword(char const* n=0):name(n){}
>       template ?class T>
>           keyword ?operator = (T const ?value)
>       {
>           default_value = handle?>(object(value).ptr());
>           return *this;
>       }
>
>       keyword ?operator = (keyword const ?k)
>       {
>           name = k.name;
>           default_value = k.default_value;
>           return *this;
>       }
>   };

[Your mailer does something strange with '<' and '?'...]

Ah, brilliant!  The reason I said it wouldn't happen soon was that I'd
forgotten that all the groundwork was already laid, and how I'd do
it.  I think the above is almost exactly what I'd have done.  I think
I'd probably make the second assignment operator private, and not
define it, though.

> Thus the expression arg("arg_name") = arg_value produces a keyword
> (does it have the necessary life span?)

Yes it does.

> I left the "," overloading for later, I attempted an intervention in
> function::call.  I didn't have much success there, cause I have a
> lot of pieces missing in my understending of the library.

Ah. Obviously the default values need to be stored with the function
somehow.  Is that already provided for?

> Why did you use python api there instead of boost::python wrappers?

To be sure I was getting optimal efficiency, probably.  Also, the
wrappers have some implications for compilation dependencies when I
develop the library, and I don't want recompile all the time.

> I have to figure out the python reference counting. They say it is
> explicit but seems like some of the py api funcs do it for you.
>
> I have to think about some overlapping that occurs now between the
> optional?>, and args.

OK.

> I guess I'll have more questions tomorrow.

You've made a good start!

-- 
                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution





More information about the Cplusplus-sig mailing list