iterator/iota: declare the iterator type first up

This means reduces the chances of mixing up inner/outer types, and
eliminates the use of the iterator typedef within teh container.
This commit is contained in:
Danny Robson 2020-02-25 16:15:45 +11:00
parent 1e3c342482
commit 58b42d5d9b

View File

@ -24,24 +24,6 @@ namespace cruft::iterator {
template <typename ValueT = std::size_t> template <typename ValueT = std::size_t>
class iota { class iota {
public: 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)
{ ; }
class iterator { class iterator {
public: public:
using iterator_category = std::random_access_iterator_tag; using iterator_category = std::random_access_iterator_tag;
@ -51,11 +33,11 @@ namespace cruft::iterator {
using reference = value_type&; using reference = value_type&;
explicit iterator () explicit iterator ()
: m_value {} : m_value {}
{ ; } { ; }
explicit iterator (value_type _value) explicit iterator (value_type _value)
: m_value (_value) : m_value (_value)
{ ; } { ; }
pointer operator-> () const& noexcept { return &m_value; } pointer operator-> () const& noexcept { return &m_value; }
@ -78,6 +60,22 @@ namespace cruft::iterator {
ValueT m_value; ValueT m_value;
}; };
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)
{ ; }
iterator begin (void) const { return iterator {}; } iterator begin (void) const { return iterator {}; }
iterator end (void) const { return iterator {m_total}; } iterator end (void) const { return iterator {m_total}; }