JSON Voorhees
Killer JSON for C++
Loading...
Searching...
No Matches
jsonv::compare_traits Struct Reference

Traits describing how to perform various aspects of comparison. More...

#include <jsonv/algorithm.hpp>

Static Public Member Functions

static int compare_kinds (kind a, kind b)
 Compare two kinds a and b.
 
static int compare_booleans (bool a, bool b)
 Compare two boolean values.
 
static int compare_integers (std::int64_t a, std::int64_t b)
 Compare two integer values.
 
static int compare_integer_decimal (std::int64_t a, double b)
 Compare the integer a with the decimal b by their exact numeric values.
 
static int compare_decimals (double a, double b)
 Compare two decimal values exactly, without an epsilon tolerance.
 
static int compare_strings (const std::string &a, const std::string &b)
 Compare two string values.
 
static int compare_object_keys (const std::string &a, const std::string &b)
 Compare two strings used for the keys of objects.
 
static int compare_objects_meta (const value &, const value &)
 Compare two objects before comparing the values.
 

Detailed Description

Traits describing how to perform various aspects of comparison.

This implementation for comparison is strict and is ultimately the one used by value::compare.

See also
compare

Definition at line 38 of file algorithm.hpp.

Member Function Documentation

◆ compare_booleans()

static int jsonv::compare_traits::compare_booleans ( bool  a,
bool  b 
)
inlinestatic

Compare two boolean values.

Definition at line 54 of file algorithm.hpp.

◆ compare_decimals()

static int jsonv::compare_traits::compare_decimals ( double  a,
double  b 
)
inlinestatic

Compare two decimal values exactly, without an epsilon tolerance.

Signed zeros compare equal and infinities follow numeric order. All NaNs compare equal to each other and greater than every non-NaN number, regardless of sign or payload. This defines a strict weak ordering for decimals.

Definition at line 105 of file algorithm.hpp.

◆ compare_integer_decimal()

static int jsonv::compare_traits::compare_integer_decimal ( std::int64_t  a,
double  b 
)
inlinestatic

Compare the integer a with the decimal b by their exact numeric values.

a is never converted to double, which would round an integer past 2^53 onto a neighbor: 9007199254740993 is greater than the decimal 9007199254740992.0, not equal to it. An integer equals a decimal only when the decimal holds exactly that integer, so both signed zeros equal 0. Infinities follow numeric order and NaN is greater than every integer, as in compare_decimals. compare calls this for both operand orders, reversing the sign of the result when the decimal is on the left.

Definition at line 78 of file algorithm.hpp.

◆ compare_integers()

static int jsonv::compare_traits::compare_integers ( std::int64_t  a,
std::int64_t  b 
)
inlinestatic

Compare two integer values.

Definition at line 63 of file algorithm.hpp.

◆ compare_kinds()

static int jsonv::compare_traits::compare_kinds ( kind  a,
kind  b 
)
inlinestatic

Compare two kinds a and b.

This should return 0 if the types are the same or if they are directly comparable (such as kind::integer and kind::decimal) – if you return 0 for non-comparable types, you risk getting a kind_error thrown.

Definition at line 45 of file algorithm.hpp.

◆ compare_object_keys()

static int jsonv::compare_traits::compare_object_keys ( const std::string &  a,
const std::string &  b 
)
inlinestatic

Compare two strings used for the keys of objects.

Definition at line 125 of file algorithm.hpp.

◆ compare_objects_meta()

static int jsonv::compare_traits::compare_objects_meta ( const value &  ,
const value &   
)
inlinestatic

Compare two objects before comparing the values.

The compare function will only check the contents of an object if this function returns 0.

Definition at line 134 of file algorithm.hpp.

◆ compare_strings()

static int jsonv::compare_traits::compare_strings ( const std::string &  a,
const std::string &  b 
)
inlinestatic

Compare two string values.

Definition at line 118 of file algorithm.hpp.


The documentation for this struct was generated from the following file: