[libc++] Rationalize our treatment of contiguous iterators and __unwrap_iter().

Authored by arthur.j.odwyer on Jan 15 2021, 9:59 AM.


[libc++] Rationalize our treatment of contiguous iterators and __unwrap_iter().

  • Implement C++20's changes to reverse_iterator, so that it won't be accidentally counted as a contiguous iterator in C++20 mode.
  • 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. Particularly check that vector::iterator is still considered contiguous in all C++ modes, even C++03.

After this patch, there continues to be no supported way to write your
own iterator type in C++17-and-earlier such that libc++ will consider it
"contiguous"; however, we now fully support the C++20 approach (in C++20
mode only). If you want user-defined contiguous iterators in C++17-and-earlier,
libc++'s position is "please upgrade to C++20."

Differential Revision: https://reviews.llvm.org/D94807