Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79451 - in trunk: boost/filesystem libs/filesystem/doc libs/filesystem/doc/src libs/filesystem/test
From: bdawes_at_[hidden]
Date: 2012-07-12 09:53:18


Author: bemandawes
Date: 2012-07-12 09:53:17 EDT (Thu, 12 Jul 2012)
New Revision: 79451
URL: http://svn.boost.org/trac/boost/changeset/79451

Log:
Add BOOST_FOREACH support. Correct C++11 range-based for statement enabler signatures. Improve test coverage. Clears feature requests #5896 and #6521.
Added:
   trunk/libs/filesystem/doc/src/hoist.bat (contents, props changed)
Text files modified:
   trunk/boost/filesystem/operations.hpp | 67 +++++++++++++++++++++++++++++++++++----
   trunk/libs/filesystem/doc/reference.html | 49 +++++++++++++++++++---------
   trunk/libs/filesystem/doc/release_history.html | 12 +++++-
   trunk/libs/filesystem/doc/src/build.bat | 3 +
   trunk/libs/filesystem/doc/src/source.html | 49 +++++++++++++++++++---------
   trunk/libs/filesystem/test/Jamfile.v2 | 2
   trunk/libs/filesystem/test/operations_unit_test.cpp | 31 +++++++++++++++--
   7 files changed, 164 insertions(+), 49 deletions(-)

Modified: trunk/boost/filesystem/operations.hpp
==============================================================================
--- trunk/boost/filesystem/operations.hpp (original)
+++ trunk/boost/filesystem/operations.hpp 2012-07-12 09:53:17 EDT (Thu, 12 Jul 2012)
@@ -33,8 +33,9 @@
 #include <boost/type_traits/is_same.hpp>
 #include <boost/iterator.hpp>
 #include <boost/cstdint.hpp>
+#include <boost/range/mutable_iterator.hpp>
+#include <boost/range/const_iterator.hpp>
 #include <boost/assert.hpp>
-
 #include <string>
 #include <utility> // for pair
 #include <ctime>
@@ -721,14 +722,37 @@
       { return m_imp == rhs.m_imp; }
   };
 
- // enable range-base for statement use
+ // enable C++11 range-base for statement use ---------------------------------------//
 
+ // begin() and end() are only used by a range-based for statement in the context of
+ // auto - thus the top-level const is stripped - so returning const is harmless and
+ // emphasizes begin() is just a pass through.
   inline
- directory_iterator& begin(directory_iterator& iter) {return iter;}
-
+ const directory_iterator& begin(const directory_iterator& iter) {return iter;}
   inline
   directory_iterator end(const directory_iterator&) {return directory_iterator();}
 
+ // enable BOOST_FOREACH ------------------------------------------------------------//
+
+ inline
+ directory_iterator& range_begin(directory_iterator& iter) {return iter;}
+ inline
+ directory_iterator range_begin(const directory_iterator& iter) {return iter;}
+ inline
+ directory_iterator range_end(const directory_iterator&) {return directory_iterator();}
+ } // namespace filesystem
+
+ // namespace boost template specializations
+ template<>
+ struct range_mutable_iterator<boost::filesystem::directory_iterator>
+ { typedef boost::filesystem::directory_iterator type; };
+ template<>
+ struct range_const_iterator <boost::filesystem::directory_iterator>
+ { typedef boost::filesystem::directory_iterator type; };
+
+namespace filesystem
+{
+
 //--------------------------------------------------------------------------------------//
 // //
 // recursive_directory_iterator helpers //
@@ -975,14 +999,41 @@
 
   };
 
- // enable range-base for statement use
+ // enable C++11 range-base for statement use ---------------------------------------//
 
+ // begin() and end() are only used by a range-based for statement in the context of
+ // auto - thus the top-level const is stripped - so returning const is harmless and
+ // emphasizes begin() is just a pass through.
   inline
- recursive_directory_iterator& begin(recursive_directory_iterator& iter) {return iter;}
-
+ const recursive_directory_iterator& begin(const recursive_directory_iterator& iter)
+ {return iter;}
   inline
   recursive_directory_iterator end(const recursive_directory_iterator&)
- {return recursive_directory_iterator();}
+ {return recursive_directory_iterator();}
+
+ // enable BOOST_FOREACH ------------------------------------------------------------//
+
+ inline
+ recursive_directory_iterator& range_begin(recursive_directory_iterator& iter)
+ {return iter;}
+ inline
+ recursive_directory_iterator range_begin(const recursive_directory_iterator& iter)
+ {return iter;}
+ inline
+ recursive_directory_iterator range_end(const recursive_directory_iterator&)
+ {return recursive_directory_iterator();}
+ } // namespace filesystem
+
+ // namespace boost template specializations
+ template<>
+ struct range_mutable_iterator<boost::filesystem::recursive_directory_iterator>
+ { typedef boost::filesystem::recursive_directory_iterator type; };
+ template<>
+ struct range_const_iterator <boost::filesystem::recursive_directory_iterator>
+ { typedef boost::filesystem::recursive_directory_iterator type; };
+
+namespace filesystem
+{
 
 # if !defined(BOOST_FILESYSTEM_NO_DEPRECATED)
   typedef recursive_directory_iterator wrecursive_directory_iterator;

Modified: trunk/libs/filesystem/doc/reference.html
==============================================================================
--- trunk/libs/filesystem/doc/reference.html (original)
+++ trunk/libs/filesystem/doc/reference.html 2012-07-12 09:53:17 EDT (Thu, 12 Jul 2012)
@@ -134,7 +134,12 @@
 <a href="#Class-directory_iterator">Class <code>directory_iterator</code></a><br>
 &nbsp;&nbsp;&nbsp; <a href="#directory_iterator-members"><code>directory_iterator</code>
     members</a><br>
+&nbsp; <code>&nbsp;directory_iterator</code><a href="#directory_iterator-members">
+ non-member functions</a><br>
 <a href="#Class-recursive_directory_iterator">Class <code>recursive_directory_iterator</code></a><br>
+ <code>&nbsp; <a href="#recursive_directory_iterator-non-member-functions">
+ recursive_directory_iterator</a></code><br>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  non-member functions<br>
     <a href="#Operational-functions">
     Operational functions</a><br>
     <code>&nbsp;&nbsp;&nbsp;&nbsp absolute<br>
@@ -152,11 +157,11 @@
 &nbsp;&nbsp;&nbsp;&nbsp equivalent<br>
 &nbsp;&nbsp;&nbsp;&nbsp file_size<br>
 &nbsp;&nbsp;&nbsp;&nbsp; hard_link_count<br>
- &nbsp;&nbsp;&nbsp;&nbsp; initial_path<br>
-&nbsp;&nbsp;&nbsp;&nbsp is_directory<br>
-&nbsp;&nbsp;&nbsp;&nbsp is_empty</code></td>
+ &nbsp;&nbsp;&nbsp;&nbsp; initial_path</code></td>
     <td width="34%" valign="top">
- <code>&nbsp;&nbsp;&nbsp;&nbsp is_other<br>
+ <code>&nbsp;&nbsp;&nbsp;&nbsp; is_directory<br>
+&nbsp;&nbsp;&nbsp;&nbsp is_empty<br>
+&nbsp;&nbsp;&nbsp;&nbsp is_other<br>
 &nbsp;&nbsp;&nbsp;&nbsp is_regular_file<br>
 &nbsp;&nbsp;&nbsp;&nbsp is_symlink<br>
 &nbsp;&nbsp;&nbsp;&nbsp last_write_time<br>
@@ -402,14 +407,26 @@
 
     class directory_iterator;
 
- inline directory_iterator&amp; begin(directory_iterator&amp; iter);
- inline directory_iterator end(const directory_iterator&amp;);
+ // enable c++11 range-based for statements
+ const directory_iterator&amp; begin(const directory_iterator&amp; iter);
+ directory_iterator end(const directory_iterator&amp;);
+
+ // enable BOOST_FOREACH
+ directory_iterator&amp; range_begin(directory_iterator&amp; iter);
+ directory_iterator range_begin(const directory_iterator&amp; iter);
+ directory_iterator range_end(const directory_iterator&amp;);
 
     class recursive_directory_iterator;
 
- inline recursive_directory_iterator&amp; begin(recursive_directory_iterator&amp; iter);
- inline recursive_directory_iterator end(const recursive_directory_iterator&amp;);
-
+ // enable c++11 range-based for statements
+ const recursive_directory_iterator&amp; begin(const recursive_directory_iterator&amp; iter);
+ recursive_directory_iterator end(const recursive_directory_iterator&amp;);
+
+&nbsp;&nbsp;&nbsp; // enable BOOST_FOREACH
+&nbsp;&nbsp;&nbsp;&nbsp;recursive_directory_iterator&amp; range_begin(recursive_directory_iterator&amp; iter);
+&nbsp;&nbsp;&nbsp;&nbsp;recursive_directory_iterator range_begin(const recursive_directory_iterator&amp; iter);
+&nbsp;&nbsp;&nbsp;&nbsp;recursive_directory_iterator range_end(const recursive_directory_iterator&amp;);
+&nbsp;
     enum <a name="file_type" href="#Enum-file_type">file_type</a>
     {
       status_error, file_not_found, regular_file, directory_file,
@@ -2045,12 +2062,12 @@
 <p><i>Throws:</i> As specified in Error reporting.</p>
 
 </blockquote>
-<h3><code>directory_iterator</code> non-member functions</h3>
-<pre>inline directory_iterator&amp; begin(directory_iterator&amp; iter);</pre>
+<h3><a name="directory_iterator-non-member-functions"><code>directory_iterator</code> non-member functions</a></h3>
+<pre>const directory_iterator&amp; begin(const directory_iterator&amp; iter);</pre>
 <blockquote>
   <p><i>Returns: </i><code>iter</code>.</p>
 </blockquote>
-<pre>inline directory_iterator end(const directory_iterator&amp;);</pre>
+<pre>directory_iterator end(const directory_iterator&amp;);</pre>
 <blockquote>
   <p><i>Returns: </i><code>directory_iterator()</code>.</p>
 </blockquote>
@@ -2191,14 +2208,14 @@
   <p>[<i>Note:</i> <code>no_push()</code> is used to prevent
   unwanted recursion into a directory. <i>--end note</i>]</p>
 </blockquote>
-<h3><code>recursive_directory_iterator</code> non-member functions</h3>
-<pre>inline recursive_directory_iterator&amp; begin(recursive_directory_iterator&amp; iter);</pre>
+<h3><a name="recursive_directory_iterator-non-member-functions"><code>recursive_directory_iterator</code> non-member functions</a></h3>
+<pre>const recursive_directory_iterator&amp; begin(const recursive_directory_iterator&amp; iter);</pre>
 <blockquote>
   <p><i>Returns: </i><code>iter</code>.</p>
 </blockquote>
-<pre>inline recursive_directory_iterator end(const recursive_directory_iterator&amp;);</pre>
+<pre>recursive_directory_iterator end(const recursive_directory_iterator&amp;);</pre>
 <blockquote>
- <p><i>Returns: </i>recursive_<code>directory_iterator()</code>.</p>
+ <p><i>Returns: </i><code>recursive_directory_iterator()</code>.</p>
 </blockquote>
 <h3><a name="Operational-functions">Operational functions</a></h3>
 <p>Operational functions query or modify files, including directories, in external

Modified: trunk/libs/filesystem/doc/release_history.html
==============================================================================
--- trunk/libs/filesystem/doc/release_history.html (original)
+++ trunk/libs/filesystem/doc/release_history.html 2012-07-12 09:53:17 EDT (Thu, 12 Jul 2012)
@@ -39,8 +39,14 @@
 <h2>1.51.0</h2>
 <ul>
   <li>Add begin() and end() non-member functions for directory_iterator and
- recursive_directory_iterator so that C++11 range-based for statements now
- work.</li>
+ recursive_directory_iterator so that C++11 range-based for statements work.
+ Suggested by feature requests
+ #5896 and
+ #6521, using the
+ #5896 approach.</li>
+ <li>Add range_begin() and range_end() non-member functions for directory_iterator and
+ recursive_directory_iterator so that
+ BOOST_FOREACH works.</li>
 </ul>
 
 <h2>1.50.0</h2>
@@ -170,7 +176,7 @@
 </ul>
 <hr>
 <p>Revised
-<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->10 July, 2012<!--webbot bot="Timestamp" endspan i-checksum="21085" --></p>
+<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->12 July, 2012<!--webbot bot="Timestamp" endspan i-checksum="21089" --></p>
 <p>© Copyright Beman Dawes, 2011</p>
 <p> Use, modification, and distribution are subject to the Boost Software
 License, Version 1.0. See <a href="http://www.boost.org/LICENSE_1_0.txt">

Modified: trunk/libs/filesystem/doc/src/build.bat
==============================================================================
--- trunk/libs/filesystem/doc/src/build.bat (original)
+++ trunk/libs/filesystem/doc/src/build.bat 2012-07-12 09:53:17 EDT (Thu, 12 Jul 2012)
@@ -1,5 +1,8 @@
 @echo off
+rem Copyright Beman Dawes 2012
+rem Distributed under the Boost Software License, Version 1.0.
 del tr2.html 2>nul
 mmp TARGET=TR2 source.html tr2.html
 del reference.html 2>nul
 mmp TARGET=BOOST source.html reference.html
+echo run "hoist" to hoist reference.html to doc directory

Added: trunk/libs/filesystem/doc/src/hoist.bat
==============================================================================
--- (empty file)
+++ trunk/libs/filesystem/doc/src/hoist.bat 2012-07-12 09:53:17 EDT (Thu, 12 Jul 2012)
@@ -0,0 +1,5 @@
+@echo off
+rem Copyright Beman Dawes 2012
+rem Distributed under the Boost Software License, Version 1.0.
+copy /y reference.html ..
+echo reference.html copied to ..

Modified: trunk/libs/filesystem/doc/src/source.html
==============================================================================
--- trunk/libs/filesystem/doc/src/source.html (original)
+++ trunk/libs/filesystem/doc/src/source.html 2012-07-12 09:53:17 EDT (Thu, 12 Jul 2012)
@@ -103,7 +103,12 @@
 <a href="#Class-directory_iterator">Class <code>directory_iterator</code></a><br>
 &nbsp;&nbsp;&nbsp; <a href="#directory_iterator-members"><code>directory_iterator</code>
     members</a><br>
+&nbsp; <code>&nbsp;directory_iterator</code><a href="#directory_iterator-members">
+ non-member functions</a><br>
 <a href="#Class-recursive_directory_iterator">Class <code>recursive_directory_iterator</code></a><br>
+ <code>&nbsp; <a href="#recursive_directory_iterator-non-member-functions">
+ recursive_directory_iterator</a></code><br>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  non-member functions<br>
     <a href="#Operational-functions">
     Operational functions</a><br>
     <code>&nbsp;&nbsp;&nbsp;&nbsp absolute<br>
@@ -121,11 +126,11 @@
 &nbsp;&nbsp;&nbsp;&nbsp equivalent<br>
 &nbsp;&nbsp;&nbsp;&nbsp file_size<br>
 &nbsp;&nbsp;&nbsp;&nbsp; hard_link_count<br>
- &nbsp;&nbsp;&nbsp;&nbsp; initial_path<br>
-&nbsp;&nbsp;&nbsp;&nbsp is_directory<br>
-&nbsp;&nbsp;&nbsp;&nbsp is_empty</code></td>
+ &nbsp;&nbsp;&nbsp;&nbsp; initial_path</code></td>
     <td width="34%" valign="top">
- <code>&nbsp;&nbsp;&nbsp;&nbsp is_other<br>
+ <code>&nbsp;&nbsp;&nbsp;&nbsp; is_directory<br>
+&nbsp;&nbsp;&nbsp;&nbsp is_empty<br>
+&nbsp;&nbsp;&nbsp;&nbsp is_other<br>
 &nbsp;&nbsp;&nbsp;&nbsp is_regular_file<br>
 &nbsp;&nbsp;&nbsp;&nbsp is_symlink<br>
 &nbsp;&nbsp;&nbsp;&nbsp last_write_time<br>
@@ -364,14 +369,26 @@
 
     class directory_iterator;
 
- inline directory_iterator&amp; begin(directory_iterator&amp; iter);
- inline directory_iterator end(const directory_iterator&amp;);
+ // enable c++11 range-based for statements
+ const directory_iterator&amp; begin(const directory_iterator&amp; iter);
+ directory_iterator end(const directory_iterator&amp;);
+
+ // enable BOOST_FOREACH
+ directory_iterator&amp; range_begin(directory_iterator&amp; iter);
+ directory_iterator range_begin(const directory_iterator&amp; iter);
+ directory_iterator range_end(const directory_iterator&amp;);
 
     class recursive_directory_iterator;
 
- inline recursive_directory_iterator&amp; begin(recursive_directory_iterator&amp; iter);
- inline recursive_directory_iterator end(const recursive_directory_iterator&amp;);
-
+ // enable c++11 range-based for statements
+ const recursive_directory_iterator&amp; begin(const recursive_directory_iterator&amp; iter);
+ recursive_directory_iterator end(const recursive_directory_iterator&amp;);
+
+&nbsp;&nbsp;&nbsp; // enable BOOST_FOREACH
+&nbsp;&nbsp;&nbsp;&nbsp;recursive_directory_iterator&amp; range_begin(recursive_directory_iterator&amp; iter);
+&nbsp;&nbsp;&nbsp;&nbsp;recursive_directory_iterator range_begin(const recursive_directory_iterator&amp; iter);
+&nbsp;&nbsp;&nbsp;&nbsp;recursive_directory_iterator range_end(const recursive_directory_iterator&amp;);
+&nbsp;
     enum <a name="file_type" href="#Enum-file_type">file_type</a>
     {
       status_error, file_not_found, regular_file, directory_file,
@@ -1989,12 +2006,12 @@
 <p><i>Throws:</i> As specified in Error reporting.</p>
 
 </blockquote>
-<h3><code>directory_iterator</code> non-member functions</h3>
-<pre>inline directory_iterator&amp; begin(directory_iterator&amp; iter);</pre>
+<h3><a name="directory_iterator-non-member-functions"><code>directory_iterator</code> non-member functions</a></h3>
+<pre>const directory_iterator&amp; begin(const directory_iterator&amp; iter);</pre>
 <blockquote>
   <p><i>Returns: </i><code>iter</code>.</p>
 </blockquote>
-<pre>inline directory_iterator end(const directory_iterator&amp;);</pre>
+<pre>directory_iterator end(const directory_iterator&amp;);</pre>
 <blockquote>
   <p><i>Returns: </i><code>directory_iterator()</code>.</p>
 </blockquote>
@@ -2131,14 +2148,14 @@
   <p>[<i>Note:</i> <code>no_push()</code> is used to prevent
   unwanted recursion into a directory. <i>--end note</i>]</p>
 </blockquote>
-<h3><code>recursive_directory_iterator</code> non-member functions</h3>
-<pre>inline recursive_directory_iterator&amp; begin(recursive_directory_iterator&amp; iter);</pre>
+<h3><a name="recursive_directory_iterator-non-member-functions"><code>recursive_directory_iterator</code> non-member functions</a></h3>
+<pre>const recursive_directory_iterator&amp; begin(const recursive_directory_iterator&amp; iter);</pre>
 <blockquote>
   <p><i>Returns: </i><code>iter</code>.</p>
 </blockquote>
-<pre>inline recursive_directory_iterator end(const recursive_directory_iterator&amp;);</pre>
+<pre>recursive_directory_iterator end(const recursive_directory_iterator&amp;);</pre>
 <blockquote>
- <p><i>Returns: </i>recursive_<code>directory_iterator()</code>.</p>
+ <p><i>Returns: </i><code>recursive_directory_iterator()</code>.</p>
 </blockquote>
 <h3><a name="Operational-functions">Operational functions</a></h3>
 <p>Operational functions query or modify files, including directories, in external

Modified: trunk/libs/filesystem/test/Jamfile.v2
==============================================================================
--- trunk/libs/filesystem/test/Jamfile.v2 (original)
+++ trunk/libs/filesystem/test/Jamfile.v2 2012-07-12 09:53:17 EDT (Thu, 12 Jul 2012)
@@ -24,7 +24,7 @@
        [ run locale_info.cpp : : : <test-info>always_show_run_output ]
        [ run operations_test.cpp : : : <link>shared <test-info>always_show_run_output ]
        [ run operations_test.cpp : : : <link>static : operations_test_static ]
- [ run operations_unit_test.cpp : : : <link>shared ]
+ [ run operations_unit_test.cpp : : : <link>shared <test-info>always_show_run_output ]
        [ run path_test.cpp : : : <link>shared ]
        [ run path_test.cpp : : : <link>static : path_test_static ]
        [ run path_unit_test.cpp : : : <link>shared ]

Modified: trunk/libs/filesystem/test/operations_unit_test.cpp
==============================================================================
--- trunk/libs/filesystem/test/operations_unit_test.cpp (original)
+++ trunk/libs/filesystem/test/operations_unit_test.cpp 2012-07-12 09:53:17 EDT (Thu, 12 Jul 2012)
@@ -155,14 +155,22 @@
 #ifndef BOOST_NO_CXX11_RANGE_BASED_FOR
     for (directory_entry& x : directory_iterator("."))
     {
+ CHECK(!x.path().empty());
        //cout << " " << x.path() << "\n";
     }
+ const directory_iterator dir_itr(".");
+ for (directory_entry& x : dir_itr)
+ {
+ CHECK(!x.path().empty());
+ //cout << " " << x.path() << "\n";
+ }
 #endif
 
- //BOOST_FOREACH(directory_entry& x, directory_iterator("."))
- //{
- // cout << " " << x.path() << "\n";
- //}
+ BOOST_FOREACH(directory_entry& x, directory_iterator("."))
+ {
+ CHECK(!x.path().empty());
+ //cout << " " << x.path() << "\n";
+ }
 
     cout << "directory_iterator_test complete" << endl;
   }
@@ -208,10 +216,23 @@
 #ifndef BOOST_NO_CXX11_RANGE_BASED_FOR
     for (directory_entry& x : recursive_directory_iterator(".."))
     {
- cout << " " << x.path() << "\n";
+ CHECK(!x.path().empty());
+ //cout << " " << x.path() << "\n";
+ }
+ const recursive_directory_iterator dir_itr("..");
+ for (directory_entry& x : dir_itr)
+ {
+ CHECK(!x.path().empty());
+ //cout << " " << x.path() << "\n";
     }
 #endif
 
+ BOOST_FOREACH(directory_entry& x, recursive_directory_iterator(".."))
+ {
+ CHECK(!x.path().empty());
+ //cout << " " << x.path() << "\n";
+ }
+
     cout << "recursive_directory_iterator_test complete" << endl;
   }
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk