FreeTensor
Loading...
Searching...
No Matches
to_string.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_TO_STRING_H
2#define FREE_TENSOR_TO_STRING_H
3
4#include <sstream>
5
6namespace freetensor {
7
8class ASTNode;
9template <class T> class Ref;
10
11// Define an `toString` function for all objects having `ostream <<` defined
12
13template <class T>
14concept HasStreamOutput = requires(std::ostream &os, const T &obj) {
15 os << obj;
16};
17
18template <class T>
19requires requires(const T &obj) {
20 requires HasStreamOutput<T>;
21
22 // We have a special version for AST and its subclasses
23 requires !std::convertible_to<T, Ref<ASTNode>>;
24}
25std::string toString(const T &obj) {
26 std::ostringstream os;
27 os << obj;
28 return os.str();
29}
30
31} // namespace freetensor
32
33#endif // FREE_TENSOR_TO_STRING_H
Definition: to_string.h:14
Definition: allocator.h:9
std::string toString(const AST &op)
Definition: print_ast.cc:784