Skip to content

Commit

Permalink
Refactored generate() for pairs. (#1501)
Browse files Browse the repository at this point in the history
Refactored `generate()` for pairs to introduce `toJSON()`, for cases
where we just want to generate the body of a JSON object.
  • Loading branch information
liujed authored Sep 20, 2018
1 parent d37330b commit 5096e1c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions ir/json_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,18 @@ class JSONGenerator {

template<typename T, typename U>
void generate(const std::pair<T, U> &v) {
out << "{" << std::endl << ++indent << "\"first\" : ";
++indent;
out << "{" << std::endl;
toJSON(v);
out << std::endl << --indent << "}";
}

template<typename T, typename U>
void toJSON(const std::pair<T, U> &v) {
out << indent << "\"first\" : ";
generate(v.first);
out << "," << std::endl << indent << "\"second\" : ";
generate(v.second);
out << std::endl << --indent << "}";
}

template<typename T>
Expand Down

0 comments on commit 5096e1c

Please sign in to comment.