#ifndef COMPARE_INL_H_ #error "Direct inclusion of this file is not allowed, include compare.h" // For the sake of sane code completion. #include "compare.h" #endif #include "numeric_helpers.h" #include #include #include namespace NYT { //////////////////////////////////////////////////////////////////////////////// template Y_FORCE_INLINE int TernaryCompare(const T& lhs, const T& rhs) { if (lhs == rhs) { return 0; } else if (lhs < rhs) { return -1; } else { return +1; } } //! An optimized version for string types. template requires std::is_same_v || std::is_same_v || std::is_same_v || std::is_same_v Y_FORCE_INLINE int TernaryCompare(const T& lhs, const T& rhs) { return GetSign(std::string_view(lhs).compare(std::string_view(rhs))); } template Y_FORCE_INLINE int NaNSafeTernaryCompare(const T& lhs, const T& rhs) { return TernaryCompare(lhs, rhs); } template requires std::is_floating_point_v Y_FORCE_INLINE int NaNSafeTernaryCompare(const T& lhs, const T& rhs) { if (lhs < rhs) { return -1; } else if (lhs > rhs) { return +1; } else if (std::isnan(lhs)) { if (std::isnan(rhs)) { return 0; } else { return +1; } } else if (std::isnan(rhs)) { return -1; } else { return 0; } } //////////////////////////////////////////////////////////////////////////////// } // namespace NYT