Incidentally, this removes some unqualified ADL calls to begin and end. (See also D119687.)
Details
- Reviewers
ldionne Mordante cor3ntin - Group Reviewers
Restricted Project - Commits
- rG690287b19982: [libc++] [test] Improve test coverage for std::{c,}{begin,end}.
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Nice cleanup! LGTM modulo some minor nits.
libcxx/test/std/iterators/iterator.range/begin-end.pass.cpp | ||
---|---|---|
68 | I would prefer to keep these two lines of comment. Else using il.begin() instead of il.cbegin() in`assert(std::cbegin(cil) == il.begin());` looks wrong. Same for the backward initializer list tests. I agree with removing the commented out asserts. | |
124 | Why is this test TEST_CONSTEXPR_CXX17 and the previous TEST_CONSTEXPR_CXX14? | |
160 | I like to see std::cfoo() == c.cfoo() in the tests. Testing against c.foo() looks wrong. |
libcxx/test/std/iterators/iterator.range/begin-end.pass.cpp | ||
---|---|---|
124 | std::rbegin was added in C++14, but reverse_iterator wasn't made constexpr-friendly until C++17. So rbegin went from nonexistent ('11) to runtime-only ('14) to fully constexpr ('17). | |
160 | Well, this is the flip side of your other comment about il.begin(). For every STL type that supports cbegin, it's an invariant that c.begin() == c.cbegin() and c.end() == c.cend(). But there are some STL types (e.g. initializer_list) that syntactically support only c.begin() and not c.cbegin(). So, if we were to try to use x.cbegin() everywhere in this test, we'd find there were some places that it wasn't supported and we'd have to fall back to x.begin(). Which, as you say, looks a bit wrong. The other thing to notice here — not directly relevant but might affect your mental model — is that std::cbegin(c) does not in any way invoke c.cbegin() on the container. std::cbegin(c) actually invokes std::begin(std::as_const(c)), which invokes c.begin() const. So (if everything is piped together correctly) this code is basically testing that c.begin() const == c.begin() non-const. |
libcxx/test/std/iterators/iterator.range/begin-end.pass.cpp | ||
---|---|---|
124 | I see. Something nice for another pub-quiz. | |
160 |
I see. I assumed std::cbegin(c)' invoked c.begin()… I was aware of the gotcha in initializer_list`. In that case I agree that the current code is better. I suggest to add some comment regarding this design choice. This avoids future "fixes" to change c.foo() to c.cfoo(). |
Not sure I understand. D119677 affects the tests for std::{c,}{r,}{begin,end}, nothing to do with any particular iterator's operator!=.
I would prefer to keep these two lines of comment. Else using il.begin() instead of il.cbegin() in`assert(std::cbegin(cil) == il.begin());` looks wrong.
Same for the backward initializer list tests.
I agree with removing the commented out asserts.