fix compile error. (#304)

This commit is contained in:
ykiko 2024-09-04 20:20:34 +08:00 committed by GitHub
parent 981e6e6e88
commit 9694f86348
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 4 deletions

View File

@ -54,7 +54,7 @@ public:
template <typename Value>
accessor& operator= (Value&& value) && {
policy::set(m_obj, m_key, std::forward<Value>(value));
policy::set(m_obj, m_key, pybind11::cast(std::forward<Value>(value)));
return *this;
}

View File

@ -95,6 +95,10 @@ handle cast(T&& value, return_value_policy policy, handle parent) {
if constexpr(std::is_convertible_v<underlying_type, handle>) {
return std::forward<T>(value);
} else if constexpr(is_unique_ptr_v<underlying_type>) {
return impl::type_caster<typename underlying_type::pointer>::cast(value.release(),
return_value_policy::take_ownership,
parent);
} else {
static_assert(!is_multiple_pointer_v<underlying_type>, "multiple pointer is not supported.");
static_assert(!std::is_void_v<std::remove_pointer_t<underlying_type>>,

View File

@ -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<T>());

View File

@ -2,6 +2,7 @@
#include <tuple>
#include <string_view>
#include <type_traits>
#include <memory>
namespace pybind11 {
@ -195,4 +196,11 @@ constexpr inline overload_cast_t<Args...> overload_cast;
/// - regular: static_cast<Return (Class::*)(Arg) const>(&Class::func)
/// - sweet: overload_cast<Arg>(&Class::func, const_)
constexpr static auto const_ = std::true_type{};
template <typename T>
constexpr bool is_unique_ptr_v = false;
template <typename T>
constexpr bool is_unique_ptr_v<std::unique_ptr<T>> = true;
} // namespace pybind11

View File

@ -86,9 +86,15 @@ struct type_caster<T, std::enable_if_t<is_py_list_like_v<T>>> {
template <typename U>
static handle cast(U&& src, return_value_policy policy, handle parent) {
auto list = pybind11::list();
if constexpr(std::is_same_v<T, std::vector<bool>>) {
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;
}
};