iterator: add methods to conform iota to LegacyIterator

This commit is contained in:
Danny Robson 2020-02-24 14:39:08 +11:00
parent 84cbbbd049
commit 3791c8b8ee

View File

@ -24,7 +24,19 @@ namespace cruft::iterator {
template <typename ValueT = std::size_t>
class iota {
public:
class iterator;
using value_type = ValueT;
using reference = ValueT&;
using const_reference = ValueT const&;
using const_iterator = iterator;
using iterator = iterator;
using difference_type = ssize_t;
using size_type = size_t;
iota ()
: m_total {}
{ ; }
iota (value_type _total)
: m_total (_total)
@ -68,7 +80,18 @@ namespace cruft::iterator {
iterator begin (void) const { return iterator {}; }
iterator end (void) const { return iterator {m_total}; }
iterator cbegin (void) const { return begin (); }
iterator cend (void) const { return cend (); }
value_type size (void) const { return m_total; }
value_type max_size (void) const { return std::numeric_limits<size_type>::max (); }
bool empty (void) const noexcept { return m_total == 0; }
void swap (iota &other) { std::swap (m_total, other); }
constexpr bool operator== (iota const &rhs) const noexcept { return m_total == rhs.m_total; }
constexpr bool operator!= (iota const &rhs) const noexcept { return m_total == rhs.m_total; }
private:
value_type m_total;