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:
parent
6de46d746e
commit
44cc7145c2
1 changed files with 21 additions and 0 deletions
|
@ -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 = ", ")
|
||||
|
|
Loading…
Reference in a new issue