[filesystem] add directory begin() and end()

[-- I crosspost this message to Boost Users List by mistake yesterday --] I would like to suggest adding functions (template functions?) that would return "begin" and "end" iterators for given path. I think that it's clearer to see: for_each(directory_begin( dir_path ), directory_end(), do_something()); than: for_each(directory_iterator( dir_path ), directory_iterator(), do_somethig()); The functions directory_begin()/directory_end() would mimic the convenient container.begin()/container.end() functions used in STL. I know that it's merely a decoration but so is std::make_pair. It could just be: template <class Path> inline class basic_directory_iterator<Path> directory_begin(const Path& dp) { return basic_directory_iterator<Path>(dp); } template <class Path> inline class basic_directory_iterator<Path> directory_end() { return basic_directory_iterator<Path>(); } Vaclav Cechura

On Nov 16, 2007 2:17 PM, v2cechura <v2cechura@atlas.cz> wrote:
[-- I crosspost this message to Boost Users List by mistake yesterday --]
I would like to suggest adding functions (template functions?) that would return "begin" and "end" iterators for given path. I think that it's clearer to see:
for_each(directory_begin( dir_path ), directory_end(), do_something());
than:
for_each(directory_iterator( dir_path ), directory_iterator(), do_somethig());
The functions directory_begin()/directory_end() would mimic the convenient container.begin()/container.end() functions used in STL. I know that it's merely a decoration but so is std::make_pair.
Not really. make_pair makes it possible not to specify the template arguments for std::pair. It is not really just a decoration. In this case, IMHO directory_{begin,end} do not add much to basic_directory_iterator, as directory_iterator is a good default and doesn't have template parameters to be deduced. In fact the functions you proposed:
... template <class Path> inline class basic_directory_iterator<Path> directory_end() { return basic_directory_iterator<Path>(); }
wouldn't work in your example, because you would need to specify the Path template argument for directory_end. On the other hand, if directory_iterator was a valid range, you could do std::for_each(boost::begin(directory_iterator(dir_path)), boost::end(directory_iterator(dir_path), ...); which would be *very* useful to leverage generic range based algorithms. HTH, gpd

v2cechura wrote:
The functions directory_begin()/directory_end() would mimic the convenient container.begin()/container.end() functions used in STL.
FWIW, oven @ http://tinyurl.com/23mmhn contains directory_range, which is a range wrapper for directory_iterator. directory_range drng(a_path); BOOST_FOREACH (boost::filesystem::path const& pt, drng) std::cout << pt.leaf() << std::endl; Regards, -- Shunsuke Sogame
participants (3)
-
Giovanni Piero Deretta
-
shunsuke
-
v2cechura