Analysis Software
Documentation for sPHENIX simulation 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 
12 
13 #include <tuple>
14 #include <type_traits>
15 
16 namespace Acts {
17 
18 namespace detail {
19 
28 template <typename... extensions_t>
29 struct Extendable {
30  // clang-format off
32  "all extensions must be default constructible");
34  "all extensions must be copy constructible");
36  "all extensions must be move constructible");
37  // clang-format on
38 
40  Extendable() = default;
41 
43  Extendable(const Extendable<extensions_t...>& extendable) = default;
44 
45  // Default move constructor
46  Extendable(Extendable<extensions_t...>&& extendable) = default;
47 
51  Extendable(const std::tuple<extensions_t...>& extensions)
52  : m_extensions(extensions) {}
53 
57  Extendable(std::tuple<extensions_t...>&& extensions)
58  : m_extensions(std::move(extensions)) {}
59 
63  Extendable<extensions_t...>& operator=(
64  const Extendable<extensions_t...>& extendable) = default;
65 
69  Extendable<extensions_t...>& operator=(
70  Extendable<extensions_t...>&& extendable) = default;
71 
77  template <typename... appendices_t>
78  Extendable<extensions_t..., appendices_t...> append(
79  appendices_t... aps) const {
80  auto catTuple =
81  std::tuple_cat(m_extensions, std::tuple<appendices_t...>(aps...));
82  return Extendable<extensions_t..., appendices_t...>(std::move(catTuple));
83  }
84 
88  template <typename extension_t>
89  const extension_t& get() const {
90  return std::get<extension_t>(m_extensions);
91  }
92 
96  template <typename extension_t>
97  extension_t& get() {
98  return std::get<extension_t>(m_extensions);
99  }
100 
104  const std::tuple<extensions_t...>& tuple() const { return m_extensions; }
105 
109  std::tuple<extensions_t...>& tuple() { return m_extensions; }
110 
111  private:
112  std::tuple<extensions_t...> m_extensions;
113 };
114 
115 } // namespace detail
116 } // namespace Acts