Provides a wrapper which allows the original object to be passed like a reference. More...
#include <references.hpp>
Public Types | |
typedef T | type |
Public Member Functions | |
operator T & () const | |
Convenience operator for converting to the underlying reference directly. More... | |
T * | pointer () const |
Accessor to a pointer to the original instance. More... | |
T & | reference () const |
Accessor to the reference of the original instance. More... | |
ReferenceWrapper (T &t) | |
Constructs the wrapper around the supplied object instance. More... | |
virtual | ~ReferenceWrapper () |
Private Attributes | |
T * | obj_ptr |
Provides a wrapper which allows the original object to be passed like a reference.
This class wraps the supplied object, storing it as a pointer and allowing it to be passed like a regular object. By itself, this is not terribly useful, but in combination with the ref/cref functions and also the is_reference_wrapper trait, it allows things like functions and function objects to be easily manipulated.
Note: reference wrappers might seem a bit redundant - why do we need them? The following case illustrates a desired usage scenario.
Unfortunately, when you come to call this function, you'll get an ambiguity error.
In these situations you can use a simple function call (not ref) and pass in this reference wrapper:
T | : the type of object this class is wrapping. |
Definition at line 85 of file references.hpp.
typedef T ecl::ReferenceWrapper< T >::type |
Convenient handle to the reference wrapper's base type.
Definition at line 88 of file references.hpp.
|
inline |
Constructs the wrapper around the supplied object instance.
Constructs the wrapper around the supplied object instance.
t | : the object instance. |
Definition at line 97 of file references.hpp.
|
inlinevirtual |
Definition at line 99 of file references.hpp.
|
inline |
Convenience operator for converting to the underlying reference directly.
When used where the underlying reference is expected, this automatically handles the conversion.
Definition at line 109 of file references.hpp.
|
inline |
Accessor to a pointer to the original instance.
Returns a pointer to the wrapped object.
Definition at line 127 of file references.hpp.
|
inline |
Accessor to the reference of the original instance.
Returns a reference to the wrapped object.
Definition at line 118 of file references.hpp.
|
private |
Definition at line 130 of file references.hpp.