view: add more assertions in slicing code
This commit is contained in:
parent
f7c477b163
commit
f1cf6933a9
34
view.hpp
34
view.hpp
@ -83,11 +83,10 @@ namespace cruft {
|
||||
typename CountT,
|
||||
typename = std::enable_if_t<std::is_integral_v<CountT>,void>
|
||||
>
|
||||
view (
|
||||
constexpr view (
|
||||
const BeginT &_begin,
|
||||
CountT _size
|
||||
):
|
||||
view (_begin, _begin + _size)
|
||||
) : view (_begin, _begin + _size)
|
||||
{ ; }
|
||||
|
||||
|
||||
@ -283,6 +282,9 @@ namespace cruft {
|
||||
>
|
||||
split (BeginT pos) const
|
||||
{
|
||||
CHECK_GE (pos, m_begin);
|
||||
CHECK_LE (pos, m_end );
|
||||
|
||||
return {
|
||||
{ m_begin, pos },
|
||||
{ pos, m_end }
|
||||
@ -298,6 +300,8 @@ namespace cruft {
|
||||
[[nodiscard]] constexpr auto
|
||||
split (IndexT idx) const
|
||||
{
|
||||
CHECK_LE (idx, size ());
|
||||
|
||||
auto last = m_begin;
|
||||
std::advance (last, idx);
|
||||
return split (last);
|
||||
@ -310,9 +314,13 @@ namespace cruft {
|
||||
// "abc".slice(0, -1) == "abc"
|
||||
// "abc".slice(0, -2) == "ab"
|
||||
template <typename IndexA, typename IndexB>
|
||||
[[nodiscard]]constexpr auto
|
||||
[[nodiscard]] constexpr
|
||||
auto
|
||||
slice (IndexA a, IndexB b) const
|
||||
{
|
||||
CHECK_LIMIT (cruft::abs (a), IndexA {0}, cruft::cast::lossless<IndexA> (size ()));
|
||||
CHECK_LIMIT (cruft::abs (b), IndexB {0}, cruft::cast::lossless<IndexB> (size ()));
|
||||
|
||||
auto first = m_begin;
|
||||
auto last = m_begin;
|
||||
|
||||
@ -328,8 +336,8 @@ namespace cruft {
|
||||
typename IndexT,
|
||||
typename = std::enable_if_t<std::is_integral_v<IndexT>>
|
||||
>
|
||||
constexpr auto
|
||||
head (IndexT idx)
|
||||
[[nodiscard]] constexpr auto
|
||||
head (IndexT idx) const
|
||||
{
|
||||
return std::get<0> (split (idx));
|
||||
}
|
||||
@ -340,19 +348,7 @@ namespace cruft {
|
||||
typename IndexT,
|
||||
typename = std::enable_if_t<std::is_integral_v<IndexT>>
|
||||
>
|
||||
constexpr auto
|
||||
tail (IndexT idx)
|
||||
{
|
||||
return std::get<1> (split (idx));
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
template <
|
||||
typename IndexT,
|
||||
typename = std::enable_if_t<std::is_integral_v<IndexT>>
|
||||
>
|
||||
constexpr auto
|
||||
[[nodiscard]] constexpr auto
|
||||
tail (IndexT idx) const
|
||||
{
|
||||
return std::get<1> (split (idx));
|
||||
|
Loading…
Reference in New Issue
Block a user