Skip to content

Commit 71b46de

Browse files
committed
update C++ headers
1 parent 04e52a6 commit 71b46de

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/mir/ndslice.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,16 @@ struct mir_slice<Iterator, 1, mir_slice_kind::contiguous>
253253
return _iterator[index];
254254
}
255255

256+
auto&& backward(mir_size_t index)
257+
{
258+
return at(size() - 1 - index);
259+
}
260+
261+
auto&& backward(mir_size_t index) const
262+
{
263+
return at(size() - 1 - index);
264+
}
265+
256266
auto&& operator[](mir_size_t index)
257267
{
258268
return at(index);

include/mir/series.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,27 @@ struct mir_series
7171
return {_index[index], _data[index]};
7272
}
7373

74+
Observation backward(mir_size_t index) const noexcept
75+
{
76+
return {_index[size() - 1 - index], _data[size() - 1 - index]};
77+
}
78+
7479
Observation operator[](mir_size_t index) const noexcept
7580
{
7681
return {_index[index], _data[index]};
7782
}
7883

84+
mir_series slice(mir_size_t a, mir_size_t b)
85+
{
86+
if (a > b)
87+
throw std::out_of_range("series::slice: a > b");
88+
if (b > size())
89+
throw std::out_of_range("series::slice: b > size()");
90+
auto newIndex = _index;
91+
newIndex += a;
92+
return { {{b - a}, _data._iterator}, std::move(newIndex) };
93+
}
94+
7995
template <class T>
8096
size_t transition_index_less(const T& val) const
8197
{

0 commit comments

Comments
 (0)