| 191 | // read-only bracket operator |
| 192 | template< typename T, typename TELEM, typename TCLASS = py::class_<T>> |
| 193 | void PyDefROBracketOperator( py::module &m, TCLASS &c ) |
| 194 | { |
| 195 | auto Get = [](T& self, int i) { |
| 196 | if (i < 0) i += self.Size(); |
| 197 | if( i<self.Size() && i>=0 ) |
| 198 | return self[i]; |
| 199 | throw py::index_error(); |
| 200 | return TELEM(); |
| 201 | }; |
| 202 | c.def("__getitem__", Get,py::arg("pos"), "Return value at given position"); |
| 203 | c.def("Get", Get, py::arg("pos"), "Return value at given position"); |
| 204 | } |
| 205 | |
| 206 | // read-write bracket operator |
| 207 | template< typename T, typename TELEM, typename TCLASS = py::class_<T>> |