#include <iostream>
#include <type_traits>
#include <utility>
#include <chrono>
#include <set>
#include <map>
#include <vector>
#include <iterator>
#include <utility>




template<typename Type>
struct RangeTypes {
    using  RangeType = std::pair<Type,Type> ;

    class Iterator {
    public:

        Iterator(): m_rangePtr(nullptr), m_currVal(0) {};
        ~Iterator() {};
        Iterator(RangeType & range, bool atEnd=false): m_rangePtr(&range) {
            if(atEnd) {
                m_currVal = m_rangePtr->second;
            } else {
                m_currVal = m_rangePtr->first;
            }
        };

        /** pre-increment ++it
        * Allow to iterate over the end of the sequence
        */
        Iterator & operator++() {
            if(m_rangePtr) {
                ++m_currVal;
            }
            return *this;
        }

        /** post-increment it++ */
        Iterator operator++(int) {
            Iterator it(*this);
            operator++();
            return it;
        }

        bool operator==(const Iterator &rhs) {
            if(m_rangePtr) {
                if(m_rangePtr == rhs.m_rangePtr ) { // if sequences are the same
                    return m_currVal == rhs.m_currVal;
                }
            }
            return false;
        }

        // Return false if the same!
        bool operator!=(const Iterator &rhs) {
            return !(*this==rhs);
        }

        // get current value;
        Type operator*() {
            return m_currVal;
        }

    private:
        RangeType * m_rangePtr;
        Type m_currVal;
    };

    class ContainerType : public RangeType {
    public:

        typedef Iterator iterator;

        ContainerType(RangeType & range ): RangeType(range) {
            // if range wrong, set to no range!
            if(this->first > this->second) {
                this->first = 0;
                this->second = 0;
            }
        }
        iterator begin() {
            return iterator(*this);
        };
        iterator end() {
            return iterator(*this,true);
        };
    };
};


#define INIT_TIMER auto start = std::chrono::high_resolution_clock::now();
#define START_TIMER  start = std::chrono::high_resolution_clock::now();
#define STOP_TIMER(name)  \
    double count = std::chrono::duration<double,std::milli>(std::chrono::high_resolution_clock::now()-start ).count(); \
    std::cout << "RUNTIME of " << name << ": " << count << " ms " << std::endl;


int main(){


    typedef unsigned int Type;
    unsigned int max = 10000;
    std::pair<Type, Type> a(0,max);


    int loops = 100;
    int n = 0;

        RangeTypes<Type>::ContainerType range(a);
        INIT_TIMER
        START_TIMER
        for(int i=1; i<loops; i++) {
            for(auto it=range.begin(); it != range.end(); it++) {
                n +=  *it;
                //std::cout << i << std::endl;
            }
        }
        STOP_TIMER("Range: ")

        std::cout<<"Finished";
	
}