Paul Manta
Paul Manta

Reputation: 31567

Boost.Python: Take possession of argument

If I have a function that takes possession of one of the arguments, are there any call policies that I should use when I expose that function with Boost.Python?

void func(MyClass* obj)
{
    // Code that takes possession of `obj`
}

Upvotes: 4

Views: 239

Answers (1)

Jir
Jir

Reputation: 3125

I think you can use boost::weak_ptr.

using boost::shared_ptr;
using boost::weak_ptr;

func (weak_ptr<MyClass> wp)
{
  shared_ptr<MyClass> sp = wp.lock ();
  if (sp)
    // sp stays alive until it goes out of scope or is reset
}

Basically, this is the example offered in the documentation of boost::weak_ptr. Here's the reference.

Upvotes: 1

Related Questions