Use std::addressof
.
You can think of it as doing the following behind the scenes:
- Reinterpret the object as a reference-to-char
- Take the address of that (won’t call the overload)
- Cast the pointer back to a pointer of your type.
Existing implementations (including Boost.Addressof) do exactly that, just taking additional care of const
and volatile
qualification.