Skip to content

Commit db23173

Browse files
Add new format_to_string function
This simply writes values formatted with format_rec to a string and returns that instead of an ostream, which is useful if immediate output isn’t the desired behaviour.
1 parent b2f45b4 commit db23173

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/util/format.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Author: Daniel Kroening, kroening@kroening.com
1010
#define CPROVER_UTIL_FORMAT_H
1111

1212
#include <iosfwd>
13+
#include <sstream>
14+
#include <string>
1315

1416
//! The below enables convenient syntax for feeding
1517
//! objects into streams, via stream << format(o)
@@ -37,4 +39,12 @@ static inline format_containert<T> format(const T &o)
3739
return format_containert<T>(o);
3840
}
3941

42+
template <typename T>
43+
std::string format_to_string(const T &o)
44+
{
45+
std::ostringstream oss;
46+
oss << format(o);
47+
return oss.str();
48+
}
49+
4050
#endif // CPROVER_UTIL_FORMAT_H

0 commit comments

Comments
 (0)