Skip to content

A wrapped std::shared_ptr. #534

Closed Answered by andre-caldas
andre-caldas asked this question in Q&A
Discussion options

You must be logged in to vote

I think I am supposed to implement a type caster. It seems that the correct way to implement a type caster is by specializing the type_caster template.

Instead of copying the nanobind/stl/shared_ptr.h code, I have derived from type_caster<std::shared_ptr<T>> and then I convert back and forth, from my SharedPtr<T> to std::shared_ptr<T>.

I am not really sure if it is correct to use std::move() where I did.

template <typename T>
struct type_caster<SharedPtr<T>>
    : type_caster<std::shared_ptr<T>>
{
  NB_TYPE_CASTER(SharedPtr<T>, type_caster<std::shared_ptr<T>>::Caster::Name)

  bool from_python(handle src, uint8_t flags, cleanup_list *cleanup) noexcept
  {
    if(!type_caster<std::shared_p…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by andre-caldas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant