[require c++20] [moved to stduuid]
Some checks failed
BlockStorage/repertory_osx/pipeline/head There was a failure building this commit
BlockStorage/repertory_linux_builds/pipeline/head Build started...

This commit is contained in:
2023-10-30 19:03:12 -05:00
parent 639d14452b
commit 4bc5cf7c64
12 changed files with 906 additions and 419 deletions

View File

@ -107,8 +107,8 @@ void spin_wait_for_mutex(std::function<bool()> complete,
void spin_wait_for_mutex(bool &complete, std::condition_variable &cond,
std::mutex &mtx, const std::string &text = "");
template <typename t>
[[nodiscard]] auto to_hex_string(const t &val) -> std::string;
template <typename collection_t>
[[nodiscard]] auto to_hex_string(const collection_t &collection) -> std::string;
// template implementations
template <typename t>
@ -154,29 +154,27 @@ template <typename data_type>
return begin + repertory_rand<data_type>() % ((end + 1) - begin);
}
template <typename t>
void remove_element_from(t &collection, const typename t::value_type &value) {
template <typename collection_t>
void remove_element_from(collection_t &collection,
const typename collection_t::value_type &value) {
collection.erase(std::remove(collection.begin(), collection.end(), value),
collection.end());
}
template <typename t>
[[nodiscard]] auto to_hex_string(const t &value) -> std::string {
std::string ret{};
template <typename collection_t>
[[nodiscard]] auto to_hex_string(const collection_t &collection)
-> std::string {
static_assert(sizeof(typename collection_t::value_type) == 1U,
"value_type must be 1 byte in size");
static constexpr const auto mask = 0xFF;
std::array<char, 3> tmp{};
for (const auto &num : value) {
#ifdef _WIN32
sprintf_s(h.data(), h.size() - 1U, "%x", static_cast<std::uint8_t>(num));
#else
sprintf(tmp.data(), "%x", static_cast<std::uint8_t>(num));
#endif
ret +=
(strlen(tmp.data()) == 1) ? std::string("0") + tmp.data() : tmp.data();
std::stringstream stream;
for (const auto &val : collection) {
stream << std::setfill('0') << std::setw(2) << std::hex
<< (static_cast<std::uint32_t>(val) & mask);
}
return ret;
return stream.str();
}
} // namespace repertory::utils