[PATCH] D58088: [adt] Add raw_pointer_iterator to iterate over std::unique_ptr<> collections

Daniel Sanders via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 18 17:41:56 PST 2019


dsanders added a comment.

In D58088#1401583 <https://reviews.llvm.org/D58088#1401583>, @dblaikie wrote:

> In D58088#1396951 <https://reviews.llvm.org/D58088#1396951>, @dsanders wrote:
>
> > In D58088#1395226 <https://reviews.llvm.org/D58088#1395226>, @paquette wrote:
> >
> > > Hmm, It might be nice to have this as a specialization of `pointer_iterator` if possible.
> > >
> > > I think it might be a source of confusion/frustration to have both a `raw_pointer_iterator` and a `pointer_iterator`, where `raw_pointer_iterator` is specifically used for //only// `unique_ptr`.
> >
> >
> > I can see a way to achieve that (std::to_address()) but it requires C++20. Without that, the closest I've been able to get is a `raw_pointer_iterator` alias to `pointer_iterator` that has specializations based on whether a third optional argument is `true_type` or `false_type`. The main thing I'm missing to fold the alias in is a way to specify the default value of T in a way that resolves to either pointer_iterator's default type T or raw_pointer_iterators default type T depending on whether *Iter is a std::unique_ptr<X>& or not. I can detect the type easily enough but selecting between the two defaults is proving troublesome as it resolves the true and false cases too early and ends up trying to do int::pointer and failing because int isn't a class type.
>
>
> Would it be difficult to have LLVM's own version of std::to_address (LLVM has had/does have various type traits implmented in-tree when they aren't available in the standard LLVM's using at the moment) or similar to use here?


That looks simple enough. I haven't gone through the spec but something as simple as:

  namespace llvm {
  template<class Ptr>
  auto to_address(const Ptr &P) noexcept { return P.operator->(); }
  template<class T>
  constexpr T* to_address(T* P) noexcept { return P; }
  }

seems to cover the majority of it (and definitely the bits I need). It's just the std::pointer_traits<Ptr>::to_address(p) based implementation of the fancy pointer overload that's missing.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D58088





More information about the llvm-commits mailing list