Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:11:07

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