summaryrefslogtreecommitdiff
path: root/ext/pybind11/include/pybind11/complex.h
diff options
context:
space:
mode:
Diffstat (limited to 'ext/pybind11/include/pybind11/complex.h')
-rw-r--r--ext/pybind11/include/pybind11/complex.h13
1 files changed, 9 insertions, 4 deletions
diff --git a/ext/pybind11/include/pybind11/complex.h b/ext/pybind11/include/pybind11/complex.h
index f767f354c..945ca0710 100644
--- a/ext/pybind11/include/pybind11/complex.h
+++ b/ext/pybind11/include/pybind11/complex.h
@@ -18,16 +18,21 @@
#endif
NAMESPACE_BEGIN(pybind11)
+NAMESPACE_BEGIN(detail)
-PYBIND11_DECL_FMT(std::complex<float>, "Zf");
-PYBIND11_DECL_FMT(std::complex<double>, "Zd");
+// The format codes are already in the string in common.h, we just need to provide a specialization
+template <typename T> struct is_fmt_numeric<std::complex<T>> {
+ static constexpr bool value = true;
+ static constexpr int index = is_fmt_numeric<T>::index + 3;
+};
-NAMESPACE_BEGIN(detail)
template <typename T> class type_caster<std::complex<T>> {
public:
- bool load(handle src, bool) {
+ bool load(handle src, bool convert) {
if (!src)
return false;
+ if (!convert && !PyComplex_Check(src.ptr()))
+ return false;
Py_complex result = PyComplex_AsCComplex(src.ptr());
if (result.real == -1.0 && PyErr_Occurred()) {
PyErr_Clear();