! @brief comparison operator for JSON types Returns an ordering that is similar to Python: - order: null < boolean < number < object < array < string < binary - furthermore, each type is not smaller than itself - discarded values are not comparable - binary is represented as a b"" string in python and directly comparable to a string; however, making a binary array directly comparable with a str
| 3469 | @since version 1.0.0 |
| 3470 | */ |
| 3471 | inline bool operator<(const value_t lhs, const value_t rhs) noexcept |
| 3472 | { |
| 3473 | static constexpr std::array<std::uint8_t, 9> order = {{ |
| 3474 | 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, |
| 3475 | 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */, |
| 3476 | 6 /* binary */ |
| 3477 | } |
| 3478 | }; |
| 3479 | |
| 3480 | const auto l_index = static_cast<std::size_t>(lhs); |
| 3481 | const auto r_index = static_cast<std::size_t>(rhs); |
| 3482 | return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index]; |
| 3483 | } |
| 3484 | } // namespace detail |
| 3485 | } // namespace nlohmann |
| 3486 |
no test coverage detected