#include "pybind11.h" #include #include #include #include #include #include #include namespace pybind11 { template struct type_caster> { struct wrapper { std::array container = {}; operator std::array&& () { return std::move(container); } }; wrapper value; bool load(const handle& src, bool convert) { if(!isinstance(src)) { return false; } auto list = src.cast(); if(list.size() != N) { return false; } for(std::size_t i = 0; i < N; ++i) { type_caster caster; if(!caster.load(list[i], convert)) { return false; } value.container[i] = caster.value; } return true; } 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)); } return list; } }; template constexpr bool is_py_list_like_v = false; template constexpr bool is_py_list_like_v> = true; template constexpr bool is_py_list_like_v> = true; template constexpr bool is_py_list_like_v> = true; template struct type_caster>> { struct wrapper { T container; operator T&& () { return std::move(container); } }; wrapper value; bool load(const handle& src, bool convert) { if(!isinstance(src)) { return false; } auto list = src.cast(); for(auto item: list) { type_caster caster; if(!caster.load(item, convert)) { return false; } value.container.push_back(caster.value); } return true; } 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)); } return list; } }; template constexpr bool is_py_map_like_v = false; template constexpr bool is_py_map_like_v> = true; template constexpr bool is_py_map_like_v> = true; template struct type_caster>> { struct wrapper { T container; operator T&& () { return std::move(container); } }; wrapper value; bool load(const handle& src, bool convert) { if(!isinstance(src)) { return false; } auto dict = src.cast(); for(auto item: dict) { type_caster key_caster; if(!key_caster.load(item.first, convert)) { return false; } type_caster value_caster; if(!value_caster.load(item.second, convert)) { return false; } value.container.try_emplace(key_caster.value, value_caster.value); } return true; } template static handle cast(U&& src, return_value_policy policy, handle parent) { auto dict = pybind11::dict(); for(auto& [key, value]: src) { dict[pybind11::cast(key, policy, parent)] = pybind11::cast(value, policy, parent); } return dict; } }; } // namespace pybind11