//********************************************************
// The following code example is taken from the book
//  C++23 - The Complete Guide
//  by Nicolai M. Josuttis (www.josuttis.com)
//  http://www.cppstd23.com
//
// The code is licensed under a
//  Creative Commons Attribution 4.0 International License
//  http://creativecommons.org/licenses/by/4.0/
//********************************************************


#include <filesystem>
#include <generator>
#include "tracingpmr.hpp"

std::pmr::generator<std::string> allFiles(const std::filesystem::path& p)
{
  if (is_directory(p)) { // if path p is a directory
    // iterate with a coroutine over the subdirectory:
    for (const auto& e : std::filesystem::directory_iterator{p}) {
      co_yield std::ranges::elements_of(allFiles(e.path()));
    }
  }
  else {
    // yield the normalized filename:
    co_yield p.lexically_normal().string();
  }  
}

