[filesystem] compiling code breaks on 1.36

I am on ubuntu 8.04. When upgrading from 1.34.1 to 1.36 the following code breaks. bfs_test.cpp: #include <iostream> #include <boost/filesystem.hpp> using std::cout; using std::endl; namespace bfs = boost::filesystem; int main() { bfs::recursive_directory_iterator end_itr; for( bfs::recursive_directory_iterator itr( "." ); itr != end_itr; ++itr ) { cout << bfs::extension( itr->leaf() ) << endl; } return 0; } I compile for 1.34.1 like this: gcc -o bfs bfs_test.cpp -lstdc++ -lboost_filesystem-gcc41-mt-1_34_1 running the result prints all file extensions recursively as expected. After switching to 1.36 compiling like this: gcc -o bfs bfs_test.cpp -lstdc++ -lboost_filesystem-gcc42-mt-1_36 gives the following error: bfs_test.cpp: In function 'int main()': bfs_test.cpp:13: error: 'class boost::filesystem::basic_directory_entry<boost::filesystem::basic_path<s td::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >' has no member named 'leaf' My mistake, or did something change/break? Scott Finley

On Fri, Aug 15, 2008 at 12:57, Scott Finley <sfinley@tomotherapy.com> wrote:
bfs_test.cpp: In function 'int main()':
bfs_test.cpp:13: error: 'class boost::filesystem::basic_directory_entry<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >' has no member named 'leaf'
My mistake, or did something change/break?
It looks like you now need itr->path().leaf() or boost::implicit_cast<bfs::path const &>(*itr).leaf() ( http://beta.boost.org/doc/libs/1_36_0/libs/filesystem/doc/reference.html#Cla... ) As I recall, this change was part of optimization efforts to make iterating faster by caching the file_status. Also, it was decided that some of the names for path decomposition functions were confusing, particularly branch and leaf, so they were changed. The new path decomposition table suggests that you should now be using filename() instead of leaf(): http://beta.boost.org/doc/libs/1_36_0/libs/filesystem/doc/reference.html#Pat... (But it's likely backwards-compatible, so you shouldn't need to.) HTH, ~ Scott

Scott McMurray wrote:
On Fri, Aug 15, 2008 at 12:57, Scott Finley <sfinley@tomotherapy.com> wrote:
bfs_test.cpp: In function 'int main()':
bfs_test.cpp:13: error: 'class boost::filesystem::basic_directory_entry<boost::filesystem::basic_path<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, boost::filesystem::path_traits> >' has no member named 'leaf'
My mistake, or did something change/break?
It looks like you now need itr->path().leaf() or boost::implicit_cast<bfs::path const &>(*itr).leaf() ( http://beta.boost.org/doc/libs/1_36_0/libs/filesystem/doc/reference.html#Cla... )
As I recall, this change was part of optimization efforts to make iterating faster by caching the file_status.
Also, it was decided that some of the names for path decomposition functions were confusing, particularly branch and leaf, so they were changed. The new path decomposition table suggests that you should now be using filename() instead of leaf(): http://beta.boost.org/doc/libs/1_36_0/libs/filesystem/doc/reference.html#Pat... (But it's likely backwards-compatible, so you shouldn't need to.)
Yes, that's the theory. But it looks like 1.36.0 inadvertently renamed basic_directory_entry::leaf without providing backward compatibility. I'll try to post a hotfix for that. Since basic_directory_entry::leaf is deprecated anyhow, my initial reaction is that it should have been left alone. --Beman
participants (3)
-
Beman Dawes
-
Scott Finley
-
Scott McMurray