From 58b42d5d9b706b46d6521cc071b6d89366448daa Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 25 Feb 2020 16:15:45 +1100 Subject: [PATCH] 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. --- iterator/iota.hpp | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/iterator/iota.hpp b/iterator/iota.hpp index 4ade8e1f..9da177f0 100644 --- a/iterator/iota.hpp +++ b/iterator/iota.hpp @@ -24,24 +24,6 @@ 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) - { ; } - 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}; }