I have this code, which does a simple recursive directory iteration and prints each directory entry and then does it again (
http://coliru.stacked-crooked.com/a/0bfab95a513ebed8 ):
#include <boost/filesystem.hpp>
#include <boost/range/iterator_range.hpp>
#include <iostream>
namespace fs = boost::filesystem;
int main()
{
try
{
const auto iter = fs::recursive_directory_iterator{ "." };
for( const auto& entry : boost::make_iterator_range( iter, {} ) )
{
std::cout << entry << "\n";
}
// Rinse and repeat
std::cout << "\n";
for( const auto& entry : boost::make_iterator_range( iter, {} ) ) // CRASH -- Replace 'iter' with 'fs::recursive_directory_iterator{"."}' and it will work.
//for( const auto& entry : boost::make_iterator_range( fs::recursive_directory_iterator{"."}, {} ) )
{
std::cout << entry << "\n";
}
}
catch( const std::exception& e )
{
std::cerr << e.what() << "\n";
}
catch( ... )
{
std::cerr << "Unknown exception.\n";
}
}
As you can see at Coliru, it crashes. (It also crashes on Visual Studio 2012 and with Boost 1.55.0 and on Coliru with <experimental/filesystem> instead of Boost.)