view: allow arbitrary index types for slice and consume

This commit is contained in:
Danny Robson 2018-07-24 15:49:38 +10:00
parent 79409eb6fe
commit f42ae40fcb

View File

@ -279,11 +279,12 @@ namespace util {
//---------------------------------------------------------------------
template <typename IndexT>
[[nodiscard]] constexpr auto
split (int pos) const
split (IndexT idx) const
{
auto last = m_begin;
std::advance (last, pos);
std::advance (last, idx);
return split (last);
}
@ -293,8 +294,9 @@ namespace util {
// "abc".slice(0, 3) == "abc"
// "abc".slice(0, -1) == "abc"
// "abc".slice(0, -2) == "ab"
[[nodiscard]] constexpr auto
slice (int a, int b) const
template <typename IndexA, typename IndexB>
[[nodiscard]]constexpr auto
slice (IndexA a, IndexB b) const
{
auto first = m_begin;
auto last = m_begin;
@ -307,8 +309,9 @@ namespace util {
//---------------------------------------------------------------------
template <typename IndexT>
[[nodiscard]] constexpr auto
consume (int count) const
consume (IndexT count) const
{
auto [a,b] = split (count);
(void)a;