TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ operator< [1/3]

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
bool operator< ( const_reference  lhs,
const_reference  rhs 
)
friend

comparison: less than

Compares whether one JSON value lhs is less than another JSON value rhs according to the following rules:

  • If lhs and 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 lhs and rhs have different types, the values are ignored and the order of the types is considered, see operator<(const value_t, const value_t).
Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether lhs is less than rhs

@complexity Linear.

@exceptionsafety No-throw guarantee: this function never throws exceptions.

@liveexample{The example demonstrates comparing several JSON types.,operator__less}

Since
version 1.0.0

Definition at line 24235 of file json.hpp.

24236 {
24237 const auto lhs_type = lhs.type();
24238 const auto rhs_type = rhs.type();
24239
24240 if (lhs_type == rhs_type)
24241 {
24242 switch (lhs_type)
24243 {
24244 case value_t::array:
24245 // note parentheses are necessary, see
24246 // https://github.com/nlohmann/json/issues/1530
24247 return (*lhs.m_value.array) < (*rhs.m_value.array);
24248
24249 case value_t::object:
24250 return (*lhs.m_value.object) < (*rhs.m_value.object);
24251
24252 case value_t::null:
24253 return false;
24254
24255 case value_t::string:
24256 return (*lhs.m_value.string) < (*rhs.m_value.string);
24257
24258 case value_t::boolean:
24259 return (lhs.m_value.boolean) < (rhs.m_value.boolean);
24260
24262 return (lhs.m_value.number_integer) < (rhs.m_value.number_integer);
24263
24265 return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned);
24266
24268 return (lhs.m_value.number_float) < (rhs.m_value.number_float);
24269
24270 case value_t::binary:
24271 return (*lhs.m_value.binary) < (*rhs.m_value.binary);
24272
24273 case value_t::discarded:
24274 default:
24275 return false;
24276 }
24277 }
24278
24279 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
24280 {
24281 return static_cast<number_float_t>(lhs.m_value.number_integer) < rhs.m_value.number_float;
24282 }
24283
24284 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
24285 {
24286 return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_integer);
24287 }
24288
24289 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
24290 {
24291 return static_cast<number_float_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_float;
24292 }
24293
24294 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
24295 {
24296 return lhs.m_value.number_float < static_cast<number_float_t>(rhs.m_value.number_unsigned);
24297 }
24298
24299 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
24300 {
24301 return lhs.m_value.number_integer < static_cast<number_integer_t>(rhs.m_value.number_unsigned);
24302 }
24303
24304 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
24305 {
24306 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) < rhs.m_value.number_integer;
24307 }
24308
24309 // We only reach this line if we cannot compare values. In that case,
24310 // we compare types. Note we have to call the operator explicitly,
24311 // because MSVC has problems otherwise.
24312 return operator<(lhs_type, rhs_type);
24313 }
NumberIntegerType number_integer_t
a type for a number (integer)
Definition: json.hpp:18390
NumberFloatType number_float_t
a type for a number (floating-point)
Definition: json.hpp:18529
friend bool operator<(const_reference lhs, const_reference rhs) noexcept
comparison: less than
Definition: json.hpp:24235
@ number_integer
number value (signed integer)
@ discarded
discarded by the parser callback function
@ binary
binary array (ordered collection of bytes)
@ object
object (unordered set of name/value pairs)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)