This is an archive of the discontinued LLVM Phabricator instance.

[libc++] Unwrap reverse_iterator<reverse_iterator<Iter>> in __unwrap_iter
ClosedPublic

Authored by philnik on Jun 4 2022, 6:12 AM.

Details

Summary

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.

Diff Detail

Event Timeline

philnik created this revision.Jun 4 2022, 6:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2022, 6:12 AM
philnik requested review of this revision.Jun 4 2022, 6:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2022, 6:12 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript

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.

philnik updated this revision to Diff 435320.Jun 8 2022, 2:05 PM
philnik marked 2 inline comments as done.
  • 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?

ldionne requested changes to this revision.Jun 9 2022, 8:22 AM
ldionne added inline comments.
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
171

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?

This revision now requires changes to proceed.Jun 9 2022, 8:22 AM
philnik updated this revision to Diff 436127.Jun 11 2022, 4:53 AM
philnik marked 4 inline comments as done.
  • Address comments
philnik updated this revision to Diff 436128.Jun 11 2022, 4:53 AM

Fix patch

philnik updated this revision to Diff 436291.Jun 13 2022, 1:31 AM
  • Try to fix CI
ldionne accepted this revision.Jun 16 2022, 11:14 AM

LGTM pending CI

libcxx/test/libcxx/algorithms/alg.modifying.operations/copy.pass.cpp
158

test_normal_reveRse

This revision is now accepted and ready to land.Jun 16 2022, 11:14 AM
philnik updated this revision to Diff 437852.Jun 17 2022, 4:55 AM
  • Try to fix CI
philnik updated this revision to Diff 437886.Jun 17 2022, 7:00 AM
philnik marked an inline comment as done.
  • Try to fix CI