@@ -661,29 +661,28 @@ class TableBuilder
661661 }
662662
663663 public:
664- template <typename ... ARGS>
664+ template <typename ARG0, typename ... ARGS>
665+ requires (sizeof ...(ARGS) == 0 )
665666 static constexpr int countColumns ()
666667 {
667668 using args_pack_t = framework::pack<ARGS...>;
668- if constexpr (sizeof ...(ARGS) == 1 &&
669- std::is_bounded_array<pack_element_t <0 , args_pack_t >>::value == false &&
670- std::is_arithmetic_v<pack_element_t <0 , args_pack_t >> == false &&
671- framework::is_base_of_template_v<std::vector, pack_element_t <0 , args_pack_t >> == false ) {
672- using objType_t = pack_element_t <0 , framework::pack<ARGS...>>;
673- using argsPack_t = decltype (tuple_to_pack (framework::to_tuple (std::declval<objType_t>())));
674- return framework::pack_size (argsPack_t{});
675- } else if constexpr (sizeof ...(ARGS) == 1 &&
676- (std::is_bounded_array<pack_element_t <0 , args_pack_t >>::value == true ||
677- framework::is_base_of_template_v<std::vector, pack_element_t <0 , args_pack_t >> == true )) {
678- using objType_t = pack_element_t <0 , framework::pack<ARGS...>>;
679- using argsPack_t = framework::pack<objType_t>;
669+ if constexpr (std::is_bounded_array_v<ARG0> == false &&
670+ std::is_arithmetic_v<ARG0> == false &&
671+ framework::is_base_of_template_v<std::vector, ARG0> == false ) {
672+ using argsPack_t = decltype (tuple_to_pack (framework::to_tuple (std::declval<ARG0>())));
680673 return framework::pack_size (argsPack_t{});
681- } else if constexpr (sizeof ...(ARGS) >= 1 ) {
682- return sizeof ...(ARGS);
683674 } else {
684- static_assert (o2::framework::always_static_assert_v<ARGS...>, " Unmanaged case " ) ;
675+ return 1 ;
685676 }
686677 }
678+
679+ template <typename ARG0, typename ... ARGS>
680+ requires (sizeof ...(ARGS) > 0 )
681+ static constexpr int countColumns ()
682+ {
683+ return 1 + sizeof ...(ARGS);
684+ }
685+
687686 void setLabel (const char * label);
688687
689688 TableBuilder (arrow::MemoryPool* pool = arrow::default_memory_pool())
@@ -699,38 +698,46 @@ class TableBuilder
699698
700699 // / Creates a lambda which is suitable to persist things
701700 // / in an arrow::Table
702- template <typename ... ARGS, size_t NCOLUMNS = countColumns<ARGS...>()>
703- auto persist (std::array<char const *, NCOLUMNS> const & columnNames)
701+ template <typename ARG0, typename ... ARGS>
702+ requires (sizeof ...(ARGS) > 0 )
703+ auto persist (std::array<char const *, sizeof ...(ARGS) + 1> const & columnNames)
704704 {
705- using args_pack_t = framework::pack<ARGS...>;
706- if constexpr (sizeof ...(ARGS) == 1 &&
707- std::is_bounded_array<pack_element_t <0 , args_pack_t >>::value == false &&
708- std::is_arithmetic_v<pack_element_t <0 , args_pack_t >> == false &&
709- framework::is_base_of_template_v<std::vector, pack_element_t <0 , args_pack_t >> == false ) {
710- using objType_t = pack_element_t <0 , framework::pack<ARGS...>>;
711- using argsPack_t = decltype (tuple_to_pack (framework::to_tuple (std::declval<objType_t>())));
705+ using args_pack_t = framework::pack<ARG0, ARGS...>;
706+ auto persister = persistTuple (framework::pack<ARG0, ARGS...>{}, columnNames);
707+ // Callback used to fill the builders
708+ return [persister = persister](unsigned int slot, typename BuilderMaker<ARG0>::FillType const & arg, typename BuilderMaker<ARGS>::FillType... args) -> void {
709+ persister (slot, std::forward_as_tuple (arg, args...));
710+ };
711+ }
712+
713+ // Special case for a single parameter to handle the serialization of struct
714+ // which can be decomposed
715+ template <typename ARG0, typename ... ARGS>
716+ requires (sizeof ...(ARGS) == 0 )
717+ auto persist (std::array<char const *, countColumns<ARG0, ARGS...>()> const & columnNames)
718+ {
719+ using args_pack_t = framework::pack<ARG0, ARGS...>;
720+ if constexpr (std::is_bounded_array_v<ARG0> == false &&
721+ std::is_arithmetic_v<ARG0> == false &&
722+ framework::is_base_of_template_v<std::vector, ARG0> == false ) {
723+ using argsPack_t = decltype (tuple_to_pack (framework::to_tuple (std::declval<ARG0>())));
712724 auto persister = persistTuple (argsPack_t{}, columnNames);
713- return [persister = persister](unsigned int slot, objType_t const & obj) -> void {
725+ return [persister = persister](unsigned int slot, ARG0 const & obj) -> void {
714726 auto t = to_tuple (obj);
715727 persister (slot, t);
716728 };
717- } else if constexpr (sizeof ...(ARGS) == 1 &&
718- (std::is_bounded_array<pack_element_t <0 , args_pack_t >>::value == true ||
719- framework::is_base_of_template_v<std::vector, pack_element_t <0 , args_pack_t >> == true )) {
720- using objType_t = pack_element_t <0 , framework::pack<ARGS...>>;
721- auto persister = persistTuple (framework::pack<objType_t>{}, columnNames);
729+ } else if constexpr ((std::is_bounded_array_v<ARG0> == true ||
730+ framework::is_base_of_template_v<std::vector, ARG0> == true )) {
731+ auto persister = persistTuple (framework::pack<ARG0>{}, columnNames);
722732 // Callback used to fill the builders
723- return [persister = persister](unsigned int slot, typename BuilderMaker<objType_t >::FillType const & arg) -> void {
733+ return [persister = persister](unsigned int slot, typename BuilderMaker<ARG0 >::FillType const & arg) -> void {
724734 persister (slot, std::forward_as_tuple (arg));
725735 };
726- } else if constexpr (sizeof ...(ARGS) >= 1 ) {
727- auto persister = persistTuple (framework::pack<ARGS...>{}, columnNames);
728- // Callback used to fill the builders
729- return [persister = persister](unsigned int slot, typename BuilderMaker<ARGS>::FillType... args) -> void {
730- persister (slot, std::forward_as_tuple (args...));
731- };
732736 } else {
733- static_assert (o2::framework::always_static_assert_v<ARGS...>, " Unmanaged case" );
737+ auto persister = persistTuple (framework::pack<ARG0>{}, columnNames);
738+ return [persister = persister](unsigned int slot, typename BuilderMaker<ARG0>::FillType const & arg) -> void {
739+ persister (slot, std::forward_as_tuple (arg));
740+ };
734741 }
735742 }
736743
0 commit comments