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>
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 
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 
56 
57  template <typename U>
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 ---------------------------
72  constexpr element_type* operator->() { return this->get(); }
74 
75  constexpr 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>
108  return iP.m_value;
109  }
110 
111 } // namespace edm
112 
113 #endif
static constexpr const element_type * to_raw_pointer(const Up *u)
constexpr propagate_const(U &&iValue)
constexpr element_type * operator->()
constexpr propagate_const< T > & operator=(propagate_const &&)=default
static constexpr element_type * to_raw_pointer(Up *u)
constexpr element_type const & operator*() const
constexpr T & get_underlying(propagate_const< T > &)
constexpr propagate_const & operator=(U &&iValue)
constexpr element_type & operator*()
HLT enums.
constexpr element_type const * operator->() const
constexpr propagate_const()=default
static constexpr const element_type * to_raw_pointer(const Up &u)
static constexpr element_type * to_raw_pointer(Up &u)
long double T
typename std::remove_reference< decltype(*std::declval< std::shared_ptr< C > &>())>::type element_type