mirror of
https://github.com/nlohmann/json.git
synced 2025-04-19 13:02:16 +03:00
* mkdocs: add string_view examples * mkdocs: reference underlying operators * mkdocs: add operator<=> examples * mkdocs: fix style check issues * mkdocs: tweak BJData page * mkdocs: add CMake option hints to macros * mkdocs: fix JSON_DISABLE_ENUM_SERIALIZATION definition * mkdocs: fix link to unit-udt.cpp * mkdocs: fix "Arbitrary Type Conversions" title * mkdocs: link to api/macros/*.md instead of features/macros.md * mkdocs: document JSON_DisableEnumSerialization CMake option * mkdocs: encode required C++ standard in example files * docset: detect gsed/sed * docset: update index * docset: fix CSS patching * docset: add list_missing_pages make target * docset: add list_removed_paths make target * docset: replace page titles with name from index * docset: add install target for Zeal docset browser * Use GCC_TOOL in ci_test_documentation target
42 lines
1.1 KiB
C++
42 lines
1.1 KiB
C++
#include <compare>
|
|
#include <iostream>
|
|
#include <nlohmann/json.hpp>
|
|
|
|
using json = nlohmann::json;
|
|
|
|
const char* to_string(const std::partial_ordering& po)
|
|
{
|
|
if (std::is_lt(po))
|
|
{
|
|
return "less";
|
|
}
|
|
else if (std::is_gt(po))
|
|
{
|
|
return "greater";
|
|
}
|
|
else if (std::is_eq(po))
|
|
{
|
|
return "equivalent";
|
|
}
|
|
return "unordered";
|
|
}
|
|
|
|
int main()
|
|
{
|
|
// create several JSON values
|
|
json array_1 = {1, 2, 3};
|
|
json array_2 = {1, 2, 4};
|
|
json object_1 = {{"A", "a"}, {"B", "b"}};
|
|
json object_2 = {{"B", "b"}, {"A", "a"}};
|
|
json number = 17;
|
|
json string = "foo";
|
|
json discarded = json(json::value_t::discarded);
|
|
|
|
|
|
// output values and comparisons
|
|
std::cout << array_1 << " <=> " << array_2 << " := " << to_string(array_1 <=> array_2) << '\n'; // *NOPAD*
|
|
std::cout << object_1 << " <=> " << object_2 << " := " << to_string(object_1 <=> object_2) << '\n'; // *NOPAD*
|
|
std::cout << string << " <=> " << number << " := " << to_string(string <=> number) << '\n'; // *NOPAD*
|
|
std::cout << string << " <=> " << discarded << " := " << to_string(string <=> discarded) << '\n'; // *NOPAD*
|
|
}
|