title: n={0,1,...,n-1} in C++
body: <p>The formal definition (in set theory) of a natural number n is as follows:</p>
  
  <ul>
  <li>0 is the empty set</li>
  <li>1 = {0}</li>
  <li>n = {0,1,...,n-1}</li>
  </ul>
  
  <p>I think this would make some C++ code much simpler, if I was allowed to do this:</p>
  
  <pre><code>for (int n : 10)
      cout &lt;&lt; n &lt;&lt; endl;
  </code></pre>
  
  <p>and it printed numbers from 0 to 9.</p>
  
  <p>So I tried doing the following, which doesn't compile:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/iterator/counting_iterator.hpp&gt;
  
  
      boost::counting_iterator&lt;int&gt; begin(int t)
      {
          return boost::counting_iterator&lt;int&gt;(0);
      }
  
      boost::counting_iterator&lt;int&gt; end(int t)
      {
          return boost::counting_iterator&lt;int&gt;(t);
      }
  
  
  
  int main() 
  {
      for (int t : 10)
          std::cout &lt;&lt; t &lt;&lt; std::endl;
  
      return 0;
  }
  </code></pre>
  
  <p>Any suggestions on how to achieve this? I get the following error with clang++:</p>
  
  <pre><code>main.cpp:22:20: error: invalid range expression of type 'int'; no viable 'begin' function available
          for (int t : 10)
                  ^ ~~
  </code></pre>
  
  <p>but I think I should be allowed to do this! :)</p>
  
  <p><em>Edit</em>: I know I can "fake" it if I add the word "range" (or some other word) in the for loop, but I'm wondering if it's possible to do it without.</p>