ToElement.h
Go to the documentation of this file.
1 #ifndef lardata_ArtDataHelper_ToElement_h
2 #define lardata_ArtDataHelper_ToElement_h
3 
4 // 'to_element' is a small function object that can be presented to a
5 // transform algorithm, enabling iteration over the underlying
6 // reference instead of the Ptr (e.g.):
7 //
8 // using lar::to_element;
9 // std::vector<art::Ptr<recob::Hit>> hits = from_somewhere();
10 // for (recob::Hit const& hit : hits | ranges::views::transform(to_element)) {
11 // ...
12 // }
13 
15 
16 namespace lar {
17  struct to_element_t {
18  template <typename T>
19  T const& operator()(art::Ptr<T> const& ptr) const {
20  return *ptr;
21  }
22  };
23 
24  inline constexpr to_element_t to_element;
25 }
26 
27 #endif // lardata_ArtDataHelper_ToElement_h
constexpr to_element_t to_element
Definition: ToElement.h:24
T const & operator()(art::Ptr< T > const &ptr) const
Definition: ToElement.h:19
LArSoft-specific namespace.
Definition: fwd.h:31