diff --git a/include/pybind11/internal/accessor.h b/include/pybind11/internal/accessor.h index 6d100557..9731e4cf 100644 --- a/include/pybind11/internal/accessor.h +++ b/include/pybind11/internal/accessor.h @@ -54,7 +54,7 @@ public: template accessor& operator= (Value&& value) && { - policy::set(m_obj, m_key, std::forward(value)); + policy::set(m_obj, m_key, pybind11::cast(std::forward(value))); return *this; } diff --git a/include/pybind11/internal/builtins.h b/include/pybind11/internal/builtins.h index 084376cb..494869e0 100644 --- a/include/pybind11/internal/builtins.h +++ b/include/pybind11/internal/builtins.h @@ -95,6 +95,10 @@ handle cast(T&& value, return_value_policy policy, handle parent) { if constexpr(std::is_convertible_v) { return std::forward(value); + } else if constexpr(is_unique_ptr_v) { + return impl::type_caster::cast(value.release(), + return_value_policy::take_ownership, + parent); } else { static_assert(!is_multiple_pointer_v, "multiple pointer is not supported."); static_assert(!std::is_void_v>, diff --git a/include/pybind11/internal/object.h b/include/pybind11/internal/object.h index 007ccf9b..4bbabceb 100644 --- a/include/pybind11/internal/object.h +++ b/include/pybind11/internal/object.h @@ -177,7 +177,7 @@ struct type_visitor { } else { // some type, like iterable, iterator, they don't have according type in python // but they have a function to check the type, then just call the function - return T::type_or_check(obj); + return T::type_or_check()(obj); } } else { return vm->isinstance(obj.ptr(), type()); diff --git a/include/pybind11/internal/type_traits.h b/include/pybind11/internal/type_traits.h index d24374bb..946d5714 100644 --- a/include/pybind11/internal/type_traits.h +++ b/include/pybind11/internal/type_traits.h @@ -2,6 +2,7 @@ #include #include #include +#include namespace pybind11 { @@ -195,4 +196,11 @@ constexpr inline overload_cast_t overload_cast; /// - regular: static_cast(&Class::func) /// - sweet: overload_cast(&Class::func, const_) constexpr static auto const_ = std::true_type{}; + +template +constexpr bool is_unique_ptr_v = false; + +template +constexpr bool is_unique_ptr_v> = true; + } // namespace pybind11 diff --git a/include/pybind11/stl.h b/include/pybind11/stl.h index 92c6667f..8cef42fa 100644 --- a/include/pybind11/stl.h +++ b/include/pybind11/stl.h @@ -86,8 +86,14 @@ struct type_caster>> { template static handle cast(U&& src, return_value_policy policy, handle parent) { auto list = pybind11::list(); - for(auto& item: src) { - list.append(pybind11::cast(item, policy, parent)); + if constexpr(std::is_same_v>) { + for(auto item: src) { + list.append(pybind11::cast(bool(item), policy, parent)); + } + } else { + for(auto& item: src) { + list.append(pybind11::cast(item, policy, parent)); + } } return list; }