Skip to content

Commit cfe6521

Browse files
committed
Reduce code duplication with more template magic
1 parent 1e28675 commit cfe6521

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

include/pybind11/numpy.h

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,25 +1428,11 @@ struct npy_format_descriptor<
14281428
};
14291429

14301430
template <typename T>
1431-
struct npy_format_descriptor<T, enable_if_t<is_same_ignoring_cvref<T, PyObject *>::value>> {
1432-
static constexpr auto name = const_name("object");
1433-
1434-
static constexpr int value = npy_api::NPY_OBJECT_;
1435-
1436-
static pybind11::dtype dtype() { return pybind11::dtype(/*typenum*/ value); }
1437-
};
1438-
1439-
template <>
1440-
struct npy_format_descriptor<handle, enable_if_t<sizeof(handle) == sizeof(PyObject *)>> {
1441-
static constexpr auto name = const_name("object");
1442-
1443-
static constexpr int value = npy_api::NPY_OBJECT_;
1444-
1445-
static pybind11::dtype dtype() { return pybind11::dtype(/*typenum*/ value); }
1446-
};
1447-
1448-
template <>
1449-
struct npy_format_descriptor<object, enable_if_t<sizeof(object) == sizeof(PyObject *)>> {
1431+
struct npy_format_descriptor<
1432+
T,
1433+
enable_if_t<is_same_ignoring_cvref<T, PyObject *>::value
1434+
|| ((std::is_same<T, handle>::value || std::is_same<T, object>::value)
1435+
&& sizeof(T) == sizeof(PyObject *))>> {
14501436
static constexpr auto name = const_name("object");
14511437

14521438
static constexpr int value = npy_api::NPY_OBJECT_;

0 commit comments

Comments
 (0)