20 PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
22 template <typename T> struct
format_descriptor<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
24 static constexpr
const char value[3] = {
'Z', c,
'\0' };
25 static std::string format() {
return std::string(value); }
28 #ifndef PYBIND11_CPP17
31 std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>>::value[3];
35 PYBIND11_NAMESPACE_BEGIN(detail)
37 template <typename T> struct
is_fmt_numeric<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
38 static constexpr
bool value =
true;
44 bool load(
handle src,
bool convert) {
47 if (!convert && !PyComplex_Check(src.
ptr()))
49 Py_complex result = PyComplex_AsCComplex(src.
ptr());
50 if (result.real == -1.0 && PyErr_Occurred()) {
54 value = std::complex<T>((T) result.real, (T) result.imag);
58 static handle cast(
const std::complex<T> &src, return_value_policy ,
handle ) {
59 return PyComplex_FromDoubles((
double) src.real(), (double) src.imag());
62 PYBIND11_TYPE_CASTER(std::complex<T>, _(
"complex"));
64 PYBIND11_NAMESPACE_END(detail)
65 PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
PyObject * ptr() const
Return the underlying PyObject * pointer.