[libcxx-commits] [PATCH] D94807: [libc++] Rationalize our treatment of contiguous iterators and __unwrap_iter().

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jan 15 10:17:40 PST 2021

Quuxplusone created this revision.
Quuxplusone added reviewers: ldionne, EricWF, rnk.
Quuxplusone added a project: libc++.
Herald added a subscriber: mgorny.
Quuxplusone requested review of this revision.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

- Expose `contiguous_iterator_tag` in all modes, not just C++20.
- Implement C++20's changes to `reverse_iterator`, so that it won't be accidentally counted as a contiguous iterator.
- Implement C++20's changes to `move_iterator` as well.
- `move_iterator` should not be contiguous. This fixes a bug where we optimized `std::copy`-of-move-iterators in an observable way. Add a regression test for that bugfix.
- Add libcxx tests for `__is_cpp17_contiguous_iterator` of all relevant standard iterator types.
- Expose `{reverse,move}_iterator::iterator_concept` in all language modes, not just C++20 mode. This isn't needed AFAIK, but it just reduces the number of differences we have to keep track of, so I think it's good.

If this passes the test suite, then I expect this to solve the issue reported by @rnk in D92776 <https://reviews.llvm.org/D92776>. They should just be able to write a conforming contiguous iterator according to https://stackoverflow.com/questions/65712091/in-c20-how-do-i-write-a-contiguous-iterator and libc++ will guarantee that it works (i.e. is optimized in std::copy) even in pre-C++20 modes.

I don't know how to test this "guarantee," though, since the optimization is unobservable by definition.

I would also like to rename `__unwrap_iter(x)` to something like `__unwrap_contiguous_iter(x)` or `__lower_contiguous_iter(x)`, to better reflect its purpose; but I didn't want to do that in this patch because it would just add icky diffs at all the call-sites.

  rG LLVM Github Monorepo



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94807.317010.patch
Type: text/x-patch
Size: 40231 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210115/b525069f/attachment-0001.bin>

More information about the libcxx-commits mailing list