Refactored template builder with try_as methods for different types

This commit is contained in:
Bartek Kryza
2023-05-01 01:40:46 +02:00
parent 6ebdc8ab77
commit 68f067f76a
12 changed files with 691 additions and 585 deletions

View File

@@ -92,9 +92,26 @@ std::string get_git_toplevel_dir();
std::vector<std::string> split(
std::string str, std::string_view delimiter, bool skip_empty = true);
template <typename T, typename F> void erase_if(std::vector<T> &v, F &&f)
{
v.erase(std::remove_if(v.begin(), v.end(), std::forward<F>(f)), v.end());
}
std::string join(
const std::vector<std::string> &toks, std::string_view delimiter);
template <typename... Args>
std::string join(std::string_view delimiter, Args... args)
{
std::vector<std::string> coll{args...};
erase_if(coll, [](const auto &s) {
return s.find_first_not_of(" \t") == std::string::npos;
});
return fmt::format("{}", fmt::join(coll, delimiter));
}
/**
* @brief Abbreviate string to max_length, and replace last 3 characters
* with ellipsis.