Boost logo

Boost :

From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2007-11-16 16:13:24

On Nov 16, 2007 2:17 PM, v2cechura <v2cechura_at_[hidden]> 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.



Boost list run by bdawes at, gregod at, cpdaniel at, john at