diff --git a/cpp/src/arrow/array/array_nested.cc b/cpp/src/arrow/array/array_nested.cc index 03f3e5af29908..fe1768bbbff2b 100644 --- a/cpp/src/arrow/array/array_nested.cc +++ b/cpp/src/arrow/array/array_nested.cc @@ -286,14 +286,17 @@ Result> FlattenListViewArray(const ListViewArrayT& list_v const auto* offsets = list_view_array.data()->template GetValues(1); const auto* sizes = list_view_array.data()->template GetValues(2); - auto is_null_or_empty = [&](int64_t i) { - if constexpr (HasNulls) { + std::function is_null_or_empty; + if constexpr (HasNulls) { + is_null_or_empty = [&](int64_t i) { if (!bit_util::GetBit(validity, list_view_array_offset + i)) { return true; } - } - return sizes[i] == 0; - }; + return sizes[i] == 0; + }; + } else { + is_null_or_empty = [&](int64_t i) { return sizes[i] == 0; }; + } // Index of the first valid, non-empty list-view. int64_t first_i = 0;