In boost directory_iterator example - how to list directory files not recursive (see this answer) is the sample code
#include <boost/filesystem.hpp>
#include <boost/range/iterator_range.hpp>
#include <iostream>
...
using namespace boost::filesystem;
for(auto& entry : boost::make_iterator_range(directory_iterator(p), {}))
{
std::cout << entry << "\n";
}
(p
is of type boost::filesystem::path
.)
Upon looking at the documentation for make_iterator_range
, I think the constructor being called is this one:
template< class ForwardTraversalIterator >
iterator_range< ForwardTraversalIterator >
make_iterator_range( ForwardTraversalIterator Begin,
ForwardTraversalIterator End );
If I'm right, then the second argument passed in the code example above, {}
, seems to correspond to the end of whatever container is invisibly iterated over by the directory_iterator
.
I've never seen this before.
Is it possible to construct the end
iterator just by value-constructing such an iterator from the empty initializer list {}
? (Am I even phrasing this properly?)
I wouldn't mind having someone spell out what is going on under the hood, given that the type of the iterator so constructed must match the type of the first iterator (directory_iterator(p)
). (Is template argument deduction going on here?)