view: allow arbitrary index types for slice and consume
This commit is contained in:
parent
79409eb6fe
commit
f42ae40fcb
13
view.hpp
13
view.hpp
@ -279,11 +279,12 @@ namespace util {
|
|||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
template <typename IndexT>
|
||||||
[[nodiscard]] constexpr auto
|
[[nodiscard]] constexpr auto
|
||||||
split (int pos) const
|
split (IndexT idx) const
|
||||||
{
|
{
|
||||||
auto last = m_begin;
|
auto last = m_begin;
|
||||||
std::advance (last, pos);
|
std::advance (last, idx);
|
||||||
return split (last);
|
return split (last);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,8 +294,9 @@ namespace util {
|
|||||||
// "abc".slice(0, 3) == "abc"
|
// "abc".slice(0, 3) == "abc"
|
||||||
// "abc".slice(0, -1) == "abc"
|
// "abc".slice(0, -1) == "abc"
|
||||||
// "abc".slice(0, -2) == "ab"
|
// "abc".slice(0, -2) == "ab"
|
||||||
[[nodiscard]] constexpr auto
|
template <typename IndexA, typename IndexB>
|
||||||
slice (int a, int b) const
|
[[nodiscard]]constexpr auto
|
||||||
|
slice (IndexA a, IndexB b) const
|
||||||
{
|
{
|
||||||
auto first = m_begin;
|
auto first = m_begin;
|
||||||
auto last = m_begin;
|
auto last = m_begin;
|
||||||
@ -307,8 +309,9 @@ namespace util {
|
|||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
template <typename IndexT>
|
||||||
[[nodiscard]] constexpr auto
|
[[nodiscard]] constexpr auto
|
||||||
consume (int count) const
|
consume (IndexT count) const
|
||||||
{
|
{
|
||||||
auto [a,b] = split (count);
|
auto [a,b] = split (count);
|
||||||
(void)a;
|
(void)a;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user