Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
combine_selectors.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file combine_selectors.hpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 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 
11 #include <tuple>
12 #include <type_traits>
13 #include <utility>
14 
15 namespace ActsFatras {
16 namespace detail {
17 
19 template <bool Initial, typename Combine, typename... Selectors>
21  static_assert(0u < sizeof...(Selectors),
22  "Must combine at least one selector");
23 
24  public:
31  template <typename... Ts>
32  bool operator()(const Ts &...things) const {
33  static_assert(
34  (true && ... && std::is_same_v<bool, decltype(Selectors()(things...))>),
35  "Not all selectors conform to the expected interface (bool)(const "
36  "T&...)");
37  return impl(std::index_sequence_for<Selectors...>(), things...);
38  }
39 
41  template <size_t I>
42  std::tuple_element_t<I, std::tuple<Selectors...>> &get() {
43  return std::get<I>(m_selectors);
44  }
46  template <typename Selector>
47  Selector &get() {
48  return std::get<Selector>(m_selectors);
49  }
50 
51  private:
52  std::tuple<Selectors...> m_selectors;
53 
54  template <std::size_t... Is, typename... Ts>
55  bool impl(std::index_sequence<Is...> /*indices*/, const Ts &...things) const {
56  Combine combine;
57  // compute status for all selectors
58  bool status[] = {std::get<Is>(m_selectors)(things...)...};
59  // reduce over the combine function with configured initial value
60  bool ret = Initial;
61  for (bool value : status) {
62  ret = combine(ret, value);
63  }
64  return ret;
65  }
66 };
67 
68 } // namespace detail
69 } // namespace ActsFatras