Skip to content

Commit

Permalink
Use an empty struct instead of nullptr_t to represent null.
Browse files Browse the repository at this point in the history
Fixes dropbox#91.
  • Loading branch information
j4cbo committed Jan 18, 2017
1 parent 8d7936d commit 07fe488
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions json11.cpp
Expand Up @@ -37,11 +37,20 @@ using std::make_shared;
using std::initializer_list;
using std::move;

/* Helper for representing null - just a do-nothing struct, plus comparison
* operators so the helpers in JsonValue work. We can't use nullptr_t because
* it may not be orderable.
*/
struct NullStruct {
bool operator==(NullStruct) const { return true; }
bool operator<(NullStruct) const { return false; }
};

/* * * * * * * * * * * * * * * * * * * *
* Serialization
*/

static void dump(std::nullptr_t, string &out) {
static void dump(NullStruct, string &out) {
out += "null";
}

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

class JsonNull final : public Value<Json::NUL, std::nullptr_t> {
class JsonNull final : public Value<Json::NUL, NullStruct> {
public:
JsonNull() : Value(nullptr) {}
JsonNull() : Value({}) {}
};

/* * * * * * * * * * * * * * * * * * * *
Expand Down

0 comments on commit 07fe488

Please sign in to comment.