Replace boost::filesystem with std (#6432)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user