Michele De Stefano's C++ Utilities
|
Adds support for random access operator (i.e. square brackets) to a class that has to be exposed to the Python interpreter. The access is only in read mode. More...
#include <mds_utils/python/container_operators.hpp>
Public Member Functions | |
Obj | py_get_item (const Obj &idx) |
Manages container read access through Python indices and slices. More... | |
Adds support for random access operator (i.e. square brackets) to a class that has to be exposed to the Python interpreter. The access is only in read mode.
Using the Curiously Recurring Template Pattern (CRTP), enables the square brackets operator. The derived class must support these methods:
size_type get_nel()
: this must return the total number of elements into the container.element_type get_el_at(size_type i)
: this must return the element at index i
.Inheriting from this class will add the support_random_access::py_get_item method to the derived class. This method is intended to be exported as the __getitem__
Python method. It will give only read access to the elements.
Definition at line 58 of file container_operators.hpp.
|
inline |
Manages container read access through Python indices and slices.
It is intended to be exposed/used as the __getitem__
method.
idx | A Python object which can be a numeric index or a numeric slice. |
idx
is an index; a list of elements if idx
is a slice.Definition at line 76 of file container_operators.hpp.