1#include <compare>
2#include <iostream>
3#include <nlohmann/json.hpp>
4
5using json = nlohmann::json;
6
7const char* to_string(const std::partial_ordering& po)
8{
9    if (std::is_lt(po))
10    {
11        return "less";
12    }
13    else if (std::is_gt(po))
14    {
15        return "greater";
16    }
17    else if (std::is_eq(po))
18    {
19        return "equivalent";
20    }
21    return "unordered";
22}
23
24int main()
25{
26    // create several JSON values
27    json array_1 = {1, 2, 3};
28    json array_2 = {1, 2, 4};
29    json object_1 = {{"A", "a"}, {"B", "b"}};
30    json object_2 = {{"B", "b"}, {"A", "a"}};
31    json number = 17;
32    json string = "foo";
33    json discarded = json(json::value_t::discarded);
34
35
36    // output values and comparisons
37    std::cout << array_1 << " <=> " << array_2 << " := " << to_string(array_1 <=> array_2) << '\n'; // *NOPAD*
38    std::cout << object_1 << " <=> " << object_2 << " := " << to_string(object_1 <=> object_2) << '\n'; // *NOPAD*
39    std::cout << string << " <=> " << number << " := " << to_string(string <=> number) << '\n'; // *NOPAD*
40    std::cout << string << " <=> " << discarded << " := " << to_string(string <=> discarded) << '\n'; // *NOPAD*
41}
42