LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
operations.h
Go to the documentation of this file.
1 
10 #ifndef LARCOREALG_COREUTILS_OPERATIONS_H
11 #define LARCOREALG_COREUTILS_OPERATIONS_H
12 
13 // C++ standard library
14 #include <memory> // std::addressof()
15 
16 namespace util {
17 
18  //----------------------------------------------------------------------------
34  struct AddressTaker {
35 
37  template <typename T>
38  auto operator()(T& ref) const
39  {
40  return std::addressof(ref);
41  }
42 
43  }; // struct AddressTaker
44 
85  decltype(auto) takeAddress()
86  {
87  return AddressTaker();
88  }
89 
90  //----------------------------------------------------------------------------
104  struct Dereferencer {
105 
107  template <typename T>
108  decltype(auto) operator()(T&& ptr) const
109  {
110  return *ptr;
111  }
112 
113  }; // struct Dereferencer
114 
128  decltype(auto) dereference()
129  {
130  return Dereferencer();
131  }
132 
133  //----------------------------------------------------------------------------
134 
135 } // namespace util
136 
137 #endif // LARCOREALG_COREUTILS_OPERATIONS_H
Namespace for general, non-LArSoft-specific utilities.
Definition: PIDAAlg.h:26
decltype(auto) takeAddress()
Returns a functor that returns the address of its argument.
Definition: operations.h:85
Functor returning the address in memory of the operand.
Definition: operations.h:34
auto operator()(T &ref) const
Returns the address of the argument.
Definition: operations.h:38
decltype(auto) dereference()
Returns a functor that returns *ptr of its argument ptr.
Definition: operations.h:128
Functor dereferencing the operand.
Definition: operations.h:104