Adding & using PYBIND11_CLASSH_TYPE_CASTERS define.

This commit is contained in:
Ralf W. Grosse-Kunstleve 2021-01-17 13:32:50 -08:00
parent 1ef19a1e04
commit d7efc9b8b1
2 changed files with 19 additions and 20 deletions

View File

@ -374,5 +374,23 @@ struct classh_type_caster<std::unique_ptr<T const>> : smart_holder_type_caster_l
operator std::unique_ptr<T const>() { return this->loaded_as_unique_ptr(); }
};
#define PYBIND11_CLASSH_TYPE_CASTERS(T) \
namespace pybind11 { \
namespace detail { \
template <> \
class type_caster<T> : public classh_type_caster<T> {}; \
template <> \
class type_caster<std::shared_ptr<T>> : public classh_type_caster<std::shared_ptr<T>> {}; \
template <> \
class type_caster<std::shared_ptr<T const>> \
: public classh_type_caster<std::shared_ptr<T const>> {}; \
template <> \
class type_caster<std::unique_ptr<T>> : public classh_type_caster<std::unique_ptr<T>> {}; \
template <> \
class type_caster<std::unique_ptr<T const>> \
: public classh_type_caster<std::unique_ptr<T const>> {}; \
} \
}
} // namespace detail
} // namespace pybind11

View File

@ -49,26 +49,7 @@ std::unique_ptr<mpty> unique_ptr_roundtrip(std::unique_ptr<mpty> obj) { return o
} // namespace classh_wip
} // namespace pybind11_tests
namespace pybind11 {
namespace detail {
using mpty = pybind11_tests::classh_wip::mpty;
template <>
class type_caster<mpty> : public classh_type_caster<mpty> {};
template <>
class type_caster<std::shared_ptr<mpty>> : public classh_type_caster<std::shared_ptr<mpty>> {};
template <>
class type_caster<std::shared_ptr<mpty const>>
: public classh_type_caster<std::shared_ptr<mpty const>> {};
template <>
class type_caster<std::unique_ptr<mpty>> : public classh_type_caster<std::unique_ptr<mpty>> {};
template <>
class type_caster<std::unique_ptr<mpty const>>
: public classh_type_caster<std::unique_ptr<mpty const>> {};
} // namespace detail
} // namespace pybind11
PYBIND11_CLASSH_TYPE_CASTERS(pybind11_tests::classh_wip::mpty)
namespace pybind11_tests {
namespace classh_wip {