Reading the contents of a directory hierarchy

#include <x/dirwalk.H>

x::dirwalk etcdir=x::dirwalk::create("/etc", true);
x::dirwalk::iterator etcdirb(etcdir->begin()), etcdire(etcdir->end());

while (etcdirb != etcdire)
    std::cout << (std::string)*etcdirb << std::endl;

// Or, a short version:

auto etcdir=x::dir::create("/etc", true);

for (auto direntry: *etcdir)
    std::cout << (std::string)direntry << std::endl;

x::dirwalk creates a factory for beginning and ending iterators, x::dirwalk::base::iterator, that are like x::dir::base::iterator, but which iterate over an entire directory hierarchy: the given directory and all of its subdirectories.

When iterating through a directory hierarchy, x::dirwalk tries to ignore ENOENTs which can occur when another process rmdirs the hierarchy which is getting walked through.