Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is nothing like this in the standard. Cycles don't play well with C++ iterators because a sequence representing the entire cycle would have <code>first == last</code> and hence be the empty sequence.</p> <p>Possibly you could introduce some state into the iterator, a Boolean flag to represent "not done yet." The flag participates in comparison. Set it <code>true</code> before iterating and to <code>false</code> upon increment/decrement.</p> <p>But it might just be better to manually write the algorithms you need. Once you've managed to represent the whole cycle, representing an empty sequence might have become impossible.</p> <p><strong>EDIT:</strong> Now I notice that you specified the number of cycles. That makes a big difference.</p> <pre><code>template&lt; class I &gt; class cyclic_iterator /* : public iterator&lt; bidirectional, yadda yadda &gt; */ { I it, beg, end; int cnt; cyclic_iterator( int c, I f, I l ) : it( f ), beg( f ), end( l ), cnt( c ) {} public: cyclic_iterator() : it(), beg(), end(), cnt() {} cyclic_iterator &amp;operator++() { ++ it; if ( it == end ) { ++ cnt; it = beg; } } // etc for --, post-operations friend bool operator== ( cyclic_iterator const &amp;lhs, cyclic_iterator const &amp;rhs ) { return lhs.it == rhs.it &amp;&amp; lhs.cnt == rhs.cnt; } // etc for != friend pair&lt; cyclic_iterator, cyclic_iterator &gt; cycle_range ( int c, I f, I l ) {//factory function, better style outside this scope return make_pair( cyclic_iterator( 0, f, l ), cyclic_iterator( c, f, l ) ); } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload