From 3791c8b8ee020153c7e1315a71293b92a732c6e5 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 24 Feb 2020 14:39:08 +1100 Subject: [PATCH] iterator: add methods to conform `iota` to LegacyIterator --- iterator/iota.hpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/iterator/iota.hpp b/iterator/iota.hpp index dad86f0c..4ade8e1f 100644 --- a/iterator/iota.hpp +++ b/iterator/iota.hpp @@ -24,7 +24,19 @@ namespace cruft::iterator { template 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::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;