The majority of the changes here are whitespace. Also simplify `ThrowingIterator`'s bookkeeping (NFC). Also move some free operators into hidden friends, for sanity's sake. Also `=delete` some more comma operators. Also use `constexpr` in C++20 instead of `TEST_CONSTEXPR_CXX14`.
Details
- Reviewers
cjdb ldionne zoecarver - Group Reviewers
Restricted Project - Commits
- rG7ba3627b5464: [libc++] Clean up test_iterators.h. NFCI.
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
The suggested changes from D102020 don't properly consider the design of this type, nor its surrounding ecosystem. Please do not merge it, and instead use the appropriate helper types that are already in test_iterators.h.
libcxx/test/support/test_iterators.h | ||
---|---|---|
635–638 | Why? This is a move-only iterator, which only makes sense in ranges land. | |
639–642 | Why? | |
666 | This overload needs to keep its [[nodiscard]]. | |
667–669 | Iterators don't have sentinel sub-types. We have a sentinel_wrapper for that. |
libcxx/test/support/test_iterators.h | ||
---|---|---|
639–642 | Upon further thought, removing this opens a gaping hole for when a I satisfies std::input_iterator, but not _`cpp17-input-iterator`_ and doesn't result in the primary template for iterator_traits. |
libcxx/test/support/test_iterators.h | ||
---|---|---|
635–638 | It makes sense anywhere it compiles, which is to say >=14. | |
639–642 | '14-compatibility. | |
666 | IMO, no, the [[nodiscard]] was just noise. We don't need to [[nodiscard]] everything in sight: we don't [[nodiscard]] operator*, for example, even though "obviously" any test code that actually discarded the result of *it would probably have a bug, just as much as any test code that actually discarded the result of it.base(). | |
667–669 | Hm. I don't particularly dislike sentinel_wrapper. At worst it's a tiny bit more verbose: compare the angle-bracketiness of alternatives some_function<cpp20_input_iterator<int*>, sentinel_wrapper<cpp20_input_iterator<int*>>>(); some_function<cpp20_input_iterator<int*>, cpp20_input_iterator<int*>::sentinel>(); (Right now sentinel_wrapper is used only in "range.iter.ops.advance/advance.pass.cpp".) I'm okay eliminating this diff for now, pending some examples of how sentinel{,_wrapper} would be used in real test cases. Certainly if we're adding sentinel we should also be refactoring some existing tests to show how it's an improvement — if it's not an improvement then we shouldn't do it. | |
859–860 | Please void operator&() const DELETE_FUNCTION; while you're at it. |
libcxx/test/support/test_iterators.h | ||
---|---|---|
635–638 | Yeah, no. This isn't useful in C++14, so it shouldn't be available. Not to mention that it depends on std::iter_value_t and std::iter_difference_t. | |
667–669 |
sentinel_wrapper is the sentinel version of our iterator wrappers; if your hard disk has a limited amount of free space where each byte counts, you'd be doing yourself a disservice as we'd need to duplicate this code for each of our other iterators too.
It's also used in range.iter.ops/range.iter.ops.next. I should fix up range.iter.ops/range.iter.ops.prev to use it too.
If, by "real test cases", you mean "more test cases" (those places where it's used today seem real to me): those should start to flow in when algorithms start to get committed.
It's a bit hard to refactor code that doesn't exist yet, but here's an example of what might exist in the near future. auto v = std::vector{1, 2, 3}; std::ranges::find(v.begin(), sentinel_wrapper(v.end()), 0); |
Are we doing this?
Basically nah; some of this has already been committed elsewhere (e.g. removing [[nodiscard]]) and the rest is not obviously good anymore.
But I've just done a new pass over test_iterators.h and recommend these new changes. There was a surprising amount of misindentation in ThrowingIterator!
LGTM when CI passes.
I'd rather keep the old formulations for operations in ThrowingIterator, but it's non-blocking.
libcxx/test/support/test_iterators.h | ||
---|---|---|
564 | I'd rather not make this change here and instead keep the previous formulations for if (action_ == ...) if (index_ == 0) ... |
Oops, contiguous_iterator's operator, was already deleted (just not at the bottom of the class like the others).
Considered moving all the other iterators' operators into hidden friends (above their deleted operator,s), and then decided that that was too big an edit; might make that PR later. I don't immediately see why random_access_iterator<T> should be comparable to random_access_iterator<U>, but I could imagine us relying on that somehow in some test.
I'd rather not make this change here and instead keep the previous formulations for if (action_ == ...) if (index_ == 0) ...