Skip to content
Open
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
26 changes: 15 additions & 11 deletions cpp/src/arrow/array/builder_primitive.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class NumericBuilder
using ArrayType = typename TypeTraits<T>::ArrayType;

template <typename T1 = T>
explicit NumericBuilder(
enable_if_parameter_free<T1, MemoryPool*> pool = default_memory_pool(),
int64_t alignment = kDefaultBufferAlignment)
requires arrow_parameter_free<T1>
explicit NumericBuilder(MemoryPool* pool = default_memory_pool(),
int64_t alignment = kDefaultBufferAlignment)
: ArrayBuilder(pool, alignment),
type_(TypeTraits<T>::type_singleton()),
data_builder_(pool, alignment) {}
Expand Down Expand Up @@ -268,8 +268,9 @@ class NumericBuilder
/// or null(0) values.
/// \return Status
template <typename ValuesIter, typename ValidIter>
enable_if_t<!std::is_pointer<ValidIter>::value, Status> AppendValues(
ValuesIter values_begin, ValuesIter values_end, ValidIter valid_begin) {
requires(!std::is_pointer_v<ValidIter>)
Status AppendValues(ValuesIter values_begin, ValuesIter values_end,
ValidIter valid_begin) {
static_assert(!internal::is_null_pointer<ValidIter>::value,
"Don't pass a NULLPTR directly as valid_begin, use the 2-argument "
"version instead");
Expand All @@ -285,8 +286,9 @@ class NumericBuilder

// Same as above, with a pointer type ValidIter
template <typename ValuesIter, typename ValidIter>
enable_if_t<std::is_pointer<ValidIter>::value, Status> AppendValues(
ValuesIter values_begin, ValuesIter values_end, ValidIter valid_begin) {
requires std::is_pointer_v<ValidIter>
Status AppendValues(ValuesIter values_begin, ValuesIter values_end,
ValidIter valid_begin) {
int64_t length = static_cast<int64_t>(std::distance(values_begin, values_end));
ARROW_RETURN_NOT_OK(Reserve(length));
data_builder_.UnsafeAppend(values_begin, values_end);
Expand Down Expand Up @@ -624,8 +626,9 @@ class ARROW_EXPORT BooleanBuilder
/// or null(0) values
/// \return Status
template <typename ValuesIter, typename ValidIter>
enable_if_t<!std::is_pointer<ValidIter>::value, Status> AppendValues(
ValuesIter values_begin, ValuesIter values_end, ValidIter valid_begin) {
requires(!std::is_pointer_v<ValidIter>)
Status AppendValues(ValuesIter values_begin, ValuesIter values_end,
ValidIter valid_begin) {
static_assert(!internal::is_null_pointer<ValidIter>::value,
"Don't pass a NULLPTR directly as valid_begin, use the 2-argument "
"version instead");
Expand All @@ -643,8 +646,9 @@ class ARROW_EXPORT BooleanBuilder

// Same as above, for a pointer type ValidIter
template <typename ValuesIter, typename ValidIter>
enable_if_t<std::is_pointer<ValidIter>::value, Status> AppendValues(
ValuesIter values_begin, ValuesIter values_end, ValidIter valid_begin) {
requires std::is_pointer_v<ValidIter>
Status AppendValues(ValuesIter values_begin, ValuesIter values_end,
ValidIter valid_begin) {
int64_t length = static_cast<int64_t>(std::distance(values_begin, values_end));
ARROW_RETURN_NOT_OK(Reserve(length));
data_builder_.UnsafeAppend<false>(
Expand Down
79 changes: 41 additions & 38 deletions cpp/src/arrow/compute/function_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#pragma once

#include <concepts>
#include <sstream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -97,16 +98,16 @@ ARROW_EXPORT
Result<std::unique_ptr<FunctionOptions>> DeserializeFunctionOptions(const Buffer& buffer);

template <typename T>
static inline enable_if_t<!has_enum_traits<T>::value, std::string> GenericToString(
const T& value) {
requires(!has_enum_traits<T>::value)
static inline std::string GenericToString(const T& value) {
std::stringstream ss;
ss << value;
return ss.str();
}

template <typename T>
static inline enable_if_t<!has_enum_traits<T>::value, std::string> GenericToString(
const std::optional<T>& value) {
requires(!has_enum_traits<T>::value)
static inline std::string GenericToString(const std::optional<T>& value) {
return value.has_value() ? GenericToString(value.value()) : "nullopt";
}

Expand All @@ -119,8 +120,8 @@ static inline std::string GenericToString(const std::string& value) {
}

template <typename T>
static inline enable_if_t<has_enum_traits<T>::value, std::string> GenericToString(
const T value) {
requires has_enum_traits<T>::value
static inline std::string GenericToString(const T value) {
return EnumTraits<T>::value_name(value);
}

Expand Down Expand Up @@ -256,21 +257,20 @@ GenericTypeSingleton() {
}

template <typename T>
static inline enable_if_same<T, std::shared_ptr<const KeyValueMetadata>,
std::shared_ptr<DataType>>
GenericTypeSingleton() {
requires std::same_as<T, std::shared_ptr<const KeyValueMetadata>>
static inline std::shared_ptr<DataType> GenericTypeSingleton() {
return map(binary(), binary());
}

template <typename T>
static inline enable_if_t<has_enum_traits<T>::value, std::shared_ptr<DataType>>
GenericTypeSingleton() {
requires has_enum_traits<T>::value
static inline std::shared_ptr<DataType> GenericTypeSingleton() {
return TypeTraits<typename EnumTraits<T>::Type>::type_singleton();
}

template <typename T>
static inline enable_if_same<T, SortKey, std::shared_ptr<DataType>>
GenericTypeSingleton() {
requires std::same_as<T, SortKey>
static inline std::shared_ptr<DataType> GenericTypeSingleton() {
std::vector<std::shared_ptr<Field>> fields;
fields.emplace_back(new Field("target", GenericTypeSingleton<std::string>()));
fields.emplace_back(new Field("order", GenericTypeSingleton<SortOrder>()));
Expand All @@ -294,7 +294,8 @@ static inline Result<std::shared_ptr<Scalar>> GenericToScalar(const FieldRef& re
return MakeScalar(ref.ToDotPath());
}

template <typename T, typename Enable = enable_if_t<has_enum_traits<T>::value>>
template <typename T>
requires has_enum_traits<T>::value
static inline Result<std::shared_ptr<Scalar>> GenericToScalar(const T value) {
using CType = typename EnumTraits<T>::CType;
return GenericToScalar(static_cast<CType>(value));
Expand Down Expand Up @@ -389,8 +390,9 @@ static inline Result<std::shared_ptr<Scalar>> GenericToScalar(
}

template <typename T>
static inline enable_if_primitive_ctype<typename CTypeTraits<T>::ArrowType, Result<T>>
GenericFromScalar(const std::shared_ptr<Scalar>& value) {
requires requires { typename CTypeTraits<T>::ArrowType; } &&
is_primitive_ctype<typename CTypeTraits<T>::ArrowType>::value
static inline Result<T> GenericFromScalar(const std::shared_ptr<Scalar>& value) {
using ArrowType = typename CTypeTraits<T>::ArrowType;
using ScalarType = typename TypeTraits<ArrowType>::ScalarType;
if (value->type->id() != ArrowType::type_id) {
Expand All @@ -403,8 +405,8 @@ GenericFromScalar(const std::shared_ptr<Scalar>& value) {
}

template <typename T>
static inline enable_if_primitive_ctype<typename EnumTraits<T>::Type, Result<T>>
GenericFromScalar(const std::shared_ptr<Scalar>& value) {
requires is_primitive_ctype<typename EnumTraits<T>::Type>::value
static inline Result<T> GenericFromScalar(const std::shared_ptr<Scalar>& value) {
ARROW_ASSIGN_OR_RAISE(auto raw_val,
GenericFromScalar<typename EnumTraits<T>::CType>(value));
return ValidateEnumValue<T>(raw_val);
Expand All @@ -414,8 +416,8 @@ template <typename T, typename U>
using enable_if_same_result = enable_if_same<T, U, Result<T>>;

template <typename T>
static inline enable_if_same_result<T, std::string> GenericFromScalar(
const std::shared_ptr<Scalar>& value) {
requires std::same_as<T, std::string>
static inline Result<T> GenericFromScalar(const std::shared_ptr<Scalar>& value) {
if (!is_base_binary_like(value->type->id())) {
return Status::Invalid("Expected binary-like type but got ", value->type->ToString());
}
Expand All @@ -425,15 +427,15 @@ static inline enable_if_same_result<T, std::string> GenericFromScalar(
}

template <typename T>
static inline enable_if_same_result<T, FieldRef> GenericFromScalar(
const std::shared_ptr<Scalar>& value) {
requires std::same_as<T, FieldRef>
static inline Result<T> GenericFromScalar(const std::shared_ptr<Scalar>& value) {
ARROW_ASSIGN_OR_RAISE(auto path, GenericFromScalar<std::string>(value));
return FieldRef::FromDotPath(path);
}

template <typename T>
static inline enable_if_same_result<T, SortKey> GenericFromScalar(
const std::shared_ptr<Scalar>& value) {
requires std::same_as<T, SortKey>
static inline Result<T> GenericFromScalar(const std::shared_ptr<Scalar>& value) {
if (value->type->id() != Type::STRUCT) {
return Status::Invalid("Expected type STRUCT but got ", value->type->id());
}
Expand All @@ -447,26 +449,26 @@ static inline enable_if_same_result<T, SortKey> GenericFromScalar(
}

template <typename T>
static inline enable_if_same_result<T, std::shared_ptr<DataType>> GenericFromScalar(
const std::shared_ptr<Scalar>& value) {
requires std::same_as<T, std::shared_ptr<DataType>>
static inline Result<T> GenericFromScalar(const std::shared_ptr<Scalar>& value) {
return value->type;
}

template <typename T>
static inline enable_if_same_result<T, TypeHolder> GenericFromScalar(
const std::shared_ptr<Scalar>& value) {
requires std::same_as<T, TypeHolder>
static inline Result<T> GenericFromScalar(const std::shared_ptr<Scalar>& value) {
return value->type;
}

template <typename T>
static inline enable_if_same_result<T, std::shared_ptr<Scalar>> GenericFromScalar(
const std::shared_ptr<Scalar>& value) {
requires std::same_as<T, std::shared_ptr<Scalar>>
static inline Result<T> GenericFromScalar(const std::shared_ptr<Scalar>& value) {
return value;
}

template <typename T>
static inline enable_if_same_result<T, std::shared_ptr<const KeyValueMetadata>>
GenericFromScalar(const std::shared_ptr<Scalar>& value) {
requires std::same_as<T, std::shared_ptr<const KeyValueMetadata>>
static inline Result<T> GenericFromScalar(const std::shared_ptr<Scalar>& value) {
auto ty = GenericTypeSingleton<std::shared_ptr<const KeyValueMetadata>>();
if (!value->type->Equals(ty)) {
return Status::Invalid("Expected ", ty->ToString(), " but got ",
Expand All @@ -486,8 +488,8 @@ GenericFromScalar(const std::shared_ptr<Scalar>& value) {
}

template <typename T>
static inline enable_if_same_result<T, Datum> GenericFromScalar(
const std::shared_ptr<Scalar>& value) {
requires std::same_as<T, Datum>
static inline Result<T> GenericFromScalar(const std::shared_ptr<Scalar>& value) {
if (value->type->id() == Type::LIST) {
const auto& holder = checked_cast<const BaseListScalar&>(*value);
return holder.value;
Expand All @@ -504,8 +506,8 @@ template <>
constexpr inline bool is_optional_v<std::nullopt_t> = true;

template <typename T>
static inline std::enable_if_t<is_optional_v<T>, Result<T>> GenericFromScalar(
const std::shared_ptr<Scalar>& value) {
requires is_optional_v<T>
static inline Result<T> GenericFromScalar(const std::shared_ptr<Scalar>& value) {
using value_type = typename T::value_type;
if (value->type->id() == Type::NA) {
return std::nullopt;
Expand All @@ -514,8 +516,9 @@ static inline std::enable_if_t<is_optional_v<T>, Result<T>> GenericFromScalar(
}

template <typename T>
static enable_if_same<typename CTypeTraits<T>::ArrowType, ListType, Result<T>>
GenericFromScalar(const std::shared_ptr<Scalar>& value) {
requires requires { typename CTypeTraits<T>::ArrowType; } &&
std::same_as<typename CTypeTraits<T>::ArrowType, ListType>
static inline Result<T> GenericFromScalar(const std::shared_ptr<Scalar>& value) {
using ValueType = typename T::value_type;
if (value->type->id() != Type::LIST) {
return Status::Invalid("Expected type LIST but got ", value->type->ToString());
Expand Down
56 changes: 28 additions & 28 deletions cpp/src/arrow/compute/kernels/aggregate_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,43 @@ namespace arrow::compute::internal {
template <typename I, typename Enable = void>
struct FindAccumulatorType {};

template <typename I>
struct FindAccumulatorType<I, enable_if_boolean<I>> {
template <arrow_boolean I>
struct FindAccumulatorType<I> {
using Type = UInt64Type;
};

template <typename I>
struct FindAccumulatorType<I, enable_if_signed_integer<I>> {
template <arrow_signed_integer I>
struct FindAccumulatorType<I> {
using Type = Int64Type;
};

template <typename I>
struct FindAccumulatorType<I, enable_if_unsigned_integer<I>> {
template <arrow_unsigned_integer I>
struct FindAccumulatorType<I> {
using Type = UInt64Type;
};

template <typename I>
struct FindAccumulatorType<I, enable_if_floating_point<I>> {
template <arrow_floating_point I>
struct FindAccumulatorType<I> {
using Type = DoubleType;
};

template <typename I>
struct FindAccumulatorType<I, enable_if_decimal32<I>> {
template <arrow_decimal32 I>
struct FindAccumulatorType<I> {
using Type = Decimal32Type;
};

template <typename I>
struct FindAccumulatorType<I, enable_if_decimal64<I>> {
template <arrow_decimal64 I>
struct FindAccumulatorType<I> {
using Type = Decimal64Type;
};

template <typename I>
struct FindAccumulatorType<I, enable_if_decimal128<I>> {
template <arrow_decimal128 I>
struct FindAccumulatorType<I> {
using Type = Decimal128Type;
};

template <typename I>
struct FindAccumulatorType<I, enable_if_decimal256<I>> {
template <arrow_decimal256 I>
struct FindAccumulatorType<I> {
using Type = Decimal256Type;
};

Expand All @@ -86,8 +86,8 @@ struct MultiplyTraits {
}
};

template <typename Type>
struct MultiplyTraits<Type, enable_if_decimal<Type>> {
template <arrow_decimal Type>
struct MultiplyTraits<Type> {
using CType = typename TypeTraits<Type>::CType;

constexpr static CType one(const DataType& ty) {
Expand Down Expand Up @@ -132,18 +132,18 @@ using arrow::internal::VisitSetBitRunsVoid;
template <typename T, typename Enable = void>
struct GetSumType;

template <typename T>
struct GetSumType<T, enable_if_floating_point<T>> {
template <arrow_floating_point T>
struct GetSumType<T> {
using SumType = double;
};

template <typename T>
struct GetSumType<T, enable_if_integer<T>> {
template <arrow_integer T>
struct GetSumType<T> {
using SumType = arrow::internal::int128_t;
};

template <typename T>
struct GetSumType<T, enable_if_decimal<T>> {
template <arrow_decimal T>
struct GetSumType<T> {
using SumType = typename TypeTraits<T>::CType;
};

Expand All @@ -156,8 +156,8 @@ struct GetSumType<T, enable_if_decimal<T>> {
// https://en.wikipedia.org/wiki/Pairwise_summation
template <typename ValueType, typename SumType, SimdLevel::type SimdLevel,
typename ValueFunc>
enable_if_t<std::is_floating_point<SumType>::value, SumType> SumArray(
const ArraySpan& data, ValueFunc&& func) {
requires std::floating_point<SumType>
SumType SumArray(const ArraySpan& data, ValueFunc&& func) {
using arrow::internal::VisitSetBitRunsVoid;

const int64_t data_size = data.length - data.GetNullCount();
Expand Down Expand Up @@ -234,8 +234,8 @@ enable_if_t<std::is_floating_point<SumType>::value, SumType> SumArray(
// naive summation for integers and decimals
template <typename ValueType, typename SumType, SimdLevel::type SimdLevel,
typename ValueFunc>
enable_if_t<!std::is_floating_point<SumType>::value, SumType> SumArray(
const ArraySpan& data, ValueFunc&& func) {
requires(!std::floating_point<SumType>)
SumType SumArray(const ArraySpan& data, ValueFunc&& func) {
using arrow::internal::VisitSetBitRunsVoid;

SumType sum = 0;
Expand Down
Loading
Loading