Uniformly strided section of an array. More...
#include <Access.h>
Public Member Functions | |
Slice (T *src, int32_t count_, int32_t stride_=1, int32_t offset_=0) | |
Slice | operator() (int32_t cnt, int32_t str=1, int32_t off=0) const |
Returns new sub-slice. | |
T & | operator[] (int32_t i) const |
Returns ith count element. | |
template<class U > | |
const Slice & | copy (const Slice< U > &v) const |
Copy elements from another slice. | |
template<class Fil > | |
const Slice & | filter (const Fil &v) const |
Apply filter in-place. | |
template<class R , class X , class A1 > | |
const Slice & | filter (R(*const func)(X, A1), const A1 &a1) |
Apply C-style unary function in-place, x = func(x, a1) | |
template<class R , class X , class A1 , class A2 > | |
const Slice & | filter (R(*const func)(X, A1, A2), const A1 &a1, const A2 &a2) |
Apply C-style binary function in-place, x = func(x, a1, a2) | |
const Slice & | reverse () |
Reverse slice. | |
Slice | reversed () const |
Returns reversed slice. | |
const Slice & | set (const T &v=T()) const |
Set all elements to argument. | |
template<class U > | |
const Slice & | swap (const Slice< U > &v) const |
Swaps elements. | |
T | mean () const |
Returns mean of elements. | |
T | sum () const |
Returns sum of elements in slice. |
Uniformly strided section of an array.
For operations between different slices, the minimum count between the two slices will be used for iteration. All operations requiring elements to be copied perform a shallow copy (i.e. use '=' operator) and therefore are safe to use with objects.
Slice | ( | T * | src, |
int32_t | count_, | ||
int32_t | stride_ = 1 , |
||
int32_t | offset_ = 0 |
||
) |
[in] | src | pointer to array elements |
[in] | count_ | how many elements to iterate over |
[in] | stride_ | stride increment through array |
[in] | offset_ | absolute offset into array, -1 is last, -2 penultimate, etc. |
Copy elements from another slice.
Source elements are statically cast to the type of the destination slice.