@@ -661,29 +661,27 @@ 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 {
667- 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>;
668+ if constexpr (std::is_bounded_array_v<ARG0> == false &&
669+ std::is_arithmetic_v<ARG0> == false &&
670+ framework::is_base_of_template_v<std::vector, ARG0> == false ) {
671+ using argsPack_t = decltype (tuple_to_pack (framework::to_tuple (std::declval<ARG0>())));
680672 return framework::pack_size (argsPack_t{});
681- } else if constexpr (sizeof ...(ARGS) >= 1 ) {
682- return sizeof ...(ARGS);
683673 } else {
684- static_assert (o2::framework::always_static_assert_v<ARGS...>, " Unmanaged case " ) ;
674+ return 1 ;
685675 }
686676 }
677+
678+ template <typename ARG0, typename ... ARGS>
679+ requires (sizeof ...(ARGS) > 0 )
680+ static constexpr int countColumns ()
681+ {
682+ return 1 + sizeof ...(ARGS);
683+ }
684+
687685 void setLabel (const char * label);
688686
689687 TableBuilder (arrow::MemoryPool* pool = arrow::default_memory_pool())
@@ -699,38 +697,44 @@ class TableBuilder
699697
700698 // / Creates a lambda which is suitable to persist things
701699 // / in an arrow::Table
702- template <typename ... ARGS, size_t NCOLUMNS = countColumns<ARGS...>()>
703- auto persist (std::array<char const *, NCOLUMNS> const & columnNames)
704- {
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>())));
700+ template <typename ARG0, typename ... ARGS>
701+ requires (sizeof ...(ARGS) > 0 )
702+ auto persist (std::array<char const *, sizeof ...(ARGS) + 1> const & columnNames)
703+ {
704+ auto persister = persistTuple (framework::pack<ARG0, ARGS...>{}, columnNames);
705+ // Callback used to fill the builders
706+ return [persister = persister](unsigned int slot, typename BuilderMaker<ARG0>::FillType const & arg, typename BuilderMaker<ARGS>::FillType... args) -> void {
707+ persister (slot, std::forward_as_tuple (arg, args...));
708+ };
709+ }
710+
711+ // Special case for a single parameter to handle the serialization of struct
712+ // which can be decomposed
713+ template <typename ARG0, typename ... ARGS>
714+ requires (sizeof ...(ARGS) == 0 )
715+ auto persist (std::array<char const *, countColumns<ARG0, ARGS...>()> const & columnNames)
716+ {
717+ if constexpr (std::is_bounded_array_v<ARG0> == false &&
718+ std::is_arithmetic_v<ARG0> == false &&
719+ framework::is_base_of_template_v<std::vector, ARG0> == false ) {
720+ using argsPack_t = decltype (tuple_to_pack (framework::to_tuple (std::declval<ARG0>())));
712721 auto persister = persistTuple (argsPack_t{}, columnNames);
713- return [persister = persister](unsigned int slot, objType_t const & obj) -> void {
722+ return [persister = persister](unsigned int slot, ARG0 const & obj) -> void {
714723 auto t = to_tuple (obj);
715724 persister (slot, t);
716725 };
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);
726+ } else if constexpr ((std::is_bounded_array_v<ARG0> == true ||
727+ framework::is_base_of_template_v<std::vector, ARG0> == true )) {
728+ auto persister = persistTuple (framework::pack<ARG0>{}, columnNames);
722729 // Callback used to fill the builders
723- return [persister = persister](unsigned int slot, typename BuilderMaker<objType_t >::FillType const & arg) -> void {
730+ return [persister = persister](unsigned int slot, typename BuilderMaker<ARG0 >::FillType const & arg) -> void {
724731 persister (slot, std::forward_as_tuple (arg));
725732 };
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- };
732733 } else {
733- static_assert (o2::framework::always_static_assert_v<ARGS...>, " Unmanaged case" );
734+ auto persister = persistTuple (framework::pack<ARG0>{}, columnNames);
735+ return [persister = persister](unsigned int slot, typename BuilderMaker<ARG0>::FillType const & arg) -> void {
736+ persister (slot, std::forward_as_tuple (arg));
737+ };
734738 }
735739 }
736740
0 commit comments