MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / operator<

Function operator<

3rd/nlohmann_json/include/nlohmann/json.hpp:6531–6603  ·  view source on GitHub ↗

! @brief comparison: less than Compares whether one JSON value @a lhs is less than another JSON value @a rhs according to the following rules: - If @a lhs and @a rhs have the same type, the values are compared using the default `<` operator. - Integer and floating-point numbers are automatically converted before comparison - In case @a lhs and @a rhs have diffe

Source from the content-addressed store, hash-verified

6529 @since version 1.0.0
6530 */
6531 friend bool operator<(const_reference lhs, const_reference rhs) noexcept
6532 {
6533 const auto lhs_type = lhs.type();
6534 const auto rhs_type = rhs.type();
6535
6536 if (lhs_type == rhs_type)
6537 {
6538 switch (lhs_type)
6539 {
6540 case value_t::array:
6541 // note parentheses are necessary, see
6542 // https://github.com/nlohmann/json/issues/1530
6543 return (*lhs.m_value.array) < (*rhs.m_value.array);
6544
6545 case value_t::object:
6546 return (*lhs.m_value.object) < (*rhs.m_value.object);
6547
6548 case value_t::null:
6549 return false;
6550
6551 case value_t::string:
6552 return (*lhs.m_value.string) < (*rhs.m_value.string);
6553
6554 case value_t::boolean:
6555 return (lhs.m_value.boolean) < (rhs.m_value.boolean);
6556
6557 case value_t::number_integer:
6558 return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
6559
6560 case value_t::number_unsigned:
6561 return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
6562
6563 case value_t::number_float:
6564 return (lhs.m_value.number_float) < (rhs.m_value.number_float);
6565
6566 case value_t::binary:
6567 return (*lhs.m_value.binary) < (*rhs.m_value.binary);
6568
6569 case value_t::discarded:
6570 default:
6571 return false;
6572 }
6573 }
6574 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
6575 {
6576 return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
6577 }
6578 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
6579 {
6580 return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_integer);
6581 }
6582 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
6583 {
6584 return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
6585 }
6586 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
6587 {
6588 return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_unsigned);

Callers 1

operator()Method · 0.70

Calls 1

basic_jsonFunction · 0.70

Tested by

no test coverage detected