StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Stsstream.h
Go to the documentation of this file.
1 
9 #ifndef STSSTREAM_H
10 #define STSSTREAM_H
11 #include <ctype.h>
12 #include "Rstrstream.h"
13 #ifdef R__SSTREAM
14 using std::streamsize;
15 
16 class istrstream : public std::istringstream {
17 public:
18 istrstream(): std::istringstream(){}
19 istrstream(const char *init):std::istringstream(std::string(init)){}
20 };
21 #else
22 #endif
23 
24 // Hide the function from `rootcint` as it cannot process variadic template parameters
25 #ifndef __CINT__
26 
27 #include <iostream>
28 #include <cstdio>
29 #include <memory>
30 #include <string>
31 
39 template<typename ... Args>
40 std::string FormString(const std::string& format, Args ... args)
41 {
42  size_t cstr_size = snprintf(nullptr, 0, format.c_str(), args ...) + 1; // Extra space for '\0'
43  std::unique_ptr<char[]> buf(new char[cstr_size]);
44  snprintf(buf.get(), cstr_size, format.c_str(), args ...);
45  return std::string(buf.get(), buf.get() + cstr_size - 1); // We don't want the '\0' inside
46 }
47 #endif
48 
49 #endif
std::string FormString(const std::string &format, Args...args)
Definition: Stsstream.h:40