CMS 3D CMS Logo

propagate_const.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_propagate_const_h
2 #define FWCore_Utilities_propagate_const_h
3 // -*- C++ -*-
4 //
5 // Package: FWCore/Utilities
6 // Class : propagate_const
7 //
16 //
17 // Original Author: Chris Jones
18 // Created: Fri, 18 Dec 2015 14:56:12 GMT
19 //
20 
21 // system include files
22 #include <type_traits>
23 #include <utility>
24 
25 // user include files
26 
27 // forward declarations
28 
29 namespace edm {
30 
31  template <typename T>
33 
34  template <typename T>
36  template <typename T>
37  T const& get_underlying(propagate_const<T> const&);
38 
39  template <typename T>
40  class propagate_const {
41  public:
42  friend T& get_underlying<T>(propagate_const<T>&);
43  friend T const& get_underlying<T>(propagate_const<T> const&);
44 
45  using element_type = typename std::remove_reference<decltype(*std::declval<T&>())>::type;
46 
47  propagate_const() = default;
48 
50  propagate_const(propagate_const<T> const&) = delete;
51  template <typename U>
52  propagate_const(U&& iValue) : m_value(std::forward<U>(iValue)) {}
53 
56 
57  template <typename U>
59  m_value = std::forward<U>(iValue);
60  return *this;
61  }
62 
63  // ---------- const member functions ---------------------
64  element_type const* get() const { return to_raw_pointer(m_value); }
65  element_type const* operator->() const { return this->get(); }
66  element_type const& operator*() const { return *m_value; }
67 
68  operator element_type const*() const { return this->get(); }
69 
70  // ---------- member functions ---------------------------
71  element_type* get() { return to_raw_pointer(m_value); }
72  element_type* operator->() { return this->get(); }
73  element_type& operator*() { return *m_value; }
74 
75  operator element_type*() { return this->get(); }
76 
77  private:
78  template <typename Up>
80  return u;
81  }
82 
83  template <typename Up>
85  return u.get();
86  }
87 
88  template <typename Up>
89  static constexpr const element_type* to_raw_pointer(const Up* u) {
90  return u;
91  }
92 
93  template <typename Up>
94  static constexpr const element_type* to_raw_pointer(const Up& u) {
95  return u.get();
96  }
97 
98  // ---------- member data --------------------------------
100  };
101 
102  template <typename T>
104  return iP.m_value;
105  }
106  template <typename T>
107  T const& get_underlying(propagate_const<T> const& iP) {
108  return iP.m_value;
109  }
110 
111 } // namespace edm
112 
113 #endif
propagate_const & operator=(U &&iValue)
type
Definition: HCALResponse.h:21
static constexpr const element_type * to_raw_pointer(const Up *u)
propagate_const(U &&iValue)
T & get_underlying(propagate_const< T > &)
propagate_const< T > & operator=(propagate_const &&)=default
static constexpr element_type * to_raw_pointer(Up *u)
propagate_const()=default
element_type const * operator->() const
element_type const & operator*() const
element_type & operator*()
HLT enums.
static constexpr const element_type * to_raw_pointer(const Up &u)
friend T & get_underlying(propagate_const< T > &)
static constexpr element_type * to_raw_pointer(Up &u)
long double T
element_type * operator->()
#define constexpr
typename std::remove_reference< decltype(*std::declval< std::shared_ptr< TrackAnalysisAlgorithm > & >())>::type element_type