mirror of
https://github.com/nlohmann/json.git
synced 2024-08-21 12:32:27 +02: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()
|
|
{
|
|
using float_limits = std::numeric_limits<json::number_float_t>;
|
|
constexpr auto nan = float_limits::quiet_NaN();
|
|
|
|
// create several JSON values
|
|
json boolean = false;
|
|
json number = 17;
|
|
json string = "17";
|
|
|
|
|
|
// output values and comparisons
|
|
std::cout << std::boolalpha << std::fixed;
|
|
std::cout << boolean << " <=> " << true << " := " << to_string(boolean <=> true) << '\n'; // *NOPAD*
|
|
std::cout << number << " <=> " << 17.0 << " := " << to_string(number <=> 17.0) << '\n'; // *NOPAD*
|
|
std::cout << number << " <=> " << nan << " := " << to_string(number <=> nan) << '\n'; // *NOPAD*
|
|
std::cout << string << " <=> " << 17 << " := " << to_string(string <=> 17) << '\n'; // *NOPAD*
|
|
}
|