This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Overload std::distance and std::advance for path::iterator
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Thu, 13 Dec 2018 12:09:38 +0000
- Subject: Re: [PATCH] Overload std::distance and std::advance for path::iterator
- References: <20181212161410.GA2589@redhat.com>
On 12/12/18 16:14 +0000, Jonathan Wakely wrote:
+void
+test04()
+{
+ std::filesystem::path p = "/a/b/c/d/e/f/g";
+ VERIFY( std::distance(p.begin(), p.end()) == 8);
+ auto it = p.begin();
+ std::advance(it, 1);
+ VERIFY( std::distance(p.begin(), it) == 1 );
+ VERIFY( it->native() == "a" );
+ std::advance(it, 3);
+ VERIFY( std::distance(p.begin(), it) == 4 );
+ VERIFY( it->native() == "d" );
+ std::advance(it, -2);
+ VERIFY( std::distance(p.begin(), it) == 2 );
+ VERIFY( it->native() == "b" );
This fails on Windows because native() returns a wide string.
Fixed like so, committed to trunk.
commit 499376d36d7f792174f9080cbd59e7482f7e18b0
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Dec 13 12:07:43 2018 +0000
Fix test to work when path::native() returns wstring
* testsuite/27_io/filesystem/path/itr/traversal.cc: Fix test for
mingw.
diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/itr/traversal.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/itr/traversal.cc
index 55760e82a9a..d77e613ee53 100644
--- a/libstdc++-v3/testsuite/27_io/filesystem/path/itr/traversal.cc
+++ b/libstdc++-v3/testsuite/27_io/filesystem/path/itr/traversal.cc
@@ -144,13 +144,13 @@ test04()
auto it = p.begin();
std::advance(it, 1);
VERIFY( std::distance(p.begin(), it) == 1 );
- VERIFY( it->native() == "a" );
+ VERIFY( it->string() == "a" );
std::advance(it, 3);
VERIFY( std::distance(p.begin(), it) == 4 );
- VERIFY( it->native() == "d" );
+ VERIFY( it->string() == "d" );
std::advance(it, -2);
VERIFY( std::distance(p.begin(), it) == 2 );
- VERIFY( it->native() == "b" );
+ VERIFY( it->string() == "b" );
}
int