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>
35  constexpr T& get_underlying(propagate_const<T>&);
36  template <typename T>
37  constexpr T const& get_underlying(propagate_const<T> const&);
38 
39  template <typename T>
40  class propagate_const {
41  public:
42  friend constexpr T& get_underlying<T>(propagate_const<T>&);
43  friend constexpr 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  constexpr propagate_const() = default;
48 
49  constexpr propagate_const(propagate_const<T>&&) = default;
50  propagate_const(propagate_const<T> const&) = delete;
51  template <typename U>
52  constexpr propagate_const(U&& iValue) : m_value(std::forward<U>(iValue)) {}
53 
54  constexpr propagate_const<T>& operator=(propagate_const&&) = default;
56 
57  template <typename U>
58  constexpr propagate_const& operator=(U&& iValue) {
59  m_value = std::forward<U>(iValue);
60  return *this;
61  }
62 
63  // ---------- const member functions ---------------------
64  constexpr element_type const* get() const { return to_raw_pointer(m_value); }
65  constexpr element_type const* operator->() const { return this->get(); }
66  constexpr element_type const& operator*() const { return *m_value; }
67 
68  constexpr operator element_type const *() const { return this->get(); }
69 
70  // ---------- member functions ---------------------------
71  constexpr element_type* get() { return to_raw_pointer(m_value); }
72  constexpr element_type* operator->() { return this->get(); }
73  constexpr element_type& operator*() { return *m_value; }
74 
75  constexpr operator element_type*() { return this->get(); }
76 
77  private:
78  template <typename Up>
79  static constexpr element_type* to_raw_pointer(Up* u) {
80  return u;
81  }
82 
83  template <typename Up>
84  static constexpr element_type* to_raw_pointer(Up& u) {
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  constexpr T const& get_underlying(propagate_const<T> const& iP) {
108  return iP.m_value;
109  }
110 
111 } // namespace edm
112 
113 #endif
edm::propagate_const::get
constexpr element_type * get()
Definition: propagate_const.h:71
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::propagate_const::get
constexpr element_type const * get() const
Definition: propagate_const.h:64
edm::propagate_const::operator->
constexpr element_type * operator->()
Definition: propagate_const.h:72
edm::propagate_const
Definition: propagate_const.h:32
edm::propagate_const::to_raw_pointer
static constexpr const element_type * to_raw_pointer(const Up *u)
Definition: propagate_const.h:89
edm::propagate_const::propagate_const
constexpr propagate_const(U &&iValue)
Definition: propagate_const.h:52
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
edm::propagate_const::m_value
T m_value
Definition: propagate_const.h:99
edm::propagate_const::operator*
constexpr element_type const & operator*() const
Definition: propagate_const.h:66
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
edm::propagate_const::to_raw_pointer
static constexpr element_type * to_raw_pointer(Up *u)
Definition: propagate_const.h:79
edm::get_underlying
constexpr T & get_underlying(propagate_const< T > &)
Definition: propagate_const.h:103
edm::propagate_const::operator*
constexpr element_type & operator*()
Definition: propagate_const.h:73
edm::propagate_const::propagate_const
constexpr propagate_const()=default
edm::propagate_const::operator=
constexpr propagate_const & operator=(U &&iValue)
Definition: propagate_const.h:58
edm::propagate_const::operator=
constexpr propagate_const< T > & operator=(propagate_const &&)=default
edm::propagate_const::to_raw_pointer
static constexpr element_type * to_raw_pointer(Up &u)
Definition: propagate_const.h:84
std
Definition: JetResolutionObject.h:76
T
long double T
Definition: Basic3DVectorLD.h:48
edm::propagate_const::to_raw_pointer
static constexpr const element_type * to_raw_pointer(const Up &u)
Definition: propagate_const.h:94
edm::propagate_const< std::shared_ptr< TrackAnalysisAlgorithm > >::element_type
typename std::remove_reference< decltype(*std::declval< std::shared_ptr< TrackAnalysisAlgorithm > & >())>::type element_type
Definition: propagate_const.h:45
edm::propagate_const::operator->
constexpr element_type const * operator->() const
Definition: propagate_const.h:65