HuaHuaY commented on code in PR #55291:
URL: https://github.com/apache/arrow/pull/55291#discussion_r4442148824
##########
cpp/src/arrow/type_traits.h:
##########
@@ -1018,6 +1025,146 @@ template <typename T, typename R = void>
using enable_if_physical_floating_point =
enable_if_t<is_physical_floating_type<T>::value, R>;
+///
+/// Compile-time collections of type ids, for metaprogramming and other
purposes.
+///
+
+/// \addtogroup type-id-collections
+/// @{
+
+/// A std::array<> of all valid Type::type ids.
+constexpr auto kAllTypeIds = std::array{Type::NA,
+ Type::BOOL,
+ Type::INT8,
+ Type::INT16,
+ Type::INT32,
+ Type::INT64,
+ Type::UINT8,
+ Type::UINT16,
+ Type::UINT32,
+ Type::UINT64,
+ Type::HALF_FLOAT,
+ Type::FLOAT,
+ Type::DOUBLE,
+ Type::DECIMAL32,
+ Type::DECIMAL64,
+ Type::DECIMAL128,
+ Type::DECIMAL256,
+ Type::DATE32,
+ Type::DATE64,
+ Type::TIME32,
+ Type::TIME64,
+ Type::TIMESTAMP,
+ Type::INTERVAL_DAY_TIME,
+ Type::INTERVAL_MONTHS,
+ Type::DURATION,
+ Type::STRING,
+ Type::BINARY,
+ Type::LARGE_STRING,
+ Type::LARGE_BINARY,
+ Type::STRING_VIEW,
+ Type::BINARY_VIEW,
+ Type::FIXED_SIZE_BINARY,
+ Type::STRUCT,
+ Type::LIST,
+ Type::LARGE_LIST,
+ Type::LIST_VIEW,
+ Type::LARGE_LIST_VIEW,
+ Type::FIXED_SIZE_LIST,
+ Type::MAP,
+ Type::DENSE_UNION,
+ Type::SPARSE_UNION,
+ Type::DICTIONARY,
+ Type::EXTENSION,
+ Type::INTERVAL_MONTH_DAY_NANO,
+ Type::RUN_END_ENCODED};
+
+/// A std::array of all integer type ids
+constexpr auto kIntegerTypeIds =
+ std::array{Type::INT8, Type::UINT8, Type::INT16, Type::UINT16,
+ Type::INT32, Type::UINT32, Type::INT64, Type::UINT64};
+
+/// A std::array of all signed integer type ids
+constexpr auto kSignedIntegerTypeIds =
+ std::array{Type::INT8, Type::INT16, Type::INT32, Type::INT64};
+
+/// A std::array of all unsigned integer type ids
+constexpr auto kUnsignedIntegerTypeIds =
+ std::array{Type::UINT8, Type::UINT16, Type::UINT32, Type::UINT64};
+
+/// A std::array of all floating-point type ids
+constexpr auto kFloatingTypeIds = std::array{Type::HALF_FLOAT, Type::FLOAT,
Type::DOUBLE};
+
+/// A std::array of all floating-point type ids, except HALF_FLOAT
+constexpr auto kPhysicalFloatingTypeIds = std::array{Type::FLOAT,
Type::DOUBLE};
+
+/// A std::array of all numeric type ids (except decimals)
+constexpr auto kNumericTypeIds = std::array{
+ Type::INT8, Type::UINT8, Type::INT16, Type::UINT16, Type::INT32,
Type::UINT32,
+ Type::INT64, Type::UINT64, Type::HALF_FLOAT, Type::FLOAT, Type::DOUBLE};
+
+/// A std::array of all decimal type ids
+constexpr auto kDecimalTypeIds =
+ std::array{Type::DECIMAL32, Type::DECIMAL64, Type::DECIMAL128,
Type::DECIMAL256};
+
+/// A std::array of all temporal type ids (dates, times, timestamps)
+constexpr auto kTemporalTypeIds =
+ std::array{Type::DATE32, Type::DATE64, Type::TIME32, Type::TIME64,
Type::TIMESTAMP};
+
+/// A std::array of all date type ids
+constexpr auto kDateTypeIds = std::array{Type::DATE32, Type::DATE64};
+
+/// A std::array of all time type ids
+constexpr auto kTimeTypeIds = std::array{Type::TIME32, Type::TIME64};
+
+/// A std::array of all interval type ids
+constexpr auto kIntervalTypeIds = std::array{
+ Type::INTERVAL_DAY_TIME, Type::INTERVAL_MONTHS,
Type::INTERVAL_MONTH_DAY_NANO};
+
+/// A std::array of all primitive type ids (excluding null, decimals,
binary-like)
+constexpr auto kPrimitiveTypeIds = std::array{Type::BOOL,
+ Type::INT8,
+ Type::UINT8,
+ Type::INT16,
+ Type::UINT16,
+ Type::INT32,
+ Type::UINT32,
+ Type::INT64,
+ Type::UINT64,
+ Type::HALF_FLOAT,
+ Type::FLOAT,
+ Type::DOUBLE,
+ Type::DATE32,
+ Type::DATE64,
+ Type::TIME32,
+ Type::TIME64,
+ Type::TIMESTAMP,
+ Type::DURATION,
+ Type::INTERVAL_DAY_TIME,
+ Type::INTERVAL_MONTHS,
+ Type::INTERVAL_MONTH_DAY_NANO};
+
+/// A std::array of all base-binary-like type ids
+constexpr auto kBaseBinaryLikeTypeIds =
+ std::array{Type::BINARY, Type::LARGE_BINARY, Type::STRING,
Type::LARGE_STRING};
+
+/// A std::array of all binary-view-like type ids
+constexpr auto kBinaryViewLikeTypeIds = std::array{Type::BINARY_VIEW,
Type::STRING_VIEW};
+
+/// @}
+
+namespace detail {
+
+template <typename T, size_t N>
+constexpr bool array_contains(const std::array<T, N>& array, T value) {
+ auto impl = [&]<std::size_t... I>(std::index_sequence<I...>) {
Review Comment:
I think this implementation could be replaced with `std::find`, which has
been `constexpr` since C++20.
However, my compilation tests showed that the generated machine code for
constant arrays is suboptimal. It is likely due to an optimization issue in the
version of LLVM I’m using—an issue affecting macOS:
https://github.com/llvm/llvm-project/pull/217655
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]