From 1b27b744c151bfa2db60566112b4d8307cb05104 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Mon, 11 Apr 2022 13:53:30 -0400 Subject: [PATCH] chore: Make stl_bind take slice as const_ref (#3852) * Make stl_bind take slice as const_ref * Change eval order if * Silence MSVC warning --- include/pybind11/pybind11.h | 3 ++- include/pybind11/stl_bind.h | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index fa018b50..797c769d 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1817,7 +1817,8 @@ private: if (holder_ptr) { init_holder_from_existing(v_h, holder_ptr, std::is_copy_constructible()); v_h.set_holder_constructed(); - } else if (inst->owned || detail::always_construct_holder::value) { + } else if (PYBIND11_SILENCE_MSVC_C4127(detail::always_construct_holder::value) + || inst->owned) { new (std::addressof(v_h.holder())) holder_type(v_h.value_ptr()); v_h.set_holder_constructed(); } diff --git a/include/pybind11/stl_bind.h b/include/pybind11/stl_bind.h index 3a3e54dd..22a29b47 100644 --- a/include/pybind11/stl_bind.h +++ b/include/pybind11/stl_bind.h @@ -232,7 +232,7 @@ void vector_modifiers( /// Slicing protocol cl.def( "__getitem__", - [](const Vector &v, slice slice) -> Vector * { + [](const Vector &v, const slice &slice) -> Vector * { size_t start = 0, stop = 0, step = 0, slicelength = 0; if (!slice.compute(v.size(), &start, &stop, &step, &slicelength)) { @@ -253,7 +253,7 @@ void vector_modifiers( cl.def( "__setitem__", - [](Vector &v, slice slice, const Vector &value) { + [](Vector &v, const slice &slice, const Vector &value) { size_t start = 0, stop = 0, step = 0, slicelength = 0; if (!slice.compute(v.size(), &start, &stop, &step, &slicelength)) { throw error_already_set(); @@ -281,7 +281,7 @@ void vector_modifiers( cl.def( "__delitem__", - [](Vector &v, slice slice) { + [](Vector &v, const slice &slice) { size_t start = 0, stop = 0, step = 0, slicelength = 0; if (!slice.compute(v.size(), &start, &stop, &step, &slicelength)) {