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:
parent
1e3c342482
commit
58b42d5d9b
@ -24,24 +24,6 @@ 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)
|
||||
{ ; }
|
||||
|
||||
class iterator {
|
||||
public:
|
||||
using iterator_category = std::random_access_iterator_tag;
|
||||
@ -51,11 +33,11 @@ namespace cruft::iterator {
|
||||
using reference = value_type&;
|
||||
|
||||
explicit iterator ()
|
||||
: m_value {}
|
||||
: m_value {}
|
||||
{ ; }
|
||||
|
||||
explicit iterator (value_type _value)
|
||||
: m_value (_value)
|
||||
: m_value (_value)
|
||||
{ ; }
|
||||
|
||||
pointer operator-> () const& noexcept { return &m_value; }
|
||||
@ -78,6 +60,22 @@ namespace cruft::iterator {
|
||||
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 end (void) const { return iterator {m_total}; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user