-
Notifications
You must be signed in to change notification settings - Fork 4
/
common.hpp
63 lines (45 loc) · 1.12 KB
/
common.hpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef __COMMON_HPP__INCLUDED__
#define __COMMON_HPP__INCLUDED__
# include <iostream>
# include <iterator> // istream_iterator
# include <sstream> // ostringstream
# include <string>
namespace util
{
// Compose a string message from multiple values
inline void print_all(std::ostream& out)
{
out << std::flush;
}
template <class H, class ...T>
void print_all(std::ostream& out, H head, T... t)
{
out << head;
print_all(out, t...);
}
template <class ...T>
std::string sprint_all(T... t)
{
std::ostringstream out;
print_all(out, t...);
return out.str();
}
// iterate over lines in a stream
namespace detail
{
class Line : public std::string
{
friend std::istream& operator>>(std::istream& in, Line& line)
{
return std::getline(in, line);
}
};
}
typedef std::istream_iterator<detail::Line> line_iterator;
//
inline std::string quoted(std::string str)
{
return '"' + str + '"';
}
}
#endif // include guard