
Hm.
Why not follow this design:
http://www.boost.org/doc/libs/1_50_0/libs/range/doc/html/range/reference/ran...
The implementation would be more elegant, but the user would have to write:
BOOST_FOREACH(directory_entry& x, directory_range(directory_iterator(".")))
instead of the simpler:
BOOST_FOREACH(directory_entry& x, directory_iterator("."))
I verified the above with an actual implementation and test.
I don't see why that's the case. In the posted link, the function istream_range() takes an argument of type istream&, which is the same argument type that the constructor of istream_iterator takes. Notice that istream_range() does *not* take an actual istream_iterator as its constructor argument.
Similarly, I would expect directory_range() to take a path argument, and return something like make_iterator_range(directory_iterator(p), directory_iterator()).
The make_iterator_range template requires ForwardIterators, but directory_iterator only meets InputIterator requirements. Perhaps someone familiar with Boost.Range can come up with a workaround.
istream_iterator is not a forward iterator either, yet istream_range() returns an iterator_range<istream_iterator>. The documentation for iterator_range says: "If the template argument is not a model of Forward Traversal Iterator, one can still use a subset of the interface. In particular, size() requires Random Access Traversal Iterators whereas empty() only requires Single Pass Iterators." So it seems this should be OK. Regards, Nate