Skip to content

Commit ef34d29

Browse files
committed
Change item_type_is_equivalent_to<>() from static function to member function, as suggested by @lalaland
1 parent a4d61b4 commit ef34d29

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

include/pybind11/buffer_info.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ struct buffer_info {
160160
// on some platforms, but `int` and `unsigned` will never be equivalent.
161161
// For the ground truth, please inspect `detail::compare_buffer_info<>`.
162162
template <typename T>
163-
static bool item_type_is_equivalent_to(const buffer_info &b) {
164-
return detail::compare_buffer_info<T>::compare(b);
163+
bool item_type_is_equivalent_to() const {
164+
return detail::compare_buffer_info<T>::compare(*this);
165165
}
166166

167167
private:

tests/test_buffers.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ TEST_SUBMODULE(buffers, m) {
2121
// https://google.github.io/styleguide/cppguide.html#Static_and_Global_Variables
2222
static auto *format_table = new std::map<std::string, std::string>;
2323
static auto *equiv_table
24-
= new std::map<std::string, bool (*)(const py::buffer_info &)>;
24+
= new std::map<std::string, bool (py::buffer_info::*)() const>;
2525
if (format_table->empty()) {
2626
#define PYBIND11_ASSIGN_HELPER(...) \
2727
(*format_table)[#__VA_ARGS__] = py::format_descriptor<__VA_ARGS__>::format(); \
28-
(*equiv_table)[#__VA_ARGS__] = py::buffer_info::item_type_is_equivalent_to<__VA_ARGS__>;
28+
(*equiv_table)[#__VA_ARGS__] = &py::buffer_info::item_type_is_equivalent_to<__VA_ARGS__>;
2929
PYBIND11_ASSIGN_HELPER(PyObject *)
3030
PYBIND11_ASSIGN_HELPER(bool)
3131
PYBIND11_ASSIGN_HELPER(std::int8_t)
@@ -44,8 +44,8 @@ TEST_SUBMODULE(buffers, m) {
4444
PYBIND11_ASSIGN_HELPER(std::complex<long double>)
4545
#undef PYBIND11_ASSIGN_HELPER
4646
}
47-
return std::pair<std::string, bool>((*format_table)[cpp_name],
48-
(*equiv_table)[cpp_name](buffer.request()));
47+
return std::pair<std::string, bool>(
48+
(*format_table)[cpp_name], (buffer.request().*((*equiv_table)[cpp_name]))());
4949
});
5050

5151
// test_from_python / test_to_python:

0 commit comments

Comments
 (0)