Skip to content

Commit 8aa9084

Browse files
author
Rafał Hibner
committed
Simplify traits
1 parent 00773c5 commit 8aa9084

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

cpp/src/arrow/type_traits.h

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -573,27 +573,35 @@ struct TypeTraits<FixedSizeListType> {
573573
};
574574
/// @}
575575

576-
namespace internal {
577-
578576
template <typename T, typename Enable = void>
579-
struct nested_has_type_singleton_impl : std::false_type {};
580-
template <typename T>
581-
struct nested_has_type_singleton_impl<T, std::enable_if_t<is_optional_like<T>::value>>
582-
: has_type_singleton<
583-
CTypeTraits<typename std::decay<decltype(*std::declval<T>())>::type>> {};
584-
template <typename T>
585-
struct nested_has_type_singleton_impl<T, std::enable_if_t<!is_optional_like<T>::value>>
586-
: has_type_singleton<CTypeTraits<T>> {};
587-
588-
} // namespace internal
577+
struct FindValueType : public std::false_type {
578+
using type = T;
579+
};
580+
template <typename OPTT>
581+
struct FindValueType<OPTT, enable_if_optional_like<OPTT>> {
582+
using type =
583+
typename FindValueType<std::decay_t<decltype(*std::declval<OPTT>())>>::type;
584+
};
585+
template <typename OPTT>
586+
struct FindValueType<std::vector<OPTT>> {
587+
using type = typename FindValueType<OPTT>::type;
588+
};
589+
template <typename OPTT, unsigned int N>
590+
struct FindValueType<std::array<OPTT, N>> {
591+
using type = typename FindValueType<OPTT>::type;
592+
};
589593

590-
template <typename T, typename R = void>
591-
using nested_has_type_singleton = typename internal::nested_has_type_singleton_impl<T, R>;
594+
template <typename T>
595+
struct ChildTypeTraits {
596+
using is_optional = internal::is_optional_like<T>;
597+
using unwrapped_type = typename FindValueType<T>::type;
598+
using has_type_singleton = internal::has_type_singleton<CTypeTraits<unwrapped_type>>;
599+
};
592600

593601
/// \addtogroup c-type-traits
594602
template <typename CType>
595603
struct CTypeTraits<std::vector<CType>,
596-
std::enable_if_t<nested_has_type_singleton<CType>::value>>
604+
std::enable_if_t<ChildTypeTraits<CType>::has_type_singleton::value>>
597605
: public TypeTraits<ListType> {
598606
using ArrowType = ListType;
599607
static auto type_singleton() {
@@ -610,15 +618,15 @@ struct CTypeTraits<std::vector<CType>,
610618
/// \addtogroup c-type-traits
611619
template <typename CType>
612620
struct CTypeTraits<std::vector<CType>,
613-
std::enable_if_t<!nested_has_type_singleton<CType>::value>>
621+
std::enable_if_t<!ChildTypeTraits<CType>::has_type_singleton::value>>
614622
: public TypeTraits<ListType> {
615623
using ArrowType = ListType;
616624
};
617625

618626
/// \addtogroup c-type-traits
619627
template <typename CType, std::size_t N>
620628
struct CTypeTraits<std::array<CType, N>,
621-
std::enable_if_t<nested_has_type_singleton<CType>::value>>
629+
std::enable_if_t<ChildTypeTraits<CType>::has_type_singleton::value>>
622630
: public TypeTraits<FixedSizeListType> {
623631
using ArrowType = FixedSizeListType;
624632

@@ -637,7 +645,7 @@ struct CTypeTraits<std::array<CType, N>,
637645
/// \addtogroup c-type-traits
638646
template <typename CType, std::size_t N>
639647
struct CTypeTraits<std::array<CType, N>,
640-
std::enable_if_t<!nested_has_type_singleton<CType>::value>>
648+
std::enable_if_t<!ChildTypeTraits<CType>::has_type_singleton::value>>
641649
: public TypeTraits<FixedSizeListType> {
642650
using ArrowType = FixedSizeListType;
643651
};

0 commit comments

Comments
 (0)