#pragma once #include struct SequenceGenerator { struct iterator : std::iterator< std::forward_iterator_tag, int, std::ptrdiff_t, const int *, const int & > { iterator() : _value( 1 ), _sequence( 1 ), _limit( 0 ) {} iterator( int limit ) : _value( 0 ), _sequence( 0 ), _limit( limit ) {} int operator*() const { return _value; } iterator &operator++() { ++_value; ++_limit; if ( _value > _sequence ) { _value = 1; ++_sequence; } return *this; } iterator operator++( int ) { iterator self( *this ); ++( *this ); return self; } bool operator==( const iterator &other ) const { return _limit == other._limit; } bool operator!=( const iterator &other ) const { return !( *this == other ); } private: int _value; int _sequence; int _limit; }; SequenceGenerator( int stop ) : _stop( stop ) {} iterator begin() const { return iterator(); } iterator end() const { return iterator( _stop ); } private: int _stop; };