diff --git a/cpp/src/arrow/compare.cc b/cpp/src/arrow/compare.cc index 06f1d14e73a..735acb10869 100644 --- a/cpp/src/arrow/compare.cc +++ b/cpp/src/arrow/compare.cc @@ -57,6 +57,7 @@ #include "arrow/util/unreachable.h" #include "arrow/visit_scalar_inline.h" #include "arrow/visit_type_inline.h" +#include "arrow/csv/lexing_internal.h" namespace arrow { @@ -147,51 +148,26 @@ struct FloatingEquality { const int32_t ulp_distance; }; + template struct FloatingEqualityDispatcher { const EqualOptions& options; Visitor&& visit; - template - void DispatchL4() { - if (options.ulp_distance()) { - visit(FloatingEquality< - T, FloatingEqualityFlags>{ - options}); - } else { - visit(FloatingEquality< - T, FloatingEqualityFlags>{ - options}); - } - } - - template - void DispatchL3() { - if (options.signed_zeros_equal()) { - DispatchL4(); - } else { - DispatchL4(); - } - } - - template - void DispatchL2() { - if (options.nans_equal()) { - DispatchL3(); - } else { - DispatchL3(); - } - } - void Dispatch() { - if (options.atol()) { - DispatchL2(); - } else { - DispatchL2(); - } + csv::internal::DispatchBool( + [&]() { + visit(FloatingEquality< + T, FloatingEqualityFlags>{options}); + }, + options.atol().has_value(), options.nans_equal(), + options.signed_zeros_equal(), options.ulp_distance().has_value()); } }; + // Call `visit(equality_func)` where `equality_func` has the signature `bool(T, T)` // and returns true if the two values compare equal. template