references.hpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Ifdefs
13 *****************************************************************************/
14 
15 #ifndef ECL_UTILITIES_REFERENCE_WRAPPER_HPP_
16 #define ECL_UTILITIES_REFERENCE_WRAPPER_HPP_
17 
18 /*****************************************************************************
19 ** Includes
20 *****************************************************************************/
21 
22 #include <ecl/mpl/bool.hpp>
23 
24 /*****************************************************************************
25 ** Wrappers
26 *****************************************************************************/
27 
28 namespace ecl {
29 
38 template <typename T>
39 T* addressOf( T & v ) {
40  return reinterpret_cast<T*>(
41  &const_cast<char&>(reinterpret_cast<const volatile char &>(v)));
42 }
84 template<typename T>
86 
87 public:
88  typedef T type;
98 
99  virtual ~ReferenceWrapper() {}
100 
109  operator T& () const { return *obj_ptr; }
110 
118  T& reference() const { return *obj_ptr; }
119 
127  T* pointer() const { return *obj_ptr; }
128 
129 private:
131 };
132 
133 /*****************************************************************************
134 ** Utility Functions
135 *****************************************************************************/
136 
144 template <typename T>
145 ReferenceWrapper<T> ref(T &wrapped_object) {
146  return ReferenceWrapper<T>(wrapped_object);
147 }
148 
156 template <typename T>
157 ReferenceWrapper<T const> cref(T const &wrapped_object) {
158  return ReferenceWrapper<T const>(wrapped_object);
159 }
160 
169 template <typename T>
170 class is_reference_wrapper : public False {};
171 
179 template <typename T>
181 
182 } // namespace ecl
183 
184 
185 #endif /* ECL_UTILITIES_REFERENCE_WRAPPER_HPP_ */
T * pointer() const
Accessor to a pointer to the original instance.
Definition: references.hpp:127
T * addressOf(T &v)
Returns the address of an object (uses correct c++ syntactics).
Definition: references.hpp:39
Embedded control libraries.
ReferenceWrapper< T const > cref(T const &wrapped_object)
Definition: references.hpp:157
virtual ~ReferenceWrapper()
Definition: references.hpp:99
Provides a wrapper which allows the original object to be passed like a reference.
Definition: references.hpp:85
T & reference() const
Accessor to the reference of the original instance.
Definition: references.hpp:118
Default action for detection of the reference wrapper type trait (false).
Definition: references.hpp:170
ReferenceWrapper< T > ref(T &wrapped_object)
Definition: references.hpp:145
ReferenceWrapper(T &t)
Constructs the wrapper around the supplied object instance.
Definition: references.hpp:97


ecl_utilities
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:28