mirror of
https://github.com/NixOS/nix.git
synced 2025-11-16 07:22:43 +01:00
parent
79122c66b1
commit
f9d1f36169
2 changed files with 50 additions and 0 deletions
|
|
@ -55,6 +55,20 @@ extern template std::string concatStringsSep(std::string_view, const std::list<s
|
|||
extern template std::string concatStringsSep(std::string_view, const std::set<std::string> &);
|
||||
extern template std::string concatStringsSep(std::string_view, const std::vector<std::string> &);
|
||||
|
||||
/**
|
||||
* Apply a function to the `iterable`'s items and concat them with `separator`.
|
||||
*/
|
||||
template<class C, class F>
|
||||
std::string concatMapStringsSep(std::string_view separator, const C & iterable, F fn)
|
||||
{
|
||||
std::vector<std::string> strings;
|
||||
strings.reserve(iterable.size());
|
||||
for (const auto & elem : iterable) {
|
||||
strings.push_back(fn(elem));
|
||||
}
|
||||
return concatStringsSep(separator, strings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore any empty strings at the start of the list, and then concatenate the
|
||||
* given strings with a separator between the elements.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue