Page MenuHomePhabricator

[libc++] Fix LWG3390: move_iterator now handles move-only iterators.

Authored by Quuxplusone on Jan 14 2022, 8:28 AM.



This can't really be tested until C++20 move_iterator is completely implemented, but I'm working on that.

Depends on D117324.

Diff Detail

Event Timeline

Quuxplusone requested review of this revision.Jan 14 2022, 8:28 AM
Quuxplusone created this revision.
Herald added 1 blocking reviewer(s): Restricted Project. · View Herald TranscriptJan 14 2022, 8:28 AM

This can't really be tested until C++20 move_iterator is completely implemented, but I'm working on that.

Can't we add a simple test with a move_iterator constructed from a non-copyable iterator and ensure that works? What else is missing?

This LGTM but I'd like to see tests for this, so I'll wait to see the child revisions I assume you're about to upload.

@ldionne: I've uploaded my proposed test now, but as it turns out, it fails because move_it.base() returns by-value in C++17; actually pulling out the .base() of a move-only move_iterator requires the C++20 changes to make .base() return by-const-ref.

I'd still prefer to land this as-is (without that test for now), but I guess I could also abandon this. My original rationale for opening this individually was that this is a (minor) change to the pre-C++20 behavior — it now moves instead of copying. I think everything else I'm doing affects our behavior only in C++20-and-later.

(Okay, so technically this behavior is observable and therefore testable pre-C++20; I'd just have to make a local iterator type that is both copy-ctable and move-ctable, but its copy-ctor counts the number of times it's called, and verify that make_move_iterator(CountingItType()) never calls the copy-ctor. But that seems like overkill, IMVHO.)

ldionne accepted this revision.Jan 24 2022, 8:22 AM

Ahh I see. Fine with this as-is without the test. I like to have a single commit for this LWG issue. My understanding is that you will then test that (and more) in D117656.

This revision is now accepted and ready to land.Jan 24 2022, 8:22 AM
This revision was landed with ongoing or failed builds.Jan 26 2022, 8:50 PM
This revision was automatically updated to reflect the committed changes.