Skip to content

Commit 2a18170

Browse files
committed
Add value_type member alias to py::array_t (resolve pybind#632)
1 parent 139a082 commit 2a18170

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

include/pybind11/numpy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,8 @@ class array : public buffer {
577577

578578
template <typename T, int ExtraFlags = array::forcecast> class array_t : public array {
579579
public:
580+
using value_type = T;
581+
580582
array_t() : array(0, static_cast<const T *>(nullptr)) {}
581583
array_t(handle h, borrowed_t) : array(h, borrowed) { }
582584
array_t(handle h, stolen_t) : array(h, stolen) { }

tests/test_numpy_array.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
using arr = py::array;
1919
using arr_t = py::array_t<uint16_t, 0>;
20+
static_assert(std::is_same<arr_t::value_type, uint16_t>::value, "");
2021

2122
template<typename... Ix> arr data(const arr& a, Ix... index) {
2223
return arr(a.nbytes() - a.offset_at(index...), (const uint8_t *) a.data(index...));

0 commit comments

Comments
 (0)