#include #include #include #include void random_module() { std::cout << std::endl << "random_module" << std::endl; auto seed = 12312; std::default_random_engine generator(seed); auto min = 0; auto max = 100; std::uniform_int_distribution uniform(min, max); int random_value = uniform(generator); std::cout << random_value << std::endl; // Using capture in lambda. auto random_generator = [&uniform, &generator]() -> int { return uniform(generator); }; std::cout << random_generator() << " " << random_generator() << std::endl; } void filesystem_module() { std::cout << std::endl << "filesystem_module" << std::endl; std::filesystem::path root("./"); for (auto&& item : std::filesystem::recursive_directory_iterator(root)) { // There is also 'item.is_directory'. if (std::filesystem::is_directory(item.status())) { std::cout << "Directory: " << item.path().filename().string() << std::endl;; } else { auto filename = item.path().filename(); std::cout << " " << filename.extension().string() << " : " << filename.string() << std::endl; } } // There are other operations for copy/delete/... } void chrono_module() { std::cout << std::endl << "chrono_module" << std::endl; // system_clock // steady_clock - never decreasing (leaps seconds, daylight saving time) // high_resolution_clock auto start = std::chrono::high_resolution_clock::now(); // Some busy work, just to create a delay. for (int x = 0; x < 10000; ++x) { for (int y = 0; y < 10000; ++y) { int z = x + y; } } auto end = std::chrono::high_resolution_clock::now(); // Get internal in miliseconds. auto ms = std::chrono::duration_cast(end - start); std::cout << "Duration: " << ms << std::endl; // Showcase of arithmetics. std::chrono::seconds seconds(55); std::chrono::hours hours(11); auto time = hours + seconds; std::cout << "Time: " << time << std::endl; } int main() { random_module(); filesystem_module(); chrono_module(); }