From 1cdeb081b2fa59c28cea8c9a4261a46646f5d2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Sun, 9 Apr 2023 20:41:57 +0200 Subject: [PATCH] Fix conversion operators for Qt type casters with latest pybind11. --- .../pybind11_qt/details/pybind11_qt_sip.h | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/pybind11-qt/include/pybind11_qt/details/pybind11_qt_sip.h b/src/pybind11-qt/include/pybind11_qt/details/pybind11_qt_sip.h index a2712ca..be2e882 100644 --- a/src/pybind11-qt/include/pybind11_qt/details/pybind11_qt_sip.h +++ b/src/pybind11-qt/include/pybind11_qt/details/pybind11_qt_sip.h @@ -52,16 +52,28 @@ namespace pybind11::detail::qt { } } - template && !is_pointer, int> = 0> - operator T&() + // pybind11 requires operator T&() & and operator T&&() && but here we want to + // use SFINAE with is_pointer so we need to template the operator + // + // having a template operator U&&() does not work since it will not + // deduce the proper return type for QClass&& or QClass& so we have two separate + // overloads, and in each one, U is actually a reference type (lvalue or rvalue) + // + + template , QClass> && + std::is_lvalue_reference_v && !is_pointer, + int> = 0> + operator U() { return value; } - template && !is_pointer, int> = 0> - operator T&&() && + template , QClass> && + std::is_rvalue_reference_v && !is_pointer, + int> = 0> + operator U() && { return std::move(value); }