Skip to content

How to avoid copy of C++ object when using += operator? #441

Answered by metab0t
metab0t asked this question in Q&A
Discussion options

You must be logged in to vote

It seems that this problem is solved by setting correct return value policy.

NB_MODULE(ext, m)
{
  nb::class_<S>(m, "S")
      .def(nb::init<>())
      .def("push_back", &S::push_back)
      .def("clear", &S::clear)
      .def(nb::self += double(), nb::rv_policy::none);
}

I am not sure if it is the idiomatic solution.

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@wjakob
Comment options

@wjakob
Comment options

Answer selected by wjakob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants