dxx-rebirth/common/include/highest_valid.h

43 lines
753 B
C++

#pragma once
#include <cstddef>
#include <iterator>
template <typename T, typename I = typename T::index_type>
struct highest_valid_t
{
struct iterator : std::iterator<std::forward_iterator_tag, I>
{
I i;
iterator(I pos) : i(pos)
{
}
iterator &operator++()
{
++ i;
return *this;
}
I operator*() const
{
return i;
}
bool operator!=(const iterator &rhs) const
{
return i != rhs.i;
}
};
T &m_container;
I m_begin;
highest_valid_t(T &t, I start) :
m_container(t), m_begin(start)
{
}
iterator begin() const { return m_begin; }
iterator end() const { return m_container.highest + 1; }
};
template <typename T>
highest_valid_t<T> highest_valid(T &t, typename T::index_type start = 0)
{
return {t, start};
}