Skip to content
This repository was archived by the owner on Mar 26, 2020. It is now read-only.

Commit 07fe488

Browse files
committed
Use an empty struct instead of nullptr_t to represent null.
Fixes #91.
1 parent 8d7936d commit 07fe488

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

json11.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,20 @@ using std::make_shared;
3737
using std::initializer_list;
3838
using std::move;
3939

40+
/* Helper for representing null - just a do-nothing struct, plus comparison
41+
* operators so the helpers in JsonValue work. We can't use nullptr_t because
42+
* it may not be orderable.
43+
*/
44+
struct NullStruct {
45+
bool operator==(NullStruct) const { return true; }
46+
bool operator<(NullStruct) const { return false; }
47+
};
48+
4049
/* * * * * * * * * * * * * * * * * * * *
4150
* Serialization
4251
*/
4352

44-
static void dump(std::nullptr_t, string &out) {
53+
static void dump(NullStruct, string &out) {
4554
out += "null";
4655
}
4756

@@ -208,9 +217,9 @@ class JsonObject final : public Value<Json::OBJECT, Json::object> {
208217
explicit JsonObject(Json::object &&value) : Value(move(value)) {}
209218
};
210219

211-
class JsonNull final : public Value<Json::NUL, std::nullptr_t> {
220+
class JsonNull final : public Value<Json::NUL, NullStruct> {
212221
public:
213-
JsonNull() : Value(nullptr) {}
222+
JsonNull() : Value({}) {}
214223
};
215224

216225
/* * * * * * * * * * * * * * * * * * * *

0 commit comments

Comments
 (0)