title: Templated cyclical data structure that works with STL built in functions possible?
body: <p>Is it possible to create a templated data structure, that is analogous to a cyclic group from Abstract Algebra (<a href="https://en.wikipedia.org/wiki/Cyclic_group" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Cyclic_group</a>), and follows the style of other STL data structures?</p>
  
  <p>The underlying storage should behave like <code>std::vector&lt;&gt;</code>, and it should work with a <em>bidirectional iterator</em>. The most important requirement, is that it plays nicely with everything else STL-related, especially in <code>&lt;algorithm&gt;</code>.</p>
  
  <p>The problem that is foresee is the <code>end()</code> iterator. I want <code>++</code> and <code>--</code> to cause the iterator to wrap around, i.e., addition and subtraction <code>mod n</code>, but that would break something like <code>std::for_each</code>.</p>
  
  <p>One possibility, that comes to mind, is to use a <code>bool</code> flag in the iterator, to indicate a complete traversal from <code>0 → n - 1</code>. Any suggestions or comments regarding feasibility would be appreciated.</p>