Replace boost::filesystem with std (#6432)

This commit is contained in:
Dennis Luxen
2024-06-20 21:44:28 +02:00
committed by GitHub
parent c3f2a6cdb9
commit f1eabc3ecc
64 changed files with 417 additions and 311 deletions
+27 -4
View File
@@ -1,16 +1,39 @@
#ifndef UNIT_TESTS_TEMPORARY_FILE_HPP
#define UNIT_TESTS_TEMPORARY_FILE_HPP
#include <boost/filesystem.hpp>
#include <cstdlib>
#include <filesystem>
#include <random>
#include <string>
inline std::string random_string(std::string::size_type length)
{
static auto &chrs = "0123456789"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
thread_local static std::mt19937 rg{std::random_device{}()};
thread_local static std::uniform_int_distribution<std::string::size_type> pick(
0, sizeof(chrs) - 2);
std::string s;
s.reserve(length);
while (length--)
{
s += chrs[pick(rg)];
}
return s;
}
struct TemporaryFile
{
TemporaryFile() : path(boost::filesystem::unique_path()) {}
TemporaryFile() : path(std::filesystem::temp_directory_path() / random_string(8)) {}
TemporaryFile(const std::string &path) : path(path) {}
~TemporaryFile() { boost::filesystem::remove(path); }
~TemporaryFile() { std::filesystem::remove(path); }
boost::filesystem::path path;
std::filesystem::path path;
};
#endif // UNIT_TESTS_TEMPORARY_FILE_HPP