test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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> T& get_underlying( propagate_const<T>& );
35  template<typename T> T const& get_underlying( propagate_const<T> const& );
36 
37 
38  template<typename T>
39  class propagate_const
40  {
41 
42  public:
43  friend T& get_underlying<T>( propagate_const<T>& );
44  friend T const& get_underlying<T>( propagate_const<T> const& );
45 
46  using element_type = typename std::remove_reference<decltype(*std::declval<T&>())>::type;
47 
48  propagate_const() = default;
49 
50  propagate_const( propagate_const<T>&&) = default;
51  propagate_const( propagate_const<T> const&) = delete;
52  template<typename U>
53  propagate_const( U&& iValue) : m_value(std::forward<U>(iValue)) {}
54 
55 
58 
59  template<typename U>
60  propagate_const& operator=(U&& iValue) {
61  m_value = std::forward<U>(iValue);
62  return *this;
63  }
64 
65 
66 
67  // ---------- const member functions ---------------------
68  element_type const* get() const { return &(*m_value); }
69  element_type const* operator->() const { return this->get(); }
70  element_type const& operator*() const { return *m_value; }
71 
72  operator element_type const* () const { return this->get(); }
73 
74  // ---------- member functions ---------------------------
75  element_type* get() { return &(*m_value); }
76  element_type* operator->() { return this->get(); }
77  element_type& operator*() { return *m_value; }
78 
79  operator element_type* () { return this->get(); }
80 
81  private:
82 
83  // ---------- member data --------------------------------
85  };
86 
87  template<typename T> T& get_underlying( propagate_const<T>& iP) { return iP.m_value;}
88  template<typename T> T const& get_underlying( propagate_const<T> const& iP ) {return iP.m_value;}
89 
90 }
91 
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*()
long double T
element_type * operator->()
typename std::remove_reference< decltype(*std::declval< std::shared_ptr< TrackAnalysisAlgorithm > & >())>::type element_type