110 , stride_{rhs.stride_}
111 , count_{rhs.count_} {
114 [[nodiscard]]
int size()
const noexcept {
118 bool empty()
const noexcept {
122 [[nodiscard]]
int stride()
const noexcept {
137 DSPLIB_ASSERT(!is_same_memory(rhs.slice(0, rhs.size())),
"Assigned array to same slice");
138 *
this = rhs.slice(0, rhs.size());
143 std::fill(begin(), end(), value);
147 mut_slice_t& operator=(
const std::initializer_list<T>& rhs) {
148 std::copy(rhs.begin(), rhs.end(), this->begin());
157 auto current = begin();
158 std::advance(current, count_);
167 auto current = begin();
168 std::advance(current, count_);
172 [[deprecated(
"use `copy` instead")]]
base_array<T> operator*()
const noexcept {
181 DSPLIB_ASSERT(size() == rhs.size(),
"Slices size must be equal");
182 const int count = size();
190 const bool is_same = is_same_memory(rhs);
193 if ((stride() == 1) && (rhs.stride() == 1)) {
194 const auto* src = rhs.data_;
197 std::memcpy(dst, src, count *
sizeof(*src));
199 std::memmove(dst, src, count *
sizeof(*src));
210 std::copy(rhs.begin(), rhs.end(), begin());
213 static mut_slice_t make_slice(T* data,
int size,
int i1,
int i2,
int step) {
218 i1 = (i1 < 0) ? (size + i1) : i1;
219 i2 = (i2 < 0) ? (size + i2) : i2;
221 const int d = std::abs(i2 - i1);
222 const int tm = std::abs(step);
223 int count = (d % tm != 0) ? (d / tm + 1) : (d / tm);
225 DSPLIB_ASSERT(step != 0,
"Slice stride cannot be zero");
226 DSPLIB_ASSERT((i1 >= 0) && (i1 < size),
"Left slice index out of range");
227 DSPLIB_ASSERT((i2 >= 0) && (i2 <= size),
"Right slice index out of range");
228 DSPLIB_ASSERT(!((step < 0) && (i1 < i2)),
"First index is smaller for negative step");
229 DSPLIB_ASSERT(!((step > 0) && (i1 > i2)),
"First index is greater for positive step");
230 DSPLIB_ASSERT(count <= size,
"Slice range is greater array size");
236 explicit mut_slice_t(T* data,
int stride,
int count)
240 DSPLIB_ASSERT(count >= 0,
"Count of elements must be positive");
243 bool is_same_memory(
slice_t<T> rhs)
noexcept {
244 if (empty() || rhs.empty()) {
247 auto start1 = rhs.data_;
248 auto end1 = start1 + (rhs.count_ * rhs.stride_);
250 std::swap(start1, end1);
254 auto end2 = start2 + (count_ * stride_);
256 std::swap(start2, end2);
259 return (start1 < end2) && (start2 < end1);