mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-23 04:50:17 +00:00
fix compile error. (#304)
This commit is contained in:
parent
981e6e6e88
commit
9694f86348
@ -54,7 +54,7 @@ public:
|
|||||||
|
|
||||||
template <typename Value>
|
template <typename Value>
|
||||||
accessor& operator= (Value&& 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;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +95,10 @@ handle cast(T&& value, return_value_policy policy, handle parent) {
|
|||||||
|
|
||||||
if constexpr(std::is_convertible_v<underlying_type, handle>) {
|
if constexpr(std::is_convertible_v<underlying_type, handle>) {
|
||||||
return std::forward<T>(value);
|
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 {
|
} else {
|
||||||
static_assert(!is_multiple_pointer_v<underlying_type>, "multiple pointer is not supported.");
|
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>>,
|
static_assert(!std::is_void_v<std::remove_pointer_t<underlying_type>>,
|
||||||
|
@ -177,7 +177,7 @@ struct type_visitor {
|
|||||||
} else {
|
} else {
|
||||||
// some type, like iterable, iterator, they don't have according type in python
|
// 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
|
// 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 {
|
} else {
|
||||||
return vm->isinstance(obj.ptr(), type<T>());
|
return vm->isinstance(obj.ptr(), type<T>());
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace pybind11 {
|
namespace pybind11 {
|
||||||
|
|
||||||
@ -195,4 +196,11 @@ constexpr inline overload_cast_t<Args...> overload_cast;
|
|||||||
/// - regular: static_cast<Return (Class::*)(Arg) const>(&Class::func)
|
/// - regular: static_cast<Return (Class::*)(Arg) const>(&Class::func)
|
||||||
/// - sweet: overload_cast<Arg>(&Class::func, const_)
|
/// - sweet: overload_cast<Arg>(&Class::func, const_)
|
||||||
constexpr static auto const_ = std::true_type{};
|
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
|
} // namespace pybind11
|
||||||
|
@ -86,8 +86,14 @@ struct type_caster<T, std::enable_if_t<is_py_list_like_v<T>>> {
|
|||||||
template <typename U>
|
template <typename U>
|
||||||
static handle cast(U&& src, return_value_policy policy, handle parent) {
|
static handle cast(U&& src, return_value_policy policy, handle parent) {
|
||||||
auto list = pybind11::list();
|
auto list = pybind11::list();
|
||||||
for(auto& item: src) {
|
if constexpr(std::is_same_v<T, std::vector<bool>>) {
|
||||||
list.append(pybind11::cast(item, policy, parent));
|
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;
|
return list;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user