|
| 1 | +// Copyright CERN and copyright holders of ALICE O2. This software is |
| 2 | +// distributed under the terms of the GNU General Public License v3 (GPL |
| 3 | +// Version 3), copied verbatim in the file "COPYING". |
| 4 | +// |
| 5 | +// See http://alice-o2.web.cern.ch/license for full licensing information. |
| 6 | +// |
| 7 | +// In applying this license CERN does not waive the privileges and immunities |
| 8 | +// granted to it by virtue of its status as an Intergovernmental Organization |
| 9 | +// or submit itself to any jurisdiction. |
| 10 | + |
| 11 | +#include <Framework/Traits.h> |
| 12 | +#include <tuple> |
| 13 | +#include <type_traits> |
| 14 | + |
| 15 | +namespace o2::framework |
| 16 | +{ |
| 17 | +struct any_type { |
| 18 | + template <class T> |
| 19 | + constexpr operator T(); // non explicit |
| 20 | +}; |
| 21 | + |
| 22 | +template <class T, typename... Args> |
| 23 | +decltype(void(T{ std::declval<Args>()... }), std::true_type()) |
| 24 | + test(int); |
| 25 | + |
| 26 | +template <class T, typename... Args> |
| 27 | +std::false_type |
| 28 | + test(...); |
| 29 | + |
| 30 | +template <class T, typename... Args> |
| 31 | +struct is_braces_constructible : decltype(test<T, Args...>(0)) { |
| 32 | +}; |
| 33 | + |
| 34 | +/// Helper function to convert a brace-initialisable struct to |
| 35 | +/// a tuple. |
| 36 | +template <class T> |
| 37 | +auto constexpr to_tuple(T&& object) noexcept |
| 38 | +{ |
| 39 | + using type = std::decay_t<T>; |
| 40 | + if constexpr (is_braces_constructible<type, any_type, any_type, any_type, any_type>{}) { |
| 41 | + auto&& [p1, p2, p3] = object; |
| 42 | + return std::make_tuple(p1, p2, p3); |
| 43 | + } else if constexpr (is_braces_constructible<type, any_type, any_type, any_type>{}) { |
| 44 | + auto&& [p1, p2] = object; |
| 45 | + return std::make_tuple(p1, p2); |
| 46 | + } else if constexpr (is_braces_constructible<type, any_type, any_type>{}) { |
| 47 | + auto&& [p1] = object; |
| 48 | + return std::make_tuple(p1); |
| 49 | + } else if constexpr (is_braces_constructible<type, any_type>{}) { |
| 50 | + return std::make_tuple(); |
| 51 | + } else { |
| 52 | + static_assert(always_static_assert<type>(), "You must inherit from AnalysisTask"); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +/// Helper function to convert a brace-initialisable struct to |
| 57 | +/// a tuple. |
| 58 | +template <class T> |
| 59 | +auto constexpr to_tuple_refs(T&& object) noexcept |
| 60 | +{ |
| 61 | + using type = std::decay_t<T>; |
| 62 | + if constexpr (is_braces_constructible<type, any_type, any_type, any_type, any_type>{}) { |
| 63 | + auto&& [p1, p2, p3] = object; |
| 64 | + return std::tie(p1, p2, p3); |
| 65 | + } else if constexpr (is_braces_constructible<type, any_type, any_type, any_type>{}) { |
| 66 | + auto&& [p1, p2] = object; |
| 67 | + return std::tie(p1, p2); |
| 68 | + } else if constexpr (is_braces_constructible<type, any_type, any_type>{}) { |
| 69 | + auto&& [p1] = object; |
| 70 | + return std::tie(p1); |
| 71 | + } else if constexpr (is_braces_constructible<type, any_type>{}) { |
| 72 | + return std::make_tuple(); |
| 73 | + } else { |
| 74 | + static_assert(always_static_assert<type>(), "You must inherit from AnalysisTask"); |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +} // namespace o2::framework |
0 commit comments