Skip to content

Commit

Permalink
apacheGH-39333: [C++] Don't use "if constexpr" in lambda
Browse files Browse the repository at this point in the history
It seems that it's not portable. At least it doesn't work as expected
with Visual Studio 2017:

    C:/arrow/cpp/src/arrow/array/array_nested.cc(291): error C2065: 'validity': undeclared identifier (compiling source file C:\arrow-build\src\arrow\CMakeFiles\arrow_shared.dir\Unity\unity_0_cxx.cxx) [C:\arrow-build\src\arrow\arrow_shared.vcxproj]
      C:/arrow/cpp/src/arrow/array/array_nested.cc(660): note: see reference to function template instantiation 'arrow::Result<std::shared_ptr<arrow::Array>> arrow::`anonymous-namespace'::FlattenListViewArray<arrow::ListViewArray,false>(const ListViewArrayT &,arrow::MemoryPool *)' being compiled
              with
              [
                  ListViewArrayT=arrow::ListViewArray
              ] (compiling source file C:\arrow-build\src\arrow\CMakeFiles\arrow_shared.dir\Unity\unity_0_cxx.cxx)
      memory_pool.cc
    C:/arrow/cpp/src/arrow/array/array_nested.cc(291): error C2065: 'list_view_array_offset': undeclared identifier (compiling source file C:\arrow-build\src\arrow\CMakeFiles\arrow_shared.dir\Unity\unity_0_cxx.cxx) [C:\arrow-build\src\arrow\arrow_shared.vcxproj]

Use "if constexpr" in outer lambda.
  • Loading branch information
kou committed Dec 21, 2023
1 parent 37616a8 commit 48321ef
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cpp/src/arrow/array/array_nested.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,17 @@ Result<std::shared_ptr<Array>> FlattenListViewArray(const ListViewArrayT& list_v
const auto* offsets = list_view_array.data()->template GetValues<offset_type>(1);
const auto* sizes = list_view_array.data()->template GetValues<offset_type>(2);

auto is_null_or_empty = [&](int64_t i) {
if constexpr (HasNulls) {
std::function<bool(int64_t)> 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;
Expand Down

0 comments on commit 48321ef

Please sign in to comment.