Skip to content

Commit 07b0f12

Browse files
committed
Use explicit struct
1 parent a6be8b4 commit 07b0f12

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

cpp/src/arrow/util/dispatch_internal.h

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,15 @@ enum class DispatchLevel : int {
3838
MAX
3939
};
4040

41-
/// A pair of function dispatch level and
41+
/// A dispatch target pairing a dispatch level with a function pointer.
4242
template <typename Func>
43-
using DynamicDispatchTarget = std::pair<DispatchLevel, Func>;
43+
struct DynamicDispatchTarget {
44+
DispatchLevel level = DispatchLevel::NONE;
45+
Func func = {};
46+
};
47+
48+
template <typename Func>
49+
DynamicDispatchTarget(DispatchLevel, Func) -> DynamicDispatchTarget<Func>;
4450

4551
namespace detail {
4652

@@ -87,7 +93,7 @@ constexpr bool DispatchIsStatic(DispatchLevel level) {
8793
template <typename Func>
8894
constexpr bool DispatchFullyStatic(const DynamicDispatchTargets<Func> auto& targets) {
8995
return std::ranges::all_of(targets, [](const DynamicDispatchTarget<Func>& trgt) {
90-
return DispatchIsStatic(trgt.first);
96+
return DispatchIsStatic(trgt.level);
9197
});
9298
}
9399

@@ -96,7 +102,7 @@ constexpr bool DispatchFullyStatic(const DynamicDispatchTargets<Func> auto& targ
96102
template <typename Func>
97103
constexpr bool DispatchHasStatic(const DynamicDispatchTargets<Func> auto& targets) {
98104
return std::ranges::any_of(targets, [](const DynamicDispatchTarget<Func>& trgt) {
99-
return DispatchIsStatic(trgt.first);
105+
return DispatchIsStatic(trgt.level);
100106
});
101107
}
102108

@@ -106,7 +112,7 @@ constexpr DynamicDispatchTarget<Func> BestDispatchTarget(
106112
const DynamicDispatchTargets<Func> auto& targets, Filter filter) {
107113
DynamicDispatchTarget<Func> best = {};
108114
for (const auto& trgt : targets) {
109-
if (trgt.first >= best.first && filter(trgt)) {
115+
if (trgt.level >= best.level && filter(trgt)) {
110116
best = trgt;
111117
}
112118
}
@@ -199,7 +205,7 @@ concept DynamicDispatchFullyStaticSpec =
199205
struct MyDynamicFunction {
200206
using FunctionType = decltype(&my_function_default);
201207
202-
static std::array<std::pair<DispatchLevel, FunctionType>, N> implementations() {
208+
static std::array<DynamicDispatchTarget<FunctionType>, N> implementations() {
203209
return {
204210
{ DispatchLevel::NONE, my_function_default }
205211
#if defined(ARROW_HAVE_RUNTIME_AVX2)
@@ -266,8 +272,8 @@ class DynamicDispatch {
266272

267273
DynamicDispatch() {
268274
const auto best = BestDispatchTarget<FunctionType>(
269-
kTargets, [this](const Target& trgt) { return IsSupported(trgt.first); });
270-
func = best.second;
275+
kTargets, [this](const Target& trgt) { return IsSupported(trgt.level); });
276+
func = best.func;
271277
}
272278

273279
template <typename... Args>
@@ -304,7 +310,7 @@ class DynamicDispatch<DynamicFunction> {
304310
using FunctionType = typename DynamicFunction::FunctionType;
305311
using Target = DynamicDispatchTarget<FunctionType>;
306312
static constexpr auto kTargets = DynamicFunction::implementations();
307-
static constexpr FunctionType kBest = BestDispatchTarget<FunctionType>(kTargets).second;
313+
static constexpr FunctionType kBest = BestDispatchTarget<FunctionType>(kTargets).func;
308314

309315
template <typename... Args>
310316
auto operator()(Args&&... args) const -> decltype(auto) {

0 commit comments

Comments
 (0)