Simplify JsonScope.

GitOrigin-RevId: c3a9aea0c053db9684853acb857ae2381d542cb2
This commit is contained in:
levlam 2019-12-08 09:02:20 +03:00
parent 8a7d6be7df
commit a0d761f27e
2 changed files with 4 additions and 20 deletions

View File

@ -301,18 +301,6 @@ class JsonScope {
JsonScope &operator<<(double x) {
return *this << JsonFloat(x);
}
template <class T>
JsonScope &operator<<(const T *x); // not implemented
template <size_t N>
JsonScope &operator<<(const char (&x)[N]) {
return *this << JsonString(Slice(x));
}
JsonScope &operator<<(const char *x) {
return *this << JsonString(Slice(x));
}
JsonScope &operator<<(const string &x) {
return *this << JsonString(Slice(x));
}
JsonScope &operator<<(Slice x) {
return *this << JsonString(x);
}
@ -401,12 +389,8 @@ class JsonObjectScope : public JsonScope {
jb_->print_offset();
*sb_ << "}";
}
template <class S, class T>
JsonObjectScope &operator<<(std::pair<S, T> key_value) {
return (*this)(key_value.first, key_value.second);
}
template <class S, class T>
JsonObjectScope &operator()(S &&key, T &&value) {
template <class T>
JsonObjectScope &operator()(Slice key, T &&value) {
CHECK(is_active());
if (is_first_) {
*sb_ << ",";
@ -590,7 +574,7 @@ class JsonValue : public Jsonable {
case Type::Object: {
auto object = scope->enter_object();
for (auto &key_value : get_object()) {
object(JsonString(key_value.first), key_value.second);
object(key_value.first, key_value.second);
}
break;
}

View File

@ -49,7 +49,7 @@ TEST(JSON, object) {
JsonBuilder jb(std::move(sb));
auto c = jb.enter_object();
c("key", "value");
c << std::make_pair("1", 2);
c("1", 2);
c.leave();
ASSERT_EQ(jb.string_builder().is_error(), false);
auto encoded = jb.string_builder().as_cslice().str();