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 &(*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 &(*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  // ---------- member data --------------------------------
80  };
81 
82  template <typename T>
84  return iP.m_value;
85  }
86  template <typename T>
87  T const& get_underlying(propagate_const<T> const& iP) {
88  return iP.m_value;
89  }
90 
91 } // namespace edm
92 
93 #endif
propagate_const & operator=(U &&iValue)
type
Definition: HCALResponse.h:21
propagate_const(U &&iValue)
T & get_underlying(propagate_const< T > &)
propagate_const< T > & operator=(propagate_const &&)=default
propagate_const()=default
element_type const * operator->() const
element_type const & operator*() const
element_type & operator*()
HLT enums.
friend T & get_underlying(propagate_const< T > &)
long double T
element_type * operator->()
typename std::remove_reference< decltype(*std::declval< std::shared_ptr< TrackAnalysisAlgorithm > & >())>::type element_type