Skip to content
Discussion options

You must be logged in to vote

The copy isn't coming from your design, it's the default policy of nb::cast. Its signature is

template <typename T> object cast(T &&value, rv_policy policy = rv_policy::automatic_reference)

and automatic_reference behaves like automatic except for pointers, where automatic is documented as falling back to "take_ownership when the return value is a pointer, move when it is a rvalue reference, and copy when it is a lvalue reference". You pass an lvalue reference, so you get copy, hence the call to a copy constructor you don't have.

What you want is the Python object that already exists for that instance, and nb::find returns exactly that without creating anything:

.def_prop_ro("view",
     …

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@ChernyshevT
Comment options

Comment options

You must be logged in to vote
1 reply
@ChernyshevT
Comment options

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