Skip to content
Open
3 changes: 2 additions & 1 deletion cpp/src/arrow/acero/asof_join_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ typedef uint64_t row_index_t;
typedef int col_index_t;

// indicates normalization of a key value
template <typename T, enable_if_t<std::is_integral<T>::value, bool> = true>
template <typename T>
requires std::is_integral_v<T>
static inline uint64_t key_value(T t) {
return static_cast<uint64_t>(t);
}
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/arrow/acero/time_series_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

namespace arrow::acero {

template <typename T, enable_if_t<std::is_integral<T>::value, bool>>
template <typename T>
requires std::is_integral_v<T>
inline uint64_t NormalizeTime(T t) {
uint64_t bias =
std::is_signed<T>::value ? static_cast<uint64_t>(1) << (8 * sizeof(T) - 1) : 0;
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/arrow/acero/time_series_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
namespace arrow::acero {

// normalize the value to unsigned 64-bits while preserving ordering of values
template <typename T, enable_if_t<std::is_integral<T>::value, bool> = true>
template <typename T>
requires std::is_integral_v<T>
uint64_t NormalizeTime(T t);

uint64_t GetTime(const RecordBatch* batch, Type::type time_type, int col, uint64_t row);
Expand Down
17 changes: 9 additions & 8 deletions cpp/src/arrow/acero/unmaterialized_table_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ class UnmaterializedCompositeTable {
}

template <class Type, class Builder = typename TypeTraits<Type>::BuilderType>
enable_if_boolean<Type, Status> static BuilderAppend(
Builder& builder, const std::shared_ptr<ArrayData>& source, uint64_t row) {
requires arrow_boolean<Type>
static Status BuilderAppend(Builder& builder, const std::shared_ptr<ArrayData>& source,
uint64_t row) {
if (source->IsNull(row)) {
builder.UnsafeAppendNull();
return Status::OK();
Expand All @@ -177,10 +178,9 @@ class UnmaterializedCompositeTable {
}

template <class Type, class Builder = typename TypeTraits<Type>::BuilderType>
enable_if_t<is_fixed_width_type<Type>::value && !is_boolean_type<Type>::value,
Status> static BuilderAppend(Builder& builder,
const std::shared_ptr<ArrayData>& source,
uint64_t row) {
requires(arrow_fixed_width<Type> && !arrow_boolean<Type>)
static Status BuilderAppend(Builder& builder, const std::shared_ptr<ArrayData>& source,
uint64_t row) {
if (source->IsNull(row)) {
builder.UnsafeAppendNull();
return Status::OK();
Expand All @@ -191,8 +191,9 @@ class UnmaterializedCompositeTable {
}

template <class Type, class Builder = typename TypeTraits<Type>::BuilderType>
enable_if_base_binary<Type, Status> static BuilderAppend(
Builder& builder, const std::shared_ptr<ArrayData>& source, uint64_t row) {
requires arrow_base_binary<Type>
static Status BuilderAppend(Builder& builder, const std::shared_ptr<ArrayData>& source,
uint64_t row) {
if (source->IsNull(row)) {
return builder.AppendNull();
}
Expand Down
12 changes: 4 additions & 8 deletions cpp/src/arrow/adapters/orc/util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -488,21 +488,17 @@ Result<std::shared_ptr<Array>> NormalizeArray(const std::shared_ptr<Array>& arra
}
}

template <class DataType, class BatchType, typename Enable = void>
template <class DataType, class BatchType>
struct Appender {};

// Types for long/double-like Appender, that is, numeric, boolean or date32
template <typename T>
using is_generic_type =
std::integral_constant<bool, is_number_type<T>::value ||
std::is_same<Date32Type, T>::value ||
is_boolean_type<T>::value>;
template <typename T, typename R = void>
using enable_if_generic = enable_if_t<is_generic_type<T>::value, R>;
concept generic_type = arrow_number<T> || std::same_as<Date32Type, T> || arrow_boolean<T>;

// Number-like
template <class DataType, class BatchType>
struct Appender<DataType, BatchType, enable_if_generic<DataType>> {
requires generic_type<DataType>
struct Appender<DataType, BatchType> {
using ArrayType = typename TypeTraits<DataType>::ArrayType;
using ValueType = typename TypeTraits<DataType>::CType;
Status VisitNull() {
Expand Down
9 changes: 6 additions & 3 deletions cpp/src/arrow/array/array_dict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ struct CompactTransposeMapVisitor {
}

template <typename Type>
enable_if_integer<Type, Status> Visit(const Type&) {
requires arrow_integer<Type>
Status Visit(const Type&) {
return CompactTransposeMapImpl<Type>();
}

Expand Down Expand Up @@ -435,14 +436,16 @@ struct MakeUnifier {
: pool(pool), value_type(std::move(value_type)) {}

template <typename T>
enable_if_no_memoize<T, Status> Visit(const T&) {
requires dictionary_has_no_memo_table<T>
Status Visit(const T&) {
// Default implementation for non-dictionary-supported datatypes
return Status::NotImplemented("Unification of ", *value_type,
" dictionaries is not implemented");
}

template <typename T>
enable_if_memoize<T, Status> Visit(const T&) {
requires dictionary_has_memo_table<T>
Status Visit(const T&) {
result.reset(new DictionaryUnifierImpl<T>(pool, value_type));
return Status::OK();
}
Expand Down
9 changes: 6 additions & 3 deletions cpp/src/arrow/array/array_list_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ class TestListArray : public ::testing::Test {
}

template <bool IsList = !kTypeClassIsListView>
std::enable_if_t<IsList, void> TestFromArraysWithSlicedOffsets() {
requires IsList
void TestFromArraysWithSlicedOffsets() {
std::vector<offset_type> offsets = {-1, -1, 0, 1, 2, 4};

std::shared_ptr<Array> offsets_wo_nulls;
Expand All @@ -356,7 +357,8 @@ class TestListArray : public ::testing::Test {
}

template <bool IsList = !kTypeClassIsListView>
std::enable_if_t<IsList, void> TestFromArraysWithSlicedNullOffsets() {
requires IsList
void TestFromArraysWithSlicedNullOffsets() {
std::vector<offset_type> offsets = {-1, -1, 0, 1, 1, 3};
std::vector<bool> offsets_w_nulls_is_valid = {true, true, true, false, true, true};

Expand Down Expand Up @@ -479,7 +481,8 @@ class TestListArray : public ::testing::Test {
}

template <bool IsListView = kTypeClassIsListView>
std::enable_if_t<IsListView, void> DoTestListViewFromArrays() {
requires IsListView
void DoTestListViewFromArrays() {
std::shared_ptr<Array> offsets1, offsets2;
std::shared_ptr<Array> sizes1, sizes2, sizes3, sizes4, sizes5;
std::shared_ptr<Array> values;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/arrow/array/array_primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ class NumericArray : public PrimitiveArray {
// Only enable this constructor without a type argument for types without additional
// metadata
template <typename T1 = TYPE>
NumericArray(enable_if_parameter_free<T1, int64_t> length,
const std::shared_ptr<Buffer>& data,
requires arrow_parameter_free<T1>
NumericArray(int64_t length, const std::shared_ptr<Buffer>& data,
const std::shared_ptr<Buffer>& null_bitmap = NULLPTR,
int64_t null_count = kUnknownNullCount, int64_t offset = 0) {
NumericArray::SetData(ArrayData::Make(TypeTraits<T1>::type_singleton(), length,
Expand Down
3 changes: 2 additions & 1 deletion cpp/src/arrow/array/array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,8 @@ class TestPrimitiveBuilder : public TestBuilder {

/// \brief uint8_t isn't a valid template parameter to uniform_int_distribution, so
/// we use SampleType to determine which kind of integer to use to sample.
template <typename T, typename = enable_if_t<std::is_integral<T>::value, T>>
template <typename T>
requires std::is_integral_v<T>
struct UniformIntSampleType {
using type = T;
};
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/arrow/array/builder_adaptive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ Status AdaptiveIntBuilderBase::Resize(int64_t capacity) {
}

template <typename new_type, typename old_type>
typename std::enable_if<sizeof(old_type) >= sizeof(new_type), Status>::type
AdaptiveIntBuilderBase::ExpandIntSizeInternal() {
requires(sizeof(old_type) >= sizeof(new_type))
Status AdaptiveIntBuilderBase::ExpandIntSizeInternal() {
return Status::OK();
}

template <typename new_type, typename old_type>
typename std::enable_if<(sizeof(old_type) < sizeof(new_type)), Status>::type
AdaptiveIntBuilderBase::ExpandIntSizeInternal() {
requires(sizeof(old_type) < sizeof(new_type))
Status AdaptiveIntBuilderBase::ExpandIntSizeInternal() {
int_size_ = sizeof(new_type);
RETURN_NOT_OK(Resize(data_->size() / sizeof(old_type)));

Expand Down
8 changes: 4 additions & 4 deletions cpp/src/arrow/array/builder_adaptive.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ class ARROW_EXPORT AdaptiveIntBuilderBase : public ArrayBuilder {
virtual Status CommitPendingData() = 0;

template <typename new_type, typename old_type>
typename std::enable_if<sizeof(old_type) >= sizeof(new_type), Status>::type
ExpandIntSizeInternal();
requires(sizeof(old_type) >= sizeof(new_type))
Status ExpandIntSizeInternal();
template <typename new_type, typename old_type>
typename std::enable_if<(sizeof(old_type) < sizeof(new_type)), Status>::type
ExpandIntSizeInternal();
requires(sizeof(old_type) < sizeof(new_type))
Status ExpandIntSizeInternal();

std::shared_ptr<ResizableBuffer> data_;
uint8_t* raw_data_ = NULLPTR;
Expand Down
10 changes: 6 additions & 4 deletions cpp/src/arrow/array/builder_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ struct AppendScalarImpl {
}

template <typename T>
enable_if_t<has_c_type<T>::value, Status> Visit(const T& t) {
requires arrow_has_c_type<T>
Status Visit(const T& t) {
return HandleFixedWidth(t);
}

Expand All @@ -125,7 +126,8 @@ struct AppendScalarImpl {
Status Visit(const Decimal256Type& t) { return HandleFixedWidth(t); }

template <typename T>
enable_if_has_string_view<T, Status> Visit(const T&) {
requires arrow_has_string_view<T>
Status Visit(const T&) {
int64_t data_size = 0;
for (auto it = scalars_begin_; it != scalars_end_; ++it) {
const auto& scalar = checked_cast<const typename TypeTraits<T>::ScalarType&>(*it);
Expand All @@ -152,8 +154,8 @@ struct AppendScalarImpl {
}

template <typename T>
enable_if_t<is_list_view_type<T>::value || is_list_like_type<T>::value, Status> Visit(
const T&) {
requires(arrow_list_view<T> || arrow_list_like<T>)
Status Visit(const T&) {
auto builder = checked_cast<typename TypeTraits<T>::BuilderType*>(builder_);
int64_t num_children = 0;
for (auto it = scalars_begin_; it != scalars_end_; ++it) {
Expand Down
18 changes: 12 additions & 6 deletions cpp/src/arrow/array/builder_dict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ class DictionaryMemoTable::DictionaryMemoTableImpl {
std::unique_ptr<MemoTable>* memo_table_;

template <typename T>
enable_if_no_memoize<T, Status> Visit(const T&) {
requires dictionary_has_no_memo_table<T>
Status Visit(const T&) {
return Status::NotImplemented("Initialization of ", value_type_->ToString(),
" memo table is not implemented");
}

template <typename T>
enable_if_memoize<T, Status> Visit(const T&) {
requires dictionary_has_memo_table<T>
Status Visit(const T&) {
using MemoTable = typename DictionaryTraits<T>::MemoTableType;
memo_table_->reset(new MemoTable(pool_, 0));
return Status::OK();
Expand All @@ -70,13 +72,15 @@ class DictionaryMemoTable::DictionaryMemoTableImpl {

private:
template <typename T, typename ArrayType>
enable_if_no_memoize<T, Status> InsertValues(const T& type, const ArrayType&) {
requires dictionary_has_no_memo_table<T>
Status InsertValues(const T& type, const ArrayType&) {
return Status::NotImplemented("Inserting array values of ", type,
" is not implemented");
}

template <typename T, typename ArrayType>
enable_if_memoize<T, Status> InsertValues(const T&, const ArrayType& array) {
requires dictionary_has_memo_table<T>
Status InsertValues(const T&, const ArrayType& array) {
if (array.null_count() > 0) {
return Status::Invalid("Cannot insert dictionary values containing nulls");
}
Expand All @@ -97,13 +101,15 @@ class DictionaryMemoTable::DictionaryMemoTableImpl {
std::shared_ptr<ArrayData>* out_;

template <typename T>
enable_if_no_memoize<T, Status> Visit(const T&) {
requires dictionary_has_no_memo_table<T>
Status Visit(const T&) {
return Status::NotImplemented("Getting array data of ", value_type_,
" is not implemented");
}

template <typename T>
enable_if_memoize<T, Status> Visit(const T&) {
requires dictionary_has_memo_table<T>
Status Visit(const T&) {
using ConcreteMemoTable = typename DictionaryTraits<T>::MemoTableType;
auto memo_table = checked_cast<ConcreteMemoTable*>(memo_table_);
ARROW_ASSIGN_OR_RAISE(*out_, DictionaryTraits<T>::GetDictionaryArrayData(
Expand Down
Loading