Simplify the implementation of std::copy and std::move by using __unwrap_iter and __rewrap_iter to unwrap and rewrap reverse_iterator<reverse_iterator<Iter>> instead of specializing __copy_impl and __move_impl.
Details
- Reviewers
ldionne Mordante var-const - Group Reviewers
Restricted Project - Commits
- rGfb3477a4dab0: [libc++] Unwrap reverse_iterator<reverse_iterator<Iter>> in __unwrap_iter
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
I like this approach! I think the test coverage should be a bit higher.
libcxx/include/__algorithm/unwrap_iter.h | ||
---|---|---|
69 | In general we avoid using auto as return type. | |
libcxx/test/libcxx/algorithms/unwrap_iter.compile.pass.cpp | ||
9 ↗ | (On Diff #434264) | The unwrap iterator is supported in C++11 and C++14. |
14 ↗ | (On Diff #434264) | I would like to see some additional tests using Standard containers that use wrapped iterator. I also would like to see some runtime tests for these containers verifying the result has the expected value. The copy test above only test with an array. |
- Address comments
libcxx/test/libcxx/algorithms/unwrap_iter.compile.pass.cpp | ||
---|---|---|
14 ↗ | (On Diff #434264) | What is the difference between the first and the second request? |
libcxx/include/__algorithm/unwrap_iter.h | ||
---|---|---|
14–15 | We should include __iterator/iterator_traits.h here instead, and then specialize __unwrap_iter_impl for reverse_iterator<reverse_iterator<T>> from reverse_iterator.h. That way, we don't need to pull the whole world into unwrap_iter.h, and we don't need to overload __unwrap_iter(...), which wasn't meant for that (we used to overload it but then we moved to specializing __unwrap_iter_impl as a customization point instead). | |
108–112 | I think it would be cleaner not to reuse the same __rewrap_iter overload set for this. We could have one "top level" entry point for reverse_iterator<reverse_iterator<...>> and then use a helper function to do the actual rewrapping. One motivation for this is that I'd like to move to a specialization based customization point for this as well in the future. | |
libcxx/test/libcxx/algorithms/alg.modifying.operations/copy.pass.cpp | ||
170 | Since we handle more than 2 layers of reverse_iterator, we should test it. | |
libcxx/test/libcxx/algorithms/unwrap_iter.pass.cpp | ||
1 ↗ | (On Diff #435320) | libcxx/test/libcxx/iterators/<something>.pass.cpp? |
LGTM pending CI
libcxx/test/libcxx/algorithms/alg.modifying.operations/copy.pass.cpp | ||
---|---|---|
157 | test_normal_reveRse |
We should include __iterator/iterator_traits.h here instead, and then specialize __unwrap_iter_impl for reverse_iterator<reverse_iterator<T>> from reverse_iterator.h. That way, we don't need to pull the whole world into unwrap_iter.h, and we don't need to overload __unwrap_iter(...), which wasn't meant for that (we used to overload it but then we moved to specializing __unwrap_iter_impl as a customization point instead).