1 #include <sstream> 2 #include <string> 3 #include <vector> 4 #include <functional> 5 6 std::string to_lower(const std::string& str); 7 8 template <typename T> join(const T & values,const std::string & delim)9std::string join(const T& values, const std::string& delim) 10 { 11 std::ostringstream ss; 12 for (const auto& v : values) { 13 if (&v != &values[0]) 14 ss << delim; 15 ss << v; 16 } 17 return ss.str(); 18 } 19 20 template <typename T> join(const std::vector<T> & values,const std::string & delim,std::function<std::string (T)> func)21std::string join(const std::vector<T>& values, const std::string& delim, std::function<std::string(T)> func) 22 { 23 std::ostringstream ss; 24 for (const auto& v : values) { 25 if (&v != &values[0]) 26 ss << delim; 27 ss << func(v); 28 } 29 return ss.str(); 30 } 31 32 std::string sformat(const char *fmt, ...) 33 __attribute__ ((format (printf, 1, 2))); 34