mirror of
https://github.com/ModOrganizer2/modorganizer-plugin_python.git
synced 2026-07-27 14:03:33 -07:00
Slight modification for tuple and variant registers using C++17 fold expressions.
This commit is contained in:
@@ -20,14 +20,11 @@ namespace boost {
|
||||
|
||||
private:
|
||||
|
||||
template <std::size_t I0, std::size_t... Is>
|
||||
static void convert_impl(const TTuple& c_tuple, list& values, std::index_sequence<I0, Is... >) {
|
||||
values.append(std::get<I0>(c_tuple));
|
||||
convert_impl(c_tuple, values, std::index_sequence<Is... >{});
|
||||
template <std::size_t... Is>
|
||||
static void convert_impl(const TTuple& c_tuple, list& values, std::index_sequence<Is... >) {
|
||||
(values.append(std::get<Is>(c_tuple)), ...);
|
||||
}
|
||||
|
||||
static void convert_impl(const TTuple&, list& values, std::index_sequence<>) {}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -99,4 +96,4 @@ namespace boost {
|
||||
}
|
||||
} //boost::python
|
||||
|
||||
#endif//TUPLES_HPP_16_JAN_2007
|
||||
#endif
|
||||
@@ -30,12 +30,13 @@ namespace boost {
|
||||
struct variant_from_python<VTemplate<Args... >> {
|
||||
|
||||
using variant_type = VTemplate<Args... >;
|
||||
using index_sequence = std::make_index_sequence<std::variant_size_v<variant_type>>;
|
||||
|
||||
static void* convertible(PyObject* py_obj) {
|
||||
|
||||
python::object obj(handle<>(borrowed(py_obj)));
|
||||
|
||||
if (impl<Args... >::convertible(obj)) {
|
||||
if (convertible_impl(obj)) {
|
||||
return py_obj;
|
||||
}
|
||||
else {
|
||||
@@ -56,29 +57,21 @@ namespace boost {
|
||||
|
||||
private:
|
||||
|
||||
static bool convertible_impl(const python::object& obj) {
|
||||
return (... || extract<Args>(obj).check());
|
||||
}
|
||||
|
||||
template <class... >
|
||||
struct impl;
|
||||
|
||||
template <>
|
||||
struct impl<> {
|
||||
static bool convertible(const python::object& obj) { return false; }
|
||||
static void construct(const python::object& obj, variant_type& c_variant) {}
|
||||
};
|
||||
|
||||
template <class UArg, class... UArgs>
|
||||
struct impl<UArg, UArgs... > {
|
||||
|
||||
static bool convertible(const python::object& obj) {
|
||||
|
||||
extract<UArg> type_checker(obj);
|
||||
if (type_checker.check()) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return impl<UArgs... >::convertible(obj);
|
||||
}
|
||||
}
|
||||
|
||||
static void construct(const python::object& obj, variant_type& c_variant) {
|
||||
|
||||
extract<UArg> type_checker(obj);
|
||||
|
||||
Reference in New Issue
Block a user