LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
AssnsNodeAsTuple.h
Go to the documentation of this file.
1 
11 #ifndef LARDATA_RECOBASEPROXY_PROXYBASE_ASSNSNODEASTUPLE_H
12 #define LARDATA_RECOBASEPROXY_PROXYBASE_ASSNSNODEASTUPLE_H
13 
14 // framework libraries
15 #include "canvas/Persistency/Common/Assns.h" // art::AssnsNode
17 
18 // C/C++ standard
19 #include <cstdlib> // std::size_t
20 #include <tuple> // std::tuple_element_t<>, std::get()
21 
22 // FIXME simplify this code if issue #18769 is accepted
23 namespace std {
24 
25  //----------------------------------------------------------------------------
26  //--- specializations of std::tuple interface for art::AssnsNode
27  //----------------------------------------------------------------------------
28 
29  // specialize for indices 0, 1, and 2; for all others, it's an incomplete type
30  template <typename L, typename R, typename D>
31  class tuple_element<0U, art::AssnsNode<L, R, D>> {
32  public:
33  using type = art::Ptr<L>;
34  };
35 
36  template <typename L, typename R, typename D>
37  class tuple_element<1U, art::AssnsNode<L, R, D>> {
38  public:
39  using type = art::Ptr<R>;
40  };
41 
42  template <typename L, typename R, typename D>
43  class tuple_element<2U, art::AssnsNode<L, R, D>> {
44  public:
45  using type = D const*;
46  };
47 
48  //----------------------------------------------------------------------------
49  template <std::size_t I, typename L, typename R, typename D>
50  constexpr std::tuple_element_t<I, art::AssnsNode<L, R, D>>& get(
51  art::AssnsNode<L, R, D>& t) noexcept;
52 
53  template <std::size_t I, typename L, typename R, typename D>
54  constexpr std::tuple_element_t<I, art::AssnsNode<L, R, D>>&& get(
55  art::AssnsNode<L, R, D>&& t) noexcept;
56 
57  template <std::size_t I, typename L, typename R, typename D>
58  constexpr std::tuple_element_t<I, art::AssnsNode<L, R, D>> const& get(
59  const art::AssnsNode<L, R, D>& t) noexcept;
60 
61  template <std::size_t I, typename L, typename R, typename D>
62  constexpr std::tuple_element_t<I, art::AssnsNode<L, R, D>> const&& get(
63  const art::AssnsNode<L, R, D>&& t) noexcept;
64 
65  template <class T, typename L, typename R, typename D>
66  constexpr T& get(art::AssnsNode<L, R, D>& t) noexcept;
67 
68  template <class T, typename L, typename R, typename D>
69  constexpr T&& get(art::AssnsNode<L, R, D>&& t) noexcept;
70 
71  template <class T, typename L, typename R, typename D>
72  constexpr const T& get(const art::AssnsNode<L, R, D>& t) noexcept;
73 
74  template <class T, typename L, typename R, typename D>
75  constexpr const T&& get(const art::AssnsNode<L, R, D>&& t) noexcept;
76 
77  //----------------------------------------------------------------------------
78 
79 } // namespace std
80 
81 //------------------------------------------------------------------------------
82 //--- implementation
83 //---
84 namespace util {
85  namespace details {
86 
87  //
88  // support utilities for implementation (they live outside std namespace)
89  //
90 
91  template <std::size_t I, typename L, typename R, typename D>
92  struct AssnsNodeGetter; // incomplete type, except for specializations...
93 
94  template <typename L, typename R, typename D>
95  struct AssnsNodeGetter<0U, L, R, D> {
96 
98  using Element_t = std::tuple_element_t<0U, AssnsNode_t>;
99 
100  static constexpr Element_t& get(AssnsNode_t& node) noexcept { return node.first; }
101 
102  static constexpr Element_t const& get(AssnsNode_t const& node) noexcept { return node.first; }
103 
104  static constexpr Element_t&& get(AssnsNode_t&& node) noexcept
105  {
106  return std::move(node.first);
107  }
108 
109  static constexpr Element_t const&& get(AssnsNode_t const&& node) noexcept
110  {
111  return std::move(node.first);
112  }
113 
114  }; // struct AssnsNodeGetter<0U>
115 
116  template <typename L, typename R, typename D>
117  struct AssnsNodeGetter<1U, L, R, D> {
118 
120  using Element_t = std::tuple_element_t<1U, AssnsNode_t>;
121 
122  static constexpr Element_t& get(AssnsNode_t& node) noexcept { return node.second; }
123 
124  static constexpr Element_t const& get(AssnsNode_t const& node) noexcept
125  {
126  return node.second;
127  }
128 
129  static constexpr Element_t&& get(AssnsNode_t&& node) noexcept
130  {
131  return std::move(node.second);
132  }
133 
134  static constexpr Element_t const&& get(AssnsNode_t const&& node) noexcept
135  {
136  return std::move(node.second);
137  }
138 
139  }; // struct AssnsNodeGetter<1U>
140 
141  template <typename L, typename R, typename D>
142  struct AssnsNodeGetter<2U, L, R, D> {
143 
145  using Element_t = std::tuple_element_t<2U, AssnsNode_t>;
146 
147  static constexpr Element_t& get(AssnsNode_t& node) noexcept { return node.data; }
148 
149  static constexpr Element_t const& get(AssnsNode_t const& node) noexcept { return node.data; }
150 
151  static constexpr Element_t&& get(AssnsNode_t&& node) noexcept { return std::move(node.data); }
152 
153  static constexpr Element_t const&& get(AssnsNode_t const&& node) noexcept
154  {
155  return std::move(node.data);
156  }
157 
158  }; // struct AssnsNodeGetter<2U>
159 
160  } // namespace details
161 } // namespace util
162 
163 namespace std {
164 
165  //----------------------------------------------------------------------------
166  //--- implementation of specializations of std::get() for art::AssnsNode
167  //----------------------------------------------------------------------------
168 
169  template <std::size_t I, typename L, typename R, typename D>
170  constexpr std::tuple_element_t<I, art::AssnsNode<L, R, D>>& get(
171  art::AssnsNode<L, R, D>& node) noexcept
172  {
174  }
175 
176  template <std::size_t I, typename L, typename R, typename D>
177  constexpr std::tuple_element_t<I, art::AssnsNode<L, R, D>>&& get(
178  art::AssnsNode<L, R, D>&& node) noexcept
179  {
180  return util::details::AssnsNodeGetter<I, L, R, D>::get(std::move(node));
181  }
182 
183  template <std::size_t I, typename L, typename R, typename D>
184  constexpr std::tuple_element_t<I, art::AssnsNode<L, R, D>> const& get(
185  art::AssnsNode<L, R, D> const& node) noexcept
186  {
188  }
189 
190  template <std::size_t I, typename L, typename R, typename D>
191  constexpr std::tuple_element_t<I, art::AssnsNode<L, R, D>> const&& get(
192  art::AssnsNode<L, R, D> const&& node) noexcept
193  {
194  return util::details::AssnsNodeGetter<I, L, R, D>::get(std::move(node));
195  }
196 
197  // not implemented yet:
198  template <class T, typename L, typename R, typename D>
199  constexpr T& get(art::AssnsNode<L, R, D>& t) noexcept;
200 
201  template <class T, typename L, typename R, typename D>
202  constexpr T&& get(art::AssnsNode<L, R, D>&& t) noexcept;
203 
204  template <class T, typename L, typename R, typename D>
205  constexpr const T& get(const art::AssnsNode<L, R, D>& t) noexcept;
206 
207  template <class T, typename L, typename R, typename D>
208  constexpr const T&& get(const art::AssnsNode<L, R, D>&& t) noexcept;
209 
210  //----------------------------------------------------------------------------
211 
212 } // namespace std
213 
214 // -----------------------------------------------------------------------------
215 
216 #endif // LARDATA_RECOBASEPROXY_PROXYBASE_ASSNSNODEASTUPLE_H
D const * data
Definition: AssnsNode.h:18
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:26
STL namespace.
std::tuple_element_t< 1U, AssnsNode_t > Element_t
std::tuple_element_t< 0U, AssnsNode_t > Element_t
first_type first
Definition: AssnsNode.h:16
second_type second
Definition: AssnsNode.h:17
Definition: MVAAlg.h:12
std::tuple_element_t< 2U, AssnsNode_t > Element_t