Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:27:55

0001 // This file is part of the Acts project.
0002 //
0003 // Copyright (C) 2016-2018 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 http://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 #include "Acts/Utilities/detail/MPL/all_of.hpp"
0012 
0013 #include <tuple>
0014 #include <type_traits>
0015 
0016 namespace Acts::detail {
0017 
0018 /// This sctruct defines an extendable std::tuple
0019 ///
0020 /// all Extensions have to :
0021 ///   - default constructible
0022 ///   - copy constructible
0023 ///   - move constructible
0024 ///
0025 /// This is needed in order to allow custom construction of objects
0026 template <typename... extensions_t>
0027 struct Extendable {
0028   // clang-format off
0029     static_assert(detail::all_of_v<std::is_default_constructible<extensions_t>::value...>,
0030                   "all extensions must be default constructible");
0031     static_assert(detail::all_of_v<std::is_copy_constructible<extensions_t>::value...>,
0032                   "all extensions must be copy constructible");
0033     static_assert(detail::all_of_v<std::is_move_constructible<extensions_t>::value...>,
0034                   "all extensions must be move constructible");
0035   // clang-format on
0036 
0037   /// Default constructor
0038   Extendable() = default;
0039 
0040   /// Default copy constructor
0041   Extendable(const Extendable<extensions_t...>& extendable) = default;
0042 
0043   // Default move constructor
0044   Extendable(Extendable<extensions_t...>&& extendable) = default;
0045 
0046   /// Constructor from tuple
0047   ///
0048   /// @param extensions Source extensions tuple
0049   Extendable(const std::tuple<extensions_t...>& extensions)
0050       : m_extensions(extensions) {}
0051 
0052   /// Constructor from tuple move
0053   ///
0054   /// @param extensions source extensions tuple
0055   Extendable(std::tuple<extensions_t...>&& extensions)
0056       : m_extensions(std::move(extensions)) {}
0057 
0058   /// Default move assignment operator
0059   ///
0060   /// @param extendable The source Extendable list
0061   Extendable<extensions_t...>& operator=(
0062       const Extendable<extensions_t...>& extendable) = default;
0063 
0064   /// Default move assignment operator
0065   ///
0066   /// @param extendable The source Extendable list
0067   Extendable<extensions_t...>& operator=(
0068       Extendable<extensions_t...>&& extendable) = default;
0069 
0070   /// Append new entries and return a new condition
0071   ///
0072   /// @tparam appendices_t Types of appended entries to the tuple
0073   ///
0074   /// @param aps The extensions to be appended to the new Extendable
0075   template <typename... appendices_t>
0076   Extendable<extensions_t..., appendices_t...> append(
0077       appendices_t... aps) const {
0078     auto catTuple =
0079         std::tuple_cat(m_extensions, std::tuple<appendices_t...>(aps...));
0080     return Extendable<extensions_t..., appendices_t...>(std::move(catTuple));
0081   }
0082 
0083   /// Const retrieval of an extension of a specific type
0084   ///
0085   /// @tparam extension_t Type of the Extension to be retrieved
0086   template <typename extension_t>
0087   const extension_t& get() const {
0088     return std::get<extension_t>(m_extensions);
0089   }
0090 
0091   /// Non-const retrieval of an extension of a specific type
0092   ///
0093   /// @tparam extension_t Type of the Extension to be retrieved
0094   template <typename extension_t>
0095   extension_t& get() {
0096     return std::get<extension_t>(m_extensions);
0097   }
0098 
0099   /// Const retrieval of the extension tuype
0100   ///
0101   /// @tparam extension_t Type of the Extension to be retrieved
0102   const std::tuple<extensions_t...>& tuple() const { return m_extensions; }
0103 
0104   /// Non-Const retrieval of the extendsion tuype
0105   ///
0106   /// @tparam extension_t Type of the Extension to be retrieved
0107   std::tuple<extensions_t...>& tuple() { return m_extensions; }
0108 
0109  private:
0110   std::tuple<extensions_t...> m_extensions;
0111 };
0112 
0113 }  // namespace Acts::detail