Popular C++ recipes tagged "iterable"http://code.activestate.com/recipes/langs/cpp/tags/iterable/2014-10-02T12:13:52-07:00ActiveState Code RecipesNumbers as Ranges - iterable integers (C++) 2014-10-02T12:13:52-07:00elazarhttp://code.activestate.com/recipes/users/4187847/http://code.activestate.com/recipes/578945-numbers-as-ranges-iterable-integers/ <p style="color: grey"> C++ recipe 578945 by <a href="/recipes/users/4187847/">elazar</a> (<a href="/recipes/tags/iterable/">iterable</a>, <a href="/recipes/tags/range/">range</a>). Revision 2. </p> <p>This header file makes simple integers iterable. Note that it works only on C++11 or above.</p> <p>Usage:</p> <pre class="prettyprint"><code>#include "num_range.h" for (int i : 3) cout &lt;&lt; i &lt;&lt; endl; </code></pre> <p>Output: 0 1 2</p> <p>Implementation note: This code is far too generic. We only need <code>DerefableInt</code>. The templates are there for no practical reason.</p> <p>Cons: pollutes namespace std; nonstandard idiom;</p>