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: equal

Compares two JSON values for equality according to the following rules:

  • Two JSON values are equal if (1) they are from the same type and (2) their stored values are the same according to their respective operator==.
  • Integer and floating-point numbers are automatically converted before comparison. Note that two NaN values are always treated as unequal.
  • Two JSON null values are equal.
Note
Floating-point inside JSON values numbers are compared with json::number_float_t::operator== which is double::operator== by default. To compare floating-point while respecting an epsilon, an alternative comparison function could be used, for instance
template<typename T, typename = typename std::enable_if<std::is_floating_point<T>::value, T>::type>
inline bool is_same(T a, T b, T epsilon = std::numeric_limits<T>::epsilon()) noexcept
{
return std::abs(a - b) <= epsilon;
}
constexpr value_t type() const noexcept
return the type of the JSON value (explicit)
Definition: json.hpp:20171
Or you can self-defined operator equal function like this:
bool my_equal(const_reference lhs, const_reference rhs) {
const auto lhs_type lhs.type();
const auto rhs_type rhs.type();
if (lhs_type == rhs_type) {
switch(lhs_type)
// self_defined case
return std::abs(lhs - rhs) <= std::numeric_limits<float>::epsilon();
// other cases remain the same with the original
...
}
...
}
const value_type & const_reference
the type of an element const reference
Definition: json.hpp:17975
@ number_float
number value (floating-point)
NaN values never compare equal to themselves or to other NaN values.
Parameters
[in]lhsfirst JSON value to consider
[in]rhssecond JSON value to consider
Returns
whether the values lhs and rhs are equal

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

@complexity Linear.

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

Since
version 1.0.0

Definition at line 24060 of file json.hpp.

24061 {
24062#ifdef __GNUC__
24063#pragma GCC diagnostic push
24064#pragma GCC diagnostic ignored "-Wfloat-equal"
24065#endif
24066 const auto lhs_type = lhs.type();
24067 const auto rhs_type = rhs.type();
24068
24069 if (lhs_type == rhs_type)
24070 {
24071 switch (lhs_type)
24072 {
24073 case value_t::array:
24074 return *lhs.m_value.array == *rhs.m_value.array;
24075
24076 case value_t::object:
24077 return *lhs.m_value.object == *rhs.m_value.object;
24078
24079 case value_t::null:
24080 return true;
24081
24082 case value_t::string:
24083 return *lhs.m_value.string == *rhs.m_value.string;
24084
24085 case value_t::boolean:
24086 return lhs.m_value.boolean == rhs.m_value.boolean;
24087
24089 return lhs.m_value.number_integer == rhs.m_value.number_integer;
24090
24092 return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned;
24093
24095 return lhs.m_value.number_float == rhs.m_value.number_float;
24096
24097 case value_t::binary:
24098 return *lhs.m_value.binary == *rhs.m_value.binary;
24099
24100 case value_t::discarded:
24101 default:
24102 return false;
24103 }
24104 }
24105
24106 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float)
24107 {
24108 return static_cast<number_float_t>(lhs.m_value.number_integer) == rhs.m_value.number_float;
24109 }
24110
24111 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer)
24112 {
24113 return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_integer);
24114 }
24115
24116 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float)
24117 {
24118 return static_cast<number_float_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_float;
24119 }
24120
24121 else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned)
24122 {
24123 return lhs.m_value.number_float == static_cast<number_float_t>(rhs.m_value.number_unsigned);
24124 }
24125
24126 else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer)
24127 {
24128 return static_cast<number_integer_t>(lhs.m_value.number_unsigned) == rhs.m_value.number_integer;
24129 }
24130
24131 else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned)
24132 {
24133 return lhs.m_value.number_integer == static_cast<number_integer_t>(rhs.m_value.number_unsigned);
24134 }
24135
24136 return false;
24137#ifdef __GNUC__
24138#pragma GCC diagnostic pop
24139#endif
24140 }
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
@ 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_unsigned
number value (unsigned integer)
@ array
array (ordered collection of values)