|
Stratax 0.3.1
|
Version: v0.2.0
Status: Complete
Header: include/stratax/core/Slice.hpp
stratax::core::Slice represents a raw, half-open, strided one-dimensional index range.
It stores signed start, stop, and nonzero step values unchanged. Positive steps select indices while they are less than stop; negative steps select indices while they are greater than stop. Container-specific normalization and clamping happen later in the slicing algorithms.
Slice is responsible for:
[start, stop)) with stridesize()) for positive and negative stridesSlice is not responsible for:
Depends on:
Used by:
| Member | Description |
|---|---|
start_ | Inclusive start index |
stop_ | Exclusive stop index |
step_ | Non-zero stride |
The following conditions are always true:
step().step() is never zero.size() returns 0 when interval direction and bounds select no indices.empty() is equivalent to size() == 0.difference_type represents signed bounds and steps. size_type represents the number of indices selected by the raw range.
Creates a strided half-open range and stores all three arguments unchanged. Negative bounds are not interpreted relative to a container during construction.
Throws
Exceptions::IndexError if step == 0Complexity
start(), stop(), and step() return the stored raw values. size() computes the number of generated indices without iterating or resolving the bounds against a container:
start() >= stop().start() <= stop().The intermediate signed distance and rounding arithmetic must be representable by difference_type.
Complexity
start() / stop() / step() / empty(): O(1)size(): O(1)Two slices are equal when their stored start, stop, and step values all match. Equality compares the raw representation, so two slices that happen to generate the same indices can still compare unequal. In C++20, operator!= is automatically rewritten from operator==.
Complexity
| Operation | Complexity |
|---|---|
| Construction | O(1) |
start() / stop() / step() | O(1) |
size() / empty() | O(1) |
operator== / operator!= | O(1) |
Slice keeps only local interval semantics; extent normalization and clamping happen in indexing-level slicing helpers where the container shape is available.
Using signed fields enables Python-like negative-index flows at higher layers without forcing unsigned conversion too early.
size() arithmetic safe across the full std::ptrdiff_t range.