23 #ifndef STDEXT_FORMAT_H
24 #define STDEXT_FORMAT_H
38 template<
class T>
void print_ostream(std::ostringstream& stream,
const T& last) { stream << last; }
39 template<
class T,
class... Args>
40 void print_ostream(std::ostringstream& stream,
const T& first,
const Args&... rest) { stream <<
"\t" << first;
print_ostream(stream, rest...); }
44 void print(
const T&... args) { std::ostringstream buf;
print_ostream(buf, args...); std::cout << buf.str() << std::endl; }
47 typename std::enable_if<std::is_integral<T>::value ||
48 std::is_pointer<T>::value ||
49 std::is_floating_point<T>::value ||
50 std::is_enum<T>::value, T>::type
sprintf_cast(
const T& t) {
return t; }
52 inline const char *
sprintf_cast(
const std::string& s) {
return s.c_str(); }
55 template<
typename Tuple,
typename... Args>
static int call(
char *s,
size_t maxlen,
const char *
format,
const Tuple& tuple,
const Args&... args) {
58 template<
typename Tuple,
typename... Args>
static int call(
char *s,
size_t maxlen,
const char *
format,
const Tuple& tuple,
const Args&... args) {
60 return _snprintf(s, maxlen,
format, args...);
68 template<
typename... Args>
69 int snprintf(
char *s,
size_t maxlen,
const char *
format,
const Args&... args) {
70 std::tuple<typename replace_extent<Args>::type...> tuple(args...);
74 template<
typename... Args>
76 std::strncpy(s,
format, maxlen);
81 template<
typename... Args>
82 inline std::string
format() {
return std::string(); }
84 template<
typename... Args>
88 template<
typename... Args>
89 std::string
format(
const std::string&
format,
const Args&... args) {