-
Hi, I've been reading about the limitations of STL vector bindings, and I'd like to implement a solution using nb::intrusive_counter. One issue I'm running into, is that It should be just a matter of adding a const/non-const |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
Ok so for the sake of the discussion, here are two minimal examples using nanobind and pybind11:
I believe nanobind changed its default return policy from reference to copy following this bug report, so I'm not surprised by the difference in behavior. At the end of the day, I'm trying to create bindings for a json-like object that feels Pythonic. Ideally I'd use type-casters (so types behaves more naturally in Python), but being unable to update the underlying data makes it very challenging to use (which is this limitation but when editing fields rather than calling functions). |
Beta Was this translation helpful? Give feedback.
Yep, that is expected. It is what it is -- the limitations of the current approach are clear, but there isn't an obvious alternative.
Just hypothetically suppose, you pursued the "wrapper" route: you would need a type that intercepts every possible attribute/method access, indexing, etc, and which stores a base pointer to the underlying array and the entry. Calling
.update()
would then dynamically resolve the current memory address and apply the update.One reason why I did not pursue this kind of approach is composability: What if the data structure is nested, and we access an element deeper inside? (e.g.
foo.data.element[5].member.update(..)
). To protect from any memory layout changes o…