wsd: helper to concatenate streamable elements together

Change-Id: I0d989b54d5eebbd3efee2502d84a82281ebf62a7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This commit is contained in:
Ashod Nakashian 2023-10-01 11:10:35 -04:00 committed by Miklos Vajna
parent 6de46d746e
commit 44cc7145c2

View file

@ -1432,6 +1432,27 @@ int main(int argc, char**argv)
return std::string(s);
}
/// Concatenate the given elements in a container to each other using
/// the delimiter of choice.
template <typename T, typename U = const char*>
inline std::string join(const T& elements, const U& delimiter = ", ")
{
std::ostringstream oss;
bool first = true;
for (const auto& elem : elements)
{
if (!first)
{
oss << delimiter;
}
oss << elem;
first = false;
}
return oss.str();
}
/// Dump an object that supports .dumpState into a string.
/// Helpful for logging.
template <typename T> std::string dump(const T& object, const std::string& indent = ", ")