Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:12:13

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include <tuple>
0012 #include <type_traits>
0013 #include <utility>
0014 
0015 namespace ActsFatras::detail {
0016 
0017 /// Combine multiple selectors with a configurable combine function.
0018 template <bool Initial, typename Combine, typename... Selectors>
0019 class CombineSelectors {
0020   static_assert(0u < sizeof...(Selectors),
0021                 "Must combine at least one selector");
0022 
0023  public:
0024   /// Call all configured selectors and combine the result.
0025   ///
0026   /// @param[in] things the inputs that will be selected
0027   /// @return a boolean indicating the combined selection decision
0028   ///
0029   /// @tparam Ts the types of the selected inputs
0030   template <typename... Ts>
0031   bool operator()(const Ts &...things) const {
0032     static_assert(
0033         (true && ... && std::is_same_v<bool, decltype(Selectors()(things...))>),
0034         "Not all selectors conform to the expected interface (bool)(const "
0035         "T&...)");
0036     return impl(std::index_sequence_for<Selectors...>(), things...);
0037   }
0038 
0039   /// Access a specific selector by index.
0040   template <std::size_t I>
0041   std::tuple_element_t<I, std::tuple<Selectors...>> &get() {
0042     return std::get<I>(m_selectors);
0043   }
0044   /// Access a specific selector by type.
0045   template <typename Selector>
0046   Selector &get() {
0047     return std::get<Selector>(m_selectors);
0048   }
0049 
0050  private:
0051   std::tuple<Selectors...> m_selectors;
0052 
0053   template <std::size_t... Is, typename... Ts>
0054   bool impl(std::index_sequence<Is...> /*indices*/, const Ts &...things) const {
0055     Combine combine;
0056     // compute status for all selectors
0057     bool status[] = {std::get<Is>(m_selectors)(things...)...};
0058     // reduce over the combine function with configured initial value
0059     bool ret = Initial;
0060     for (bool value : status) {
0061       ret = combine(ret, value);
0062     }
0063     return ret;
0064   }
0065 };
0066 
0067 }  // namespace ActsFatras::detail