Skip to content

Commit

Permalink
Reduce code duplication with more template magic
Browse files Browse the repository at this point in the history
  • Loading branch information
MaartenBaert committed Nov 16, 2024
1 parent 1e28675 commit cfe6521
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions include/pybind11/numpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -1428,25 +1428,11 @@ struct npy_format_descriptor<
};

template <typename T>
struct npy_format_descriptor<T, enable_if_t<is_same_ignoring_cvref<T, PyObject *>::value>> {
static constexpr auto name = const_name("object");

static constexpr int value = npy_api::NPY_OBJECT_;

static pybind11::dtype dtype() { return pybind11::dtype(/*typenum*/ value); }
};

template <>
struct npy_format_descriptor<handle, enable_if_t<sizeof(handle) == sizeof(PyObject *)>> {
static constexpr auto name = const_name("object");

static constexpr int value = npy_api::NPY_OBJECT_;

static pybind11::dtype dtype() { return pybind11::dtype(/*typenum*/ value); }
};

template <>
struct npy_format_descriptor<object, enable_if_t<sizeof(object) == sizeof(PyObject *)>> {
struct npy_format_descriptor<
T,
enable_if_t<is_same_ignoring_cvref<T, PyObject *>::value
|| ((std::is_same<T, handle>::value || std::is_same<T, object>::value)
&& sizeof(T) == sizeof(PyObject *))>> {
static constexpr auto name = const_name("object");

static constexpr int value = npy_api::NPY_OBJECT_;
Expand Down

0 comments on commit cfe6521

Please sign in to comment.