Closed Weeena closed 8 years ago
Does this not exist already?
/**
* \brief Retrieve the address of the stored object
*
* This function must be used with caution, as the returned address
* may not be what you expect it to be!
*
* \return Pointer to the stored object
*/
void* pointer() const;
Well, I would prefer a function that is as typesafe as get()
is. Furthermore, as the comment to pointer()
states, "This function must be used with caution": It does not handle multiple inheritance (but get()
does).
I would like to somehow withdraw my claim. I can't remember exactly how it happened, but I overlooked that I can simply apply &
to the returned reference from get()
to get the pointer to the wrapped object. (I guess I mixed it somewhat up with the fact that one cannot take a pointer to a reference.)
Ah good, sorry didn't have time to look at this today anyway.
We would like
UserObject
to have an addtional function similar toget()
that returns a pointer to the wrapped object rather than a reference (e.g. a functiongetPointer()
).Motivation: At initialization time where performance is not key we like - with the help of ponder - to prepare a data repository and some worker objects that work with the data objects in that repository. We would like to initialize those worker objects such that they store some kind of reference to the data objects. During processing time where performance is key the worker objects should have fast access to the data objects by way of the stored references.
We consider wrapping our data objects in
UserObject
s. Now, the only way to get some reference to the wrapped object is by way ofget()
which returns a referenceT&
. Alas, this reference cannot easily be stored for later use in the processing phase (and we would not like to use astd::reference_wrapper
). Hence, we would like to have a function that returns a pointer to the wrapped object and the returned pointer we can store for fast access during processing time.