Refactored template builder with try_as methods for different types
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user