[libcxx-commits] [PATCH] D128744: [libc++][ranges] Implement `ranges::partial_sort`.

Hui via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sat Jul 9 19:51:36 PDT 2022


huixie90 added inline comments.


================
Comment at: libcxx/include/__algorithm/make_heap.h:30
 {
     typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
     difference_type __n = __last - __first;
----------------
huixie90 wrote:
> For C++20 algorithms, we should use `iter_difference_t `.
> 
> the `difference_type` is coming from `incrementable_traits` when `iterator_traits` is not specialized
> 
> (Note this applies to all other usages of `difference_type`)
Actually, it is fine for this algorithm to use iterator_traits

since the input are required to model c++20 random_access_iterator and C++ 20 random_access_iterator implies c++17 input iterator and that makes sure that iterator_traits exists and consistent with c++20’s iter_differnece_t (and iter_value_t for the value_type)

I think this can be a problem only in algorithms that take c++20 input iterators, because c++ 20 input_iterators can have empty iterator_traits


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D128744



More information about the libcxx-commits mailing list