Boost C++ Libraries: Ticket #6521: Directory listing using C++11 range-based for loops https://svn.boost.org/trac10/ticket/6521 <p> I have written a simple 'container' class for a directory, 'containing' all of its subdirectories: </p> <pre class="wiki">namespace boost{ namespace filesystem{ class directory{ path p_; public: inline directory(path p):p_(p){ return; } directory_iterator begin(){ return directory_iterator(p_); } directory_iterator end(){ return directory_iterator(); } }; } } </pre><p> so that that range-based for loop can be used: </p> <pre class="wiki">for(auto i:directory("/home")){ ... } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6521 Trac 1.4.3 Beman Dawes Thu, 19 Apr 2012 15:17:29 GMT status changed https://svn.boost.org/trac10/ticket/6521#comment:1 https://svn.boost.org/trac10/ticket/6521#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> A message has been posted to the Boost developers mailing list asking for comments on your proposal. </p> <p> Thanks for raising the issue, </p> <p> --Beman </p> Ticket mustrumr97@… Fri, 15 Jun 2012 12:52:51 GMT <link>https://svn.boost.org/trac10/ticket/6521#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6521#comment:2</guid> <description> <p> I have read the mailing list. I think all filtering should be moved to the directory iterators and that the helper functions should only be used for passing parameters to the iterator constructor like this: </p> <pre class="wiki">template&lt;class... argts&gt; boost::iterator_range&lt;directory_iterator&gt; directory_range(argts... args){ return boost::iterator_range&lt;directory_iterator&gt;( directory_iterator(args...), directory_iterator() ); } template&lt;class... argts&gt; boost::iterator_range&lt;recursive_directory_iterator&gt; recursive_directory_range(argts... args){ return boost::iterator_range&lt;recursive_directory_iterator( recursive_directory_iterator(args...), recursive_directory_iterator() ); } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>mlimber</dc:creator> <pubDate>Tue, 13 Jun 2017 14:11:26 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/6521#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6521#comment:3</guid> <description> <p> Note that because <code>directory_iterator</code> supports <code>begin()</code>/<code>end()</code>, one can already use range-for loops like this: </p> <div class="wiki-code"><div class="code"><pre><span class="k">for</span><span class="p">(</span> <span class="k">const</span> <span class="k">auto</span><span class="o">&amp;</span> <span class="nl">dir_ent</span> <span class="p">:</span> <span class="n">directory_iterator</span><span class="p">{</span> <span class="s">&quot;my/path/to/iterate&quot;</span> <span class="p">}</span> <span class="p">)</span> <span class="p">{</span> <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">dir_ent</span><span class="p">.</span><span class="n">path</span><span class="p">()</span> <span class="o">&lt;&lt;</span> <span class="sc">&#39;\n&#39;</span><span class="p">;</span> <span class="p">}</span> </pre></div></div> </description> <category>Ticket</category> </item> </channel> </rss>