Based on D100160.
Details
- Reviewers
 cjdb ldionne • Quuxplusone EricWF miscco - Group Reviewers
 Restricted Project - Commits
 - rGbdd68357901d: [libc++][ranges] iterator.concept.sizedsentinel: sized_sentinel_for and…
 
Diff Detail
- Repository
 - rG LLVM Github Monorepo
 
Event Timeline
Code looks good modulo naming; the test drags in a lot of extra dependencies it doesn't need.
| libcxx/include/iterator | ||
|---|---|---|
| 2600–2607 | I'd prefer to see _Sp and _Ip just for consistency with line 2591.  | |
| libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.sentinel/sized_sentinel_for.compile.pass.cpp | ||
| 43–48 | Instead of std::input_or_output_iterator auto, how about int*: struct IntSentinel {
    friend bool operator==(IntSentinel, int*);
    friend int operator-(IntSentinel, int*);
    friend int operator-(int*, IntSentinel);
};
static_assert(std::sized_sentinel_for<IntSentinel, int*>);
static_assert(!std::sized_sentinel_for<int*, IntSentinel>);  // IntSentinel is not an iterator | |
| 66–72 | Please avoid reopening namespace std. Just struct DoubleSentinel {
    friend bool operator==(DoubleSentinel, double*);
    friend int operator-(DoubleSentinel, double*);
    friend int operator-(double*, DoubleSentinel);
};
template<>
inline constexpr bool std::disable_sized_sentinel_for<DoubleSentinel, double*> = true;
    // notice the un-necessity of `namespace std {` here
static_assert(!std::sized_sentinel_for<DoubleSentinel, double*>); | |
| 156–163 | I don't think this test should depend on <filesystem>. (As below, all you're testing here is that you can't subtract directory_iterators, and we knew that already.)  | |
| 187–191 | These initially confused me, but then I got it: it's because these iterators are merely bidirectional, not random-access, so they don't support operator-, so they're not "sized" sentinels. I would prefer to eliminate the dependency on the associative containers and write simply e.g. #include "test_iterators.h" static_assert(std::sized_sentinel_for<random_access_iterator<int*>, random_access_iterator<int*>>); static_assert(!std::sized_sentinel_for<bidirectional_iterator<int*>, bidirectional_iterator<int*>>);  | |
| libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.sentinel/sized_sentinel_for.compile.pass.cpp | ||
|---|---|---|
| 187–191 | Reiterating from previous reviews, which this one has inherited from: the point is to make sure these types are standard conforming. The dependencies are intentional.  | |
| libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.sentinel/sized_sentinel_for.compile.pass.cpp | ||
|---|---|---|
| 187–191 | SGTM. Will do.  | |
| libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.sentinel/sized_sentinel_for.compile.pass.cpp | ||
|---|---|---|
| 156–163 | 
 Which existing tests confirm this isn't possible?  | |
LGTM % comments — fix the nits and land it!
| libcxx/test/std/iterators/iterator.requirements/iterator.concepts/iterator.concept.sentinel/sized_sentinel_for.compile.pass.cpp | ||
|---|---|---|
| 40–42 | Please remove constexpr.  | |
| 45–47 | Nit: Either break the line between ; and //, or simply s/int_sized_sentinel/IntSentinel/ so that you don't need to break the line.  | |
| 54 | s/std::vector<int>::iterator/int*/; then you don't need to break the line.  | |
| 57 | Add: not_copyable() = default;  | |
| 110–111 | Remove this linebreak. Ditto through the end of the file.  | |
| 131–132 | s/std::vector<int>::iterator/int*/g so that you don't have to break the line.  | |
Please move all iterator concept conformance tests into their appropriate files (including re-adding any iterators that might have been deleted previously).
- Unindent comment that got moved.
 
| libcxx/include/__iterator/concepts.h | ||
|---|---|---|
| 111 ↗ | (On Diff #339398) | Any ideas as to why clang format wants to move this comment?  | 
| libcxx/include/__iterator/concepts.h | ||
|---|---|---|
| 111 ↗ | (On Diff #339402) | 
 This diff moved the phab comment 🤦. This is the code comment I'm talking about.  | 
std::list hasn't had its conformance test updated, but otherwise I have one nit.
| libcxx/test/std/containers/associative/map/iterator_concept_conformance.compile.pass.cpp | ||
|---|---|---|
| 33–34 ↗ | (On Diff #339402) | This should be for iterator, and is missing checks for iterator and const_iterator on the RHS. Same for other files too.  | 
| 44–45 ↗ | (On Diff #339402) | Missing checks for iterator and const_iterator on the RHS. Same for other files too.  | 
| libcxx/test/std/containers/sequences/array/iterator_concept_conformance.compile.pass.cpp | ||
| 42–60 ↗ | (On Diff #339402) | Could we order these as if they were a set of increasing two digit numbers please? iterator: 0 I think that will make it easier to track that all have been accounted for in the right permutation.  | 
| libcxx/test/std/containers/unord/unord.map/iterator_concept_conformance.compile.pass.cpp | ||
| 61 ↗ | (On Diff #339402) | local_iterator and const_local_iterator need checking too please.  | 
std::list still hasn't had its conformance test updated.
| libcxx/test/std/containers/sequences/deque/iterator_concept_conformance.compile.pass.cpp | ||
|---|---|---|
| 53–61 ↗ | (On Diff #339462) | Thos lot isn't necessary (std::reverse_iterator gets its own file so it doesn't need to be on the LHS, but it looks to me like that file is missing?).  | 
std::list still hasn't had its conformance test updated.
For any future reviewers: this is done.
By the way, the windows bots were failing (everything else passed) because I didn't have an XFAIL on the added test but I added that before committing.
I'd prefer to see _Sp and _Ip just for consistency with line 2591.