Library of Assembled Shared Sources
 
Loading...
Searching...
No Matches
lass::python::Slice Struct Reference

Helper type to get or return Python slice objects. More...

#include <subscript.h>

Public Member Functions

Py_ssize_t adjustIndices (Py_ssize_t sequenceLength)
 Adjust start and stop for actual sequence length, returning slice length.
 

Public Attributes

Py_ssize_t start
 start index of slice. Always the index of a valid iterator after calling adjustIndices()
 
Py_ssize_t stop
 stop index of slice. Can be -1 if step < 0! It's not guaranteed that stop == start + sliceLength * step
 
Py_ssize_t step
 step size of slice.
 

Detailed Description

Helper type to get or return Python slice objects.

This helper can be used as C++ parameter type to overload __getitem__ to support Python slice objects.

See Subscript Protocol for more details and examples.

Note
Before you can use the start/stop indices, you must adjust them for the actual sequence length by calling adjustIndices(). This will also return the actual number of elements in the slice.
See also
Subscript Protocol
adjustIndex
adjustIndexEx
PyExportTraits<Slice>

Definition at line 192 of file subscript.h.

Member Function Documentation

◆ adjustIndices()

Py_ssize_t lass::python::Slice::adjustIndices ( Py_ssize_t sequenceLength)

Adjust start and stop for actual sequence length, returning slice length.

Parameters
sequenceLengthactual length of the sequence to be sliced
Returns
sliceLength, actual number of elements in slice
Note
Unlike PySlice_AdjustIndices, start will never be -1 (that case, which only happens when sliceLength == 0 and step < 0, is normalized to start = stop = 0).
Precondition
sequenceLength >= 0
step != 0
Postcondition
start >= 0 && start <= sequenceLength
stop >= -1 && stop <= sequenceLength

Definition at line 50 of file subscript.cpp.

References start, step, and stop.


The documentation for this struct was generated from the following files: