]> git.proxmox.com Git - ceph.git/blob - ceph/src/include/stringify.h
d7b90ed2c909413af2c27c1af5ab17902442c882
[ceph.git] / ceph / src / include / stringify.h
1 #ifndef __CEPH_STRINGIFY_H
2 #define __CEPH_STRINGIFY_H
3
4 #include <string>
5 #include <sstream>
6
7 template<typename T>
8 inline std::string stringify(const T& a) {
9 #if defined(__GNUC__) && !(defined(__clang__) || defined(__INTEL_COMPILER))
10 static __thread std::ostringstream ss;
11 ss.str("");
12 #else
13 std::ostringstream ss;
14 #endif
15 ss << a;
16 return ss.str();
17 }
18
19 template <class T, class A>
20 T joinify(const A &begin, const A &end, const T &t)
21 {
22 T result;
23 for (A it = begin; it != end; it++) {
24 if (!result.empty())
25 result.append(t);
26 result.append(*it);
27 }
28 return result;
29 }
30
31 #endif