[PATCH] D58421: Add partial implementation of std::to_address() as llvm::to_address()

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 20 10:01:46 PST 2019


dsanders added inline comments.


================
Comment at: include/llvm/ADT/STLExtras.h:1589-1592
+template <class Ptr>
+typename Ptr::element_type *to_address(const Ptr &P) noexcept {
+  return P.operator->();
+}
----------------
dblaikie wrote:
> dexonsmith wrote:
> > Can you use `decltype(std::declval<Ptr>().operator->())` instead of `typename Ptr::element_type *` to avoid requiring an `element_type` typedef?
> Yep, or late bound return:
> 
>   auto to_address(const Ptr &P) -> decltype(P.operator->()) { return P.operator->(); }
> 
> Also probably leave off the noexcept - LLVM doesn't build with exceptions anyway. So there's not a lot/much point in littering noexcept everywhere.
I've gone with the late bound return, partly because it's a little shorter and partly because it means we just drop the -> onwards for C++14.

> Also probably leave off the noexcept - LLVM doesn't build with exceptions anyway. So there's not a lot/much point in littering noexcept everywhere.

Sure. I only included it to match the std::to_address() declaration we're implementing. As you say, it's not doing anything for LLVM


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58421/new/

https://reviews.llvm.org/D58421





More information about the llvm-commits mailing list