Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions cpp/src/arrow/compute/kernels/codegen_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#pragma once

#include <concepts>
#include <cstdint>
#include <cstring>
#include <memory>
Expand Down Expand Up @@ -1234,9 +1233,12 @@ struct GeneratorApplicator<Generator, Arg1, WithFirstTypeTwice, Args...> {
using Type = GeneratorApplicator<Generator, Arg1, Arg1, Args...>::Type;
};

// std::is_invocable_v is used instead of the std::invocable concept because some
// older standard library implementations (e.g., macOS 11.x libc++, used by CRAN)
// have partial C++20 concepts support and lack std::invocable.
template <auto Transform, auto TypeIdArray, size_t ArrayIndex,
template <typename...> class Generator, typename... Args>
requires std::invocable<decltype(Transform), Type::type>
requires std::is_invocable_v<decltype(Transform), Type::type>
auto GenerateKernelExecImpl(Type::type id) {
constexpr auto kNumTypeIds = std::tuple_size_v<decltype(TypeIdArray)>;
static_assert(ArrayIndex < kNumTypeIds);
Expand Down Expand Up @@ -1272,7 +1274,7 @@ auto GenerateKernelExecImpl(Type::type id) {

template <auto Transform, auto TypeIdArray, template <typename...> class Generator,
typename... Args>
requires std::invocable<decltype(Transform), Type::type>
requires std::is_invocable_v<decltype(Transform), Type::type>
auto GenerateKernelExec(detail::GetTypeId get_id) {
return detail::GenerateKernelExecImpl<Transform, TypeIdArray, /*ArrayIndex=*/0,
Generator, Args...>(get_id.id);
Expand Down
25 changes: 22 additions & 3 deletions cpp/src/parquet/column_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,29 @@ inline void CheckNumberDecoded(int64_t number_decoded, int64_t expected) {
}
}

/// True if a T can hold a U.
/// True if an integer type T can hold every value of integer type U.
///
/// Written in terms of std::numeric_limits rather than std::in_range because
/// the libc++ in the macOS 11.3 SDK used by CRAN does not provide the latter.
template <typename T, typename U>
struct CanHold {
static_assert(std::is_integral_v<T> && std::is_integral_v<U>,
"can_hold_v is only defined for integer types");
static constexpr bool value =
std::numeric_limits<T>::digits >= std::numeric_limits<U>::digits &&
(std::is_signed_v<T> || !std::is_signed_v<U>);
};

template <typename T, typename U>
inline constexpr bool can_hold_v = std::in_range<T>(std::numeric_limits<U>::min()) &&
std::in_range<T>(std::numeric_limits<U>::max());
inline constexpr bool can_hold_v = CanHold<T, U>::value;

static_assert(can_hold_v<int64_t, int32_t>);
static_assert(can_hold_v<int64_t, uint32_t>);
static_assert(can_hold_v<int32_t, int32_t>);
static_assert(!can_hold_v<int32_t, int64_t>);
static_assert(!can_hold_v<int32_t, uint32_t>);
Comment thread
thisisnic marked this conversation as resolved.
Resolved
static_assert(!can_hold_v<uint32_t, int32_t>);
static_assert(!can_hold_v<uint64_t, int32_t>);

/// Clamp to a given type.
template <typename T, typename U>
Expand Down
Loading