STL offers std::to_address under <memory>
for this purpose starting in C++ 20. Looking at the implementation for MSVC, it seems to revolve around manually calling operator->
, so this could be another option in older language versions. This has the advantage of also working with raw pointers, useful in template scenarios where the exact pointer type can vary.