title: C++ directory item iteration without exceptions
body: <p>In C++17 it became easy to iterate over the items in some directory <code>dir</code>:</p>
  <pre><code>for ( auto&amp; dirEntry: std::filesystem::directory_iterator(dir) )
  {
    if ( !dirEntry.is_regular_file() ) continue;
  ...
  </code></pre>
  <p>Unfortunately this way may throw exceptions, which I want to avoid in my program.</p>
  <p>The iteration without throwing exceptions is also possible:</p>
  <pre><code>std::error_code ec;
  const std::filesystem::directory_iterator dirEnd;
  for ( auto it = std::filesystem::directory_iterator( dir, ec ); !ec &amp;&amp; it != dirEnd; it.increment( ec ) )
  {
    if ( !it-&gt;is_regular_file( ec ) ) continue;
  ...
  </code></pre>
  <p>but it is much wordier in C++. For example, I cannot use range based for. And this larger code size is really significant for me since I have a lot of places with iteration.
  Is there a way to simplify the code iterating directory items and still avoid exceptions?</p>