diff --git a/include/xlnt/utils/optional.hpp b/include/xlnt/utils/optional.hpp index 8677f24b..4f56c812 100644 --- a/include/xlnt/utils/optional.hpp +++ b/include/xlnt/utils/optional.hpp @@ -25,6 +25,7 @@ #include #include +#include #include namespace xlnt { @@ -49,6 +50,23 @@ class optional using set_move_noexcept_t = typename std::conditional{} && std::is_nothrow_move_assignable{}, std::true_type, std::false_type>::type; using clear_noexcept_t = typename std::conditional{}, std::true_type, std::false_type>::type; #endif + /// + /// Default equality operation, just uses operator== + /// + template >::type * = nullptr> + constexpr bool compare_equal(const T &lhs, const T &rhs) const + { + return lhs == rhs; + } + + /// + /// equality operation for floating point numbers. Provides "fuzzy" equality + /// + template >::type * = nullptr> + constexpr bool compare_equal(const T &lhs, const T &rhs) const + { + return detail::float_equals(lhs, rhs); + } public: /// @@ -281,7 +299,8 @@ public: { return true; } - return value_ref() == other.value_ref(); + // equality is overloaded to provide fuzzy equality when T is a fp number + return compare_equal(value_ref(), other.value_ref()); } ///