[C++-sig] Re: with_custodian_and_ward clarification

Stefan Seefeld seefeld at sympatico.ca
Wed Feb 11 18:39:15 CET 2004


David Abrahams wrote:
> Stefan Seefeld <stefan.seefeld at orthosoft.ca> writes:
> 
> 
>>hi there,
>>
>>I want to call a function that connects one object ('slave')
>>to another ('master'). Looking through the documentation for
>>the possible call policies, my best guess is to use
>>'with_custodian_and_ward'.
>>
>>void connect(Slave *s, Master *m) { s->connect(m);}
>>
>>...
>>
>>def("connect",
>>     make_function(connect, with_custodian_and_ward<1, 2>()));
>>
>>
>>The docs say the lifetime of '2' is thus tied to the lifetime
>>of '1'. I'm *guessing* it means that '2' will *at least* live
>>as long as '1'. Is that correct ? (The docs could be a bit more
>>explicit about that)
> 
> 
> What docs are you looking at?

http://www.boost.org/libs/python/doc/tutorial/doc/call_policies.html

> http://www.boost.org/libs/python/doc/v2/with_custodian_and_ward.html#introduction
> 
>   This header provides faciliites for establishing a lifetime
>   dependency between two of a function's Python argument or result
>   objects. 
>   The ward object will not be destroyed until after the custodian as
>   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   long as the custodian object supports weak references

Ah, that's quite clear indeed. Thanks !

Stefan





More information about the Cplusplus-sig mailing list