ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
type_collector.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file type_collector.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2016-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #pragma once
10 #include <boost/hana/filter.hpp>
11 #include <boost/hana/set.hpp>
12 #include <boost/hana/type.hpp>
13 
14 namespace Acts {
15 
16 namespace detail {
17 namespace hana = boost::hana;
18 
24  // Checks whether the type even has a result type
25  static constexpr auto predicate = hana::is_valid(
26  [](auto t) -> hana::type<typename decltype(t)::type::result_type>{});
27  // meta function to extract the result type
28  template <typename T>
29  using extractor_impl = typename T::result_type;
30  // embed meta function in hana
31  static constexpr auto extractor = hana::template_<extractor_impl>;
32 };
33 
39  // Checks if aborter even has action type
40  static constexpr auto predicate = hana::is_valid(
41  [](auto t) -> hana::type<typename decltype(t)::type::action_type>{});
42  // meta function to extract the action type
43  template <typename T>
44  using extractor_impl = typename T::action_type;
45  // converted to hana
46  static constexpr auto extractor = hana::template_<extractor_impl>;
47 };
48 
55 constexpr auto type_collector = [](auto t_, auto predicate, auto extractor) {
56  // filtered list using predicate
57  constexpr auto have_result =
58  hana::filter(t_, [&](auto t) { return predicate(t); });
59  // convert to set to remove duplicates, and transform to unpacked type
60  // using extractor.
61  constexpr auto result_types =
62  hana::to_set(hana::transform(have_result, extractor));
63  return result_types;
64 };
65 
74 template <typename helper, typename... items>
75 constexpr auto type_collector_t = type_collector(hana::tuple_t<items...>,
76  helper::predicate,
77  helper::extractor);
78 
83 template <typename T>
84 constexpr bool has_result_type_v =
85  decltype(result_type_extractor::predicate(hana::type_c<T>))::value;
86 
91 template <typename T>
93 
98 template <typename T>
99 constexpr bool has_action_type_v =
100  decltype(action_type_extractor::predicate(hana::type_c<T>))::value;
101 
106 template <typename T>
108 } // namespace detail
109 
110 } // namespace Acts