@@ -777,6 +777,61 @@ bool operator!=(Json::const_reference json1, Json::const_reference json2)
777
777
return !(json1 == json2);
778
778
}
779
779
780
+ // ==================================================================================================
781
+ bool operator <(Json::const_reference json1, Json::const_reference json2)
782
+ {
783
+ auto visitor = [&json1, &json2](const auto &value1, const auto &value2) -> bool
784
+ {
785
+ using S1 = decltype (value1);
786
+ using S2 = decltype (value2);
787
+
788
+ if constexpr (JsonNull<S1> && JsonNull<S2>)
789
+ {
790
+ return false ;
791
+ }
792
+ else if constexpr (
793
+ (JsonFloatingPoint<S1> && JsonNumber<S2>) || (JsonFloatingPoint<S2> && JsonNumber<S1>))
794
+ {
795
+ const auto fvalue1 = static_cast <json_floating_point_type>(value1);
796
+ const auto fvalue2 = static_cast <json_floating_point_type>(value2);
797
+
798
+ return fvalue1 < fvalue2;
799
+ }
800
+ else if constexpr (JsonNumber<S1> && JsonNumber<S2>)
801
+ {
802
+ return value1 < static_cast <S1>(value2);
803
+ }
804
+ else if constexpr (fly::SameAsAny<S1, S2>)
805
+ {
806
+ return value1 < value2;
807
+ }
808
+ else
809
+ {
810
+ return json1.m_value .index () < json2.m_value .index ();
811
+ }
812
+ };
813
+
814
+ return std::visit (std::move (visitor), json1.m_value , json2.m_value );
815
+ }
816
+
817
+ // ==================================================================================================
818
+ bool operator <=(Json::const_reference json1, Json::const_reference json2)
819
+ {
820
+ return !(json2 < json1);
821
+ }
822
+
823
+ // ==================================================================================================
824
+ bool operator >(Json::const_reference json1, Json::const_reference json2)
825
+ {
826
+ return !(json1 <= json2);
827
+ }
828
+
829
+ // ==================================================================================================
830
+ bool operator >=(Json::const_reference json1, Json::const_reference json2)
831
+ {
832
+ return !(json1 < json2);
833
+ }
834
+
780
835
// ==================================================================================================
781
836
json_string_type Json::validate_string (json_string_type &&value)
782
837
{
0 commit comments