AssnsNode.h
Go to the documentation of this file.
1 #ifndef canvas_Persistency_Common_AssnsNode_h
2 #define canvas_Persistency_Common_AssnsNode_h
3 
5 
6 #include <type_traits>
7 
8 namespace art {
9 
10  // for dereference return type
11  template <typename L, typename R, typename D>
12  struct AssnsNode {
13  using first_type = Ptr<L>;
15  using data_type = D;
18  D const* data{nullptr};
19  AssnsNode() = default;
20  AssnsNode(art::Ptr<L> const& l, art::Ptr<R> const& r, D const& d)
21  : first{l}, second{r}, data{&d}
22  {}
23  };
24 
25  //=======================================
26  // tuple_element<> interface
27  namespace detail {
28  template <std::size_t I, typename Node>
29  struct tuple_element;
30 
31  template <typename L, typename R, typename D>
32  struct tuple_element<0, AssnsNode<L, R, D>> {
33  using type = Ptr<L>;
34  };
35 
36  template <typename L, typename R, typename D>
37  struct tuple_element<1, AssnsNode<L, R, D>> {
38  using type = Ptr<R>;
39  };
40 
41  template <typename L, typename R, typename D>
42  struct tuple_element<2, AssnsNode<L, R, D>> {
43  using type = D;
44  };
45  }
46 
47  template <std::size_t I, typename Node>
48  struct tuple_element;
49 
50  template <std::size_t I, typename L, typename R, typename D>
51  struct tuple_element<I, AssnsNode<L, R, D>> {
53  };
54 
55  template <std::size_t I, typename Node>
57 
58  //=======================================
59  // get<> interface
60  namespace detail {
61  template <typename L, typename R, typename D>
62  struct get_helper {
64  using first_type = typename node_t::first_type;
65  using second_type = typename node_t::second_type;
66 
67  // Indexed accessors
68  template <std::size_t I>
69  static std::enable_if_t<(I == 0), tuple_element_t<I, node_t> const&>
71  {
72  return r.first;
73  }
74 
75  template <std::size_t I>
76  static std::enable_if_t<(I == 1), tuple_element_t<I, node_t> const&>
78  {
79  return r.second;
80  }
81 
82  template <std::size_t I>
83  static std::enable_if_t<(I == 2), tuple_element_t<I, node_t> const&>
85  {
86  return *r.data;
87  }
88 
89  // By-type accessors
90  template <typename T>
91  static std::enable_if_t<std::is_same_v<T, first_type>, T const&>
93  {
94  return r.first;
95  }
96 
97  template <typename T>
98  static std::enable_if_t<std::is_same_v<T, second_type>, T const&>
100  {
101  return r.second;
102  }
103 
104  template <typename T>
105  static std::enable_if_t<std::is_same_v<T, D>, T const&>
107  {
108  return *r.data;
109  }
110  };
111  }
112 
113  template <typename T, typename L, typename R, typename D>
114  auto const&
115  get(AssnsNode<L, R, D> const& r)
116  {
117  return detail::get_helper<L, R, D>::template get_element<T>(r);
118  }
119 
120  template <std::size_t I, typename L, typename R, typename D>
121  auto const&
122  get(AssnsNode<L, R, D> const& r)
123  {
124  return detail::get_helper<L, R, D>::template get_element<I>(r);
125  }
126 }
127 
128 #endif /* canvas_Persistency_Common_AssnsNode_h */
129 
130 // Local Variables:
131 // mode: c++
132 // End:
D const * data
Definition: AssnsNode.h:18
static std::enable_if_t<(I==1), tuple_element_t< I, node_t > const & > get_element(node_t const &r)
Definition: AssnsNode.h:77
static std::enable_if_t< std::is_same_v< T, first_type >, T const & > get_element(node_t const &r)
Definition: AssnsNode.h:92
AssnsNode(art::Ptr< L > const &l, art::Ptr< R > const &r, D const &d)
Definition: AssnsNode.h:20
#define D
Debug message.
Definition: tclscanner.cpp:775
static QStrList * l
Definition: config.cpp:1044
static std::enable_if_t< std::is_same_v< T, second_type >, T const & > get_element(node_t const &r)
Definition: AssnsNode.h:99
static std::enable_if_t< std::is_same_v< T, D >, T const & > get_element(node_t const &r)
Definition: AssnsNode.h:106
typename tuple_element< I, Node >::type tuple_element_t
Definition: AssnsNode.h:56
static std::enable_if_t<(I==0), tuple_element_t< I, node_t > const & > get_element(node_t const &r)
Definition: AssnsNode.h:70
static std::enable_if_t<(I==2), tuple_element_t< I, node_t > const & > get_element(node_t const &r)
Definition: AssnsNode.h:84
first_type first
Definition: AssnsNode.h:16
second_type second
Definition: AssnsNode.h:17
static QCString type
Definition: declinfo.cpp:672
AssnsNode()=default
typename node_t::second_type second_type
Definition: AssnsNode.h:65
typename node_t::first_type first_type
Definition: AssnsNode.h:64