|
Boost : |
From: Brad King (brad.king_at_[hidden])
Date: 2002-04-03 13:41:18
Hello,
During the discussion of possible new C++ features, I think someone
mentioned an "addressof()" feature that would give the real address of
an object even if it overloads operator&(). Doug Gregor and I
recently realized that it may be possible to implement this in a
library.
Ignoring cv-qualifiers, this may work:
template <typename T>
T* address_of(T& v)
{
struct address_of_helper {};
return reinterpret_cast<T*>(&reinterpret_cast<address_of_helper&>(v));
}
The relevent paragraph in the '98 standard appears to be 5.2.10/10. If
this indeed will work, it may be worth adding to boost, perhaps in
boost/utility.hpp.
Thoughts?
-Brad
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk