summaryrefslogtreecommitdiffstats
path: root/src/include/stringify.h
blob: 1b2a130c9301d0764bf6cf1cfcc1e62f38843ecc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef __CEPH_STRINGIFY_H
#define __CEPH_STRINGIFY_H

#include <string>
#include <sstream>

#include "include/types.h"

template<typename T>
inline std::string stringify(const T& a) {
#if defined(__GNUC__) && !(defined(__clang__) || defined(__INTEL_COMPILER))
  static __thread std::ostringstream ss;
  ss.str("");
#else
  std::ostringstream ss;
#endif
  ss << a;
  return ss.str();
}

template <class T, class A>
T joinify(const A &begin, const A &end, const T &t)
{
  T result;
  for (A it = begin; it != end; it++) {
    if (!result.empty())
      result.append(t);
    result.append(*it);
  }
  return result;
}

#endif