ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Extendable.hpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Extendable.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 
11 #include <tuple>
12 #include <type_traits>
14 
15 namespace Acts {
16 
17 namespace detail {
18 
27 template <typename... extensions_t>
28 struct Extendable {
29  // clang-format off
31  "all extensions must be default constructible");
33  "all extensions must be copy constructible");
35  "all extensions must be move constructible");
36  // clang-format on
37 
39  Extendable() = default;
40 
42  Extendable(const Extendable<extensions_t...>& extendable) = default;
43 
44  // Default move constructor
45  Extendable(Extendable<extensions_t...>&& extendable) = default;
46 
50  Extendable(const std::tuple<extensions_t...>& extensions)
51  : m_extensions(extensions) {}
52 
56  Extendable(std::tuple<extensions_t...>&& extensions)
57  : m_extensions(std::move(extensions)) {}
58 
62  Extendable<extensions_t...>& operator=(
63  const Extendable<extensions_t...>& extendable) = default;
64 
68  Extendable<extensions_t...>& operator=(
69  Extendable<extensions_t...>&& extendable) = default;
70 
76  template <typename... appendices_t>
77  Extendable<extensions_t..., appendices_t...> append(
78  appendices_t... aps) const {
79  auto catTuple =
80  std::tuple_cat(m_extensions, std::tuple<appendices_t...>(aps...));
81  return Extendable<extensions_t..., appendices_t...>(std::move(catTuple));
82  }
83 
87  template <typename extension_t>
88  const extension_t& get() const {
89  return std::get<extension_t>(m_extensions);
90  }
91 
95  template <typename extension_t>
96  extension_t& get() {
97  return std::get<extension_t>(m_extensions);
98  }
99 
103  const std::tuple<extensions_t...>& tuple() const { return m_extensions; }
104 
108  std::tuple<extensions_t...>& tuple() { return m_extensions; }
109 
110  private:
111  std::tuple<extensions_t...> m_extensions;
112 };
113 
114 } // namespace detail
115 } // namespace Acts