-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathformat.h
50 lines (39 loc) · 978 Bytes
/
format.h
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
/*******************************************************************\
Module:
Author: Daniel Kroening, [email protected]
\*******************************************************************/
#ifndef CPROVER_UTIL_FORMAT_H
#define CPROVER_UTIL_FORMAT_H
#include <iosfwd>
#include <sstream>
#include <string>
//! The below enables convenient syntax for feeding
//! objects into streams, via stream << format(o)
template <typename T>
class format_containert
{
public:
explicit format_containert(const T &_o) : o(_o)
{
}
const T &o;
};
template <typename T>
static inline std::ostream &
operator<<(std::ostream &os, const format_containert<T> &f)
{
return format_rec(os, f.o);
}
template <typename T>
static inline format_containert<T> format(const T &o)
{
return format_containert<T>(o);
}
template <typename T>
std::string format_to_string(const T &o)
{
std::ostringstream oss;
oss << format(o);
return oss.str();
}
#endif // CPROVER_UTIL_FORMAT_H