Skip to content

Commit 38e028d

Browse files
committed
one more round of cleanups for json.h
1 parent 29e3918 commit 38e028d

1 file changed

Lines changed: 16 additions & 26 deletions

File tree

libpstack/json.h

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ operator << (std::ostream &os, const JSON<unsigned char, C>&json) {
7070
template <typename T, typename C>
7171
std::ostream &
7272
operator << (std::ostream &os, const JSON<T, C>&json)
73-
requires (std::is_integral<T>::value && !std::is_same<T, unsigned char>::value)
73+
requires (std::is_integral_v<T> && !std::is_same_v<T, unsigned char>)
7474
{
7575
return os << json.object;
7676
}
@@ -83,32 +83,13 @@ std::ostream &
8383
operator << (std::ostream &os, const JSON<bool, C> &json)
8484
{ return os << (json.object ? "true" : "false"); }
8585

86-
/*
87-
* printers for arrays. char[N] is special, we treat that as a string.
88-
*/
89-
template <typename C, size_t N>
90-
std::ostream &
91-
operator << (std::ostream &os, const JSON<char[N], C> &json)
92-
{ return os << JSON<const char *, C>(&json.object[0], json.context); }
93-
94-
template <typename T, size_t N, typename C>
95-
std::ostream &
96-
operator << (std::ostream &os, const JSON<T[N], C> &j)
97-
{
98-
os << "[";
99-
for (size_t i = 0; i < N; ++i) {
100-
os << (i ? ",\n" : "") << json(j.object[i], j.context);
101-
}
102-
return os << "]";
103-
}
104-
10586
// String-like things.
10687
template <typename T> concept Stringish = std::convertible_to<const T, std::string_view>;
10788

10889
template <Stringish T>
10990
struct Escape {
11091
const T &value;
111-
Escape(const T &value_) : value(value_) { }
92+
explicit Escape(const T &value_) : value(value_) { }
11293
};
11394

11495
/*
@@ -119,8 +100,13 @@ struct Field {
119100
const K &k;
120101
const V &v;
121102
Field(const K &k_, const V &v_) : k(k_), v(v_) {}
103+
122104
Field() = delete;
123105
Field(const Field<K, V> &) = delete;
106+
Field(Field<K, V> &&) = delete;
107+
Field &operator = (const Field &) = delete;
108+
Field &operator = (Field &&) = delete;
109+
~Field() = default;
124110
};
125111

126112
/*
@@ -202,8 +188,8 @@ operator << (std::ostream &os, const JSON<NotAsObject<Container>, Context> &cont
202188
// Exception thrown when encoding error happens.
203189
struct JSONEncodingError : public std::exception {
204190
std::string msg;
205-
const char *what() const noexcept { return msg.c_str(); }
206-
JSONEncodingError(std::string &&rhs) : msg(std::move(rhs)) {}
191+
[[nodiscard]] const char *what() const noexcept override { return msg.c_str(); }
192+
explicit JSONEncodingError(std::string &&rhs) : msg(std::move(rhs)) {}
207193
};
208194

209195
// Escape a string, and print it out.
@@ -213,8 +199,8 @@ inline std::ostream & operator << (std::ostream &o, const Escape<T> &escape)
213199
auto flags(o.flags());
214200
std::string_view view{ escape.value };
215201
for (auto i = view.begin(); i != view.end();) {
216-
int c;
217-
switch (c = (unsigned char)*i++) {
202+
int c = (unsigned char)*i++;
203+
switch (c) {
218204
case '\b': o << "\\b"; break;
219205
case '\f': o << "\\f"; break;
220206
case '\n': o << "\\n"; break;
@@ -277,6 +263,10 @@ class JObject {
277263
public:
278264
explicit JObject(std::ostream &os_) : os{os_} { os << "{ "; }
279265
~JObject() { os << " }"; }
266+
JObject(const JObject &) = delete;
267+
JObject(JObject &&) = delete;
268+
auto operator = (const JObject &) = delete;
269+
auto operator = (JObject &&) = delete;
280270

281271
template <typename K, typename V, typename C> JObject &field(const K &k, const V&v, const C &c) {
282272
Field<K, V> field(k, v);
@@ -310,7 +300,7 @@ class JsonNull {};
310300

311301
template <typename C>
312302
std::ostream &
313-
operator << (std::ostream &os, const JSON<JsonNull, C> &) {
303+
operator << (std::ostream &os, [[maybe_unused]] const JSON<JsonNull, C> &null) {
314304
return os << "null";
315305
}
316306
}

0 commit comments

Comments
 (0)