mirror of
https://github.com/boostorg/filesystem.git
synced 2026-01-29 19:42:08 +00:00
path begin, end return const iterator, force cr/nl
[SVN r354]
This commit is contained in:
11
doc/path.htm
11
doc/path.htm
@@ -147,7 +147,10 @@ boost/filesystem/path.hpp</a> <a name="synopsis">synopsis</a></h2>
|
||||
<p><b>Rationale:</b> The return type of several functions (<i>operator<<,
|
||||
leaf, branch</i>) is <i>const path</i> instead of <i>path</i> to disallow
|
||||
expressions like <i>(p1<<p2) = p3</i>. See Scott Myers, <i>Effective C++</i>,
|
||||
Item 21.</p>
|
||||
Item 21. Likewise, <i>begin()</i> and <i>end()</i> return <i>const iterator</i>
|
||||
rather than <i>iterator</i>. This detects non-portable code such as <i>++pth.begin()</i>,
|
||||
which will not work if <i>iterator</i> is a non-class type. See <i>next()</i>
|
||||
and <i>prior()</i> in <a href="../../utility/utility.htm">boost/utility.hpp</a>.</p>
|
||||
<h2><a name="Member">Member</a> functions</h2>
|
||||
<p>For the sake of exposition, class <i>path</i> member functions are described
|
||||
as if the class contains a private member <i>std::vector<std::string> m_name</i>.
|
||||
@@ -262,8 +265,8 @@ the returned string is always unambiguous.</p>
|
||||
<h3><a name="leaf">leaf</a></h3>
|
||||
<blockquote>
|
||||
<pre>const std::string leaf() const;</pre>
|
||||
<p><b>Returns:</b> <code>is_null() ? string() : m_name.back()</code></p>
|
||||
<p><b>Rationale: </b>Return type is <code>string</code> rather than <code>const
|
||||
<p><b>Returns:</b> <code>is_null() ? std::string() : m_name.back()</code></p>
|
||||
<p><b>Rationale: </b>Return type is <code>const string</code> rather than <code>const
|
||||
string &</code> to give implementations freedom to avoid maintaining the
|
||||
leaf as a separate <code>string</code> object.</p>
|
||||
</blockquote>
|
||||
@@ -309,7 +312,7 @@ likely to change.</p>
|
||||
<hr>
|
||||
<p>© Copyright Beman Dawes, 2002</p>
|
||||
<p>Revised
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->01 August, 2002<!--webbot bot="Timestamp" endspan i-checksum="34406" --></p>
|
||||
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%d %B, %Y" startspan -->02 August, 2002<!--webbot bot="Timestamp" endspan i-checksum="34408" --></p>
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
@@ -92,8 +92,8 @@ namespace boost
|
||||
std::ptrdiff_t
|
||||
> iterator;
|
||||
|
||||
iterator begin() const;
|
||||
iterator end() const
|
||||
const iterator begin() const;
|
||||
const iterator end() const
|
||||
{
|
||||
iterator itr;
|
||||
itr.base().path_ptr = this;
|
||||
|
||||
@@ -314,7 +314,7 @@ namespace boost
|
||||
} // while more elements
|
||||
}
|
||||
|
||||
path::iterator path::begin() const
|
||||
const path::iterator path::begin() const
|
||||
{
|
||||
iterator itr;
|
||||
itr.base().path_ptr = this;
|
||||
|
||||
@@ -10,11 +10,14 @@
|
||||
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/filesystem/exception.hpp>
|
||||
#include <boost/utility.hpp>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
using boost::filesystem::path;
|
||||
using boost::next;
|
||||
using boost::prior;
|
||||
|
||||
#define BOOST_INCLUDE_MAIN
|
||||
#include <boost/test/test_tools.hpp>
|
||||
@@ -197,74 +200,74 @@ int test_main( int, char*[] )
|
||||
|
||||
itr_ck = path( "/", fs::system_specific );
|
||||
BOOST_TEST( *itr_ck.begin() == std::string( "/" ) );
|
||||
BOOST_TEST( ++itr_ck.begin() == itr_ck.end() );
|
||||
BOOST_TEST( *--itr_ck.end() == std::string( "/" ) );
|
||||
BOOST_TEST( --itr_ck.end() == itr_ck.begin() );
|
||||
BOOST_TEST( next(itr_ck.begin()) == itr_ck.end() );
|
||||
BOOST_TEST( *next(itr_ck.end()) == std::string( "/" ) );
|
||||
BOOST_TEST( next(itr_ck.end()) == itr_ck.begin() );
|
||||
|
||||
itr_ck = path( "/foo", fs::system_specific );
|
||||
BOOST_TEST( *itr_ck.begin() == std::string( "/" ) );
|
||||
BOOST_TEST( *++itr_ck.begin() == std::string( "foo" ) );
|
||||
BOOST_TEST( ++++itr_ck.begin() == itr_ck.end() );
|
||||
BOOST_TEST( ++itr_ck.begin() == --itr_ck.end() );
|
||||
BOOST_TEST( *--itr_ck.end() == std::string( "foo" ) );
|
||||
BOOST_TEST( *----itr_ck.end() == std::string( "/" ) );
|
||||
BOOST_TEST( ----itr_ck.end() == itr_ck.begin() );
|
||||
BOOST_TEST( *next( itr_ck.begin() ) == std::string( "foo" ) );
|
||||
BOOST_TEST( next(next( itr_ck.begin() )) == itr_ck.end() );
|
||||
BOOST_TEST( next( itr_ck.begin() ) == prior( itr_ck.end() ) );
|
||||
BOOST_TEST( *prior( itr_ck.end() ) == std::string( "foo" ) );
|
||||
BOOST_TEST( *prior(prior( itr_ck.end() )) == std::string( "/" ) );
|
||||
BOOST_TEST( prior(prior( itr_ck.end() )) == itr_ck.begin() );
|
||||
|
||||
itr_ck = "foo";
|
||||
BOOST_TEST( *itr_ck.begin() == std::string( "foo" ) );
|
||||
BOOST_TEST( ++itr_ck.begin() == itr_ck.end() );
|
||||
BOOST_TEST( *--itr_ck.end() == std::string( "foo" ) );
|
||||
BOOST_TEST( --itr_ck.end() == itr_ck.begin() );
|
||||
BOOST_TEST( next( itr_ck.begin() ) == itr_ck.end() );
|
||||
BOOST_TEST( *prior( itr_ck.end() ) == std::string( "foo" ) );
|
||||
BOOST_TEST( prior( itr_ck.end() ) == itr_ck.begin() );
|
||||
|
||||
# ifdef BOOST_WINDOWS
|
||||
|
||||
itr_ck = path( "c:", fs::system_specific );
|
||||
BOOST_TEST( *itr_ck.begin() == std::string( "c:" ) );
|
||||
BOOST_TEST( ++itr_ck.begin() == itr_ck.end() );
|
||||
BOOST_TEST( --itr_ck.end() == itr_ck.begin() );
|
||||
BOOST_TEST( *--itr_ck.end() == std::string( "c:" ) );
|
||||
BOOST_TEST( next( itr_ck.begin() ) == itr_ck.end() );
|
||||
BOOST_TEST( prior( itr_ck.end() ) == itr_ck.begin() );
|
||||
BOOST_TEST( *prior( itr_ck.end() ) == std::string( "c:" ) );
|
||||
|
||||
itr_ck = path( "c:/", fs::system_specific );
|
||||
BOOST_TEST( *itr_ck.begin() == std::string( "c:/" ) );
|
||||
BOOST_TEST( ++itr_ck.begin() == itr_ck.end() );
|
||||
BOOST_TEST( --itr_ck.end() == itr_ck.begin() );
|
||||
BOOST_TEST( *--itr_ck.end() == std::string( "c:/" ) );
|
||||
BOOST_TEST( next( itr_ck.begin() ) == itr_ck.end() );
|
||||
BOOST_TEST( prior( itr_ck.end() ) == itr_ck.begin() );
|
||||
BOOST_TEST( *prior( itr_ck.end() ) == std::string( "c:/" ) );
|
||||
|
||||
itr_ck = path( "c:foo", fs::system_specific );
|
||||
BOOST_TEST( *itr_ck.begin() == std::string( "c:" ) );
|
||||
BOOST_TEST( *++itr_ck.begin() == std::string( "foo" ) );
|
||||
BOOST_TEST( ++++itr_ck.begin() == itr_ck.end() );
|
||||
BOOST_TEST( ----itr_ck.end() == itr_ck.begin() );
|
||||
BOOST_TEST( *--itr_ck.end() == std::string( "foo" ) );
|
||||
BOOST_TEST( *----itr_ck.end() == std::string( "c:" ) );
|
||||
BOOST_TEST( *next( itr_ck.begin() ) == std::string( "foo" ) );
|
||||
BOOST_TEST( next(next( itr_ck.begin() )) == itr_ck.end() );
|
||||
BOOST_TEST( prior(prior( itr_ck.end() )) == itr_ck.begin() );
|
||||
BOOST_TEST( *prior( itr_ck.end() ) == std::string( "foo" ) );
|
||||
BOOST_TEST( *prior(prior( itr_ck.end() )) == std::string( "c:" ) );
|
||||
|
||||
itr_ck = path( "c:/foo", fs::system_specific );
|
||||
BOOST_TEST( *itr_ck.begin() == std::string( "c:/" ) );
|
||||
BOOST_TEST( *++itr_ck.begin() == std::string( "foo" ) );
|
||||
BOOST_TEST( ++++itr_ck.begin() == itr_ck.end() );
|
||||
BOOST_TEST( ----itr_ck.end() == itr_ck.begin() );
|
||||
BOOST_TEST( *--itr_ck.end() == std::string( "foo" ) );
|
||||
BOOST_TEST( *----itr_ck.end() == std::string( "c:/" ) );
|
||||
BOOST_TEST( *next( itr_ck.begin() ) == std::string( "foo" ) );
|
||||
BOOST_TEST( next(next( itr_ck.begin() )) == itr_ck.end() );
|
||||
BOOST_TEST( prior(prior( itr_ck.end() )) == itr_ck.begin() );
|
||||
BOOST_TEST( *prior( itr_ck.end() ) == std::string( "foo" ) );
|
||||
BOOST_TEST( *prior(prior( itr_ck.end() )) == std::string( "c:/" ) );
|
||||
|
||||
itr_ck = path( "//share", fs::system_specific );
|
||||
BOOST_TEST( *itr_ck.begin() == std::string( "//share" ) );
|
||||
BOOST_TEST( ++itr_ck.begin() == itr_ck.end() );
|
||||
BOOST_TEST( --itr_ck.end() == itr_ck.begin() );
|
||||
BOOST_TEST( *--itr_ck.end() == std::string( "//share" ) );
|
||||
BOOST_TEST( next( itr_ck.begin() ) == itr_ck.end() );
|
||||
BOOST_TEST( prior( itr_ck.end() ) == itr_ck.begin() );
|
||||
BOOST_TEST( *prior( itr_ck.end() ) == std::string( "//share" ) );
|
||||
|
||||
itr_ck = path( "//share/foo", fs::system_specific );
|
||||
BOOST_TEST( *itr_ck.begin() == std::string( "//share" ) );
|
||||
BOOST_TEST( *++itr_ck.begin() == std::string( "foo" ) );
|
||||
BOOST_TEST( ++++itr_ck.begin() == itr_ck.end() );
|
||||
BOOST_TEST( ----itr_ck.end() == itr_ck.begin() );
|
||||
BOOST_TEST( *--itr_ck.end() == std::string( "foo" ) );
|
||||
BOOST_TEST( *----itr_ck.end() == std::string( "//share" ) );
|
||||
BOOST_TEST( *next( itr_ck.begin() ) == std::string( "foo" ) );
|
||||
BOOST_TEST( next(next( itr_ck.begin() )) == itr_ck.end() );
|
||||
BOOST_TEST( prior(prior( itr_ck.end() )) == itr_ck.begin() );
|
||||
BOOST_TEST( *prior( itr_ck.end() ) == std::string( "foo" ) );
|
||||
BOOST_TEST( *prior(prior( itr_ck.end() )) == std::string( "//share" ) );
|
||||
|
||||
itr_ck = path( "prn:", fs::system_specific );
|
||||
BOOST_TEST( *itr_ck.begin() == std::string( "prn:" ) );
|
||||
BOOST_TEST( ++itr_ck.begin() == itr_ck.end() );
|
||||
BOOST_TEST( --itr_ck.end() == itr_ck.begin() );
|
||||
BOOST_TEST( *--itr_ck.end() == std::string( "prn:" ) );
|
||||
BOOST_TEST( next( itr_ck.begin() ) == itr_ck.end() );
|
||||
BOOST_TEST( prior( itr_ck.end() ) == itr_ck.begin() );
|
||||
BOOST_TEST( *prior( itr_ck.end() ) == std::string( "prn:" ) );
|
||||
|
||||
check( path( "/", fs::system_specific ), "/" );
|
||||
check( path( "/f", fs::system_specific ), "/f" );
|
||||
@@ -304,6 +307,6 @@ int test_main( int, char*[] )
|
||||
# endif // BOOST_WINDOWS
|
||||
|
||||
// std::cout << errors << " errors detected\n";
|
||||
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user