From 3e36c878b4af683bcb7336392e26fbe42b7a07b8 Mon Sep 17 00:00:00 2001 From: snippet Date: Sun, 29 Mar 2020 11:08:49 +1100 Subject: [PATCH] Add Size to lambda capture --- python/vector.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/vector.cpp b/python/vector.cpp index d7214e58..6da3d954 100644 --- a/python/vector.cpp +++ b/python/vector.cpp @@ -17,7 +17,7 @@ auto register_vector_type(py::module &m, const char *name) { array.def(py::init()) .def(py::init()) - .def(py::init([](const std::array &arr) { + .def(py::init([Size](const std::array &arr) { Array a; for (size_t i = 0; i < Size; ++i) a[i] = arr[i]; @@ -37,12 +37,12 @@ auto register_vector_type(py::module &m, const char *name) { .def(py::self -= py::self) .def(py::self *= py::self) .def(py::self /= py::self) - .def("__getitem__", [](const Array &a, size_t index) -> Value { + .def("__getitem__", [Size](const Array &a, size_t index) -> Value { if (index >= Size) throw py::index_error(); return a[index]; }, "index"_a) - .def("__setitem__", [](Array &a, size_t index, Value value) { + .def("__setitem__", [Size](Array &a, size_t index, Value value) { if (index >= Size) throw py::index_error(); a[index] = value; @@ -51,7 +51,7 @@ auto register_vector_type(py::module &m, const char *name) { [](Array &a, const Value &v) { a.x() = v; }) .def_property("y", [](const Array &a) { return a.y(); }, [](Array &a, const Value &v) { a.y() = v; }) - .def_buffer([](Array &m) -> py::buffer_info { + .def_buffer([Size](Array &m) -> py::buffer_info { return py::buffer_info( m.v, // Pointer to buffer sizeof(Value), // Size of one scalar