44 lines
913 B
C++
44 lines
913 B
C++
/*
|
|
* Copyright 2015 Cloudius Systems
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "core/sstring.hh"
|
|
#include <vector>
|
|
#include <sstream>
|
|
|
|
template<typename PrintableRange>
|
|
static inline
|
|
sstring join(sstring delimiter, const PrintableRange& items) {
|
|
return join(delimiter, items.begin(), items.end());
|
|
}
|
|
|
|
template<typename Iterator>
|
|
static inline
|
|
sstring join(sstring delimiter, Iterator begin, Iterator end) {
|
|
std::ostringstream oss;
|
|
while (begin != end) {
|
|
oss << *begin;
|
|
++begin;
|
|
if (begin != end) {
|
|
oss << delimiter;
|
|
}
|
|
}
|
|
return oss.str();
|
|
}
|
|
|
|
template<typename Printable>
|
|
static inline
|
|
sstring
|
|
to_string(const std::vector<Printable>& items) {
|
|
return "[" + join(", ", items) + "]";
|
|
}
|
|
|
|
template<typename Printable>
|
|
static inline
|
|
sstring
|
|
to_string(std::initializer_list<Printable> items) {
|
|
return "[" + join(", ", std::begin(items), std::end(items)) + "]";
|
|
}
|