With this, we can do
std::unordered_set<dht::tokens> tokens
logger.debug("tokens = {}", tokens)
51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
/*
|
|
* Copyright 2015 Cloudius Systems
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "core/sstring.hh"
|
|
#include <vector>
|
|
#include <sstream>
|
|
#include <unordered_set>
|
|
|
|
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)) + "]";
|
|
}
|
|
|
|
template <typename T>
|
|
std::ostream& operator<<(std::ostream& os, const std::unordered_set<T>& items) {
|
|
os << "{" << join(", ", items) << "}";
|
|
return os;
|
|
}
|