Skip to content

Commit

Permalink
iter_swap on transform_view::iterator is still possible
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Bucior <[email protected]>
  • Loading branch information
fsb4000 and AdamBucior committed Sep 12, 2021
1 parent a456b6c commit fc2c151
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tests/std/tests/P0896R4_views_transform/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ struct iterator_instantiator {
assert(ranges::iter_move(i0) == add8(mutable_ints[0])); // NB: moving from int leaves it unchanged
STATIC_ASSERT(NOEXCEPT_IDL0(ranges::iter_move(i0)));

// LWG-3520 forbids iter_swap for transform_view::iterator
STATIC_ASSERT(!CanIterSwap<decltype(i0)>);
}

Expand Down Expand Up @@ -776,4 +775,19 @@ int main() {

(void) views::transform(Fn{})(span<int>{});
}

{ // Validate that iter_swap works then result of transform_view is a lvalue reference
char out[] = "hello";
auto v = ranges::transform_view{out, [](char& i) -> char& { return i; }};
auto i1 = v.begin();
auto i2 = v.begin() + 1;

assert(*i1 == 'h');
assert(*i2 == 'e');

ranges::iter_swap(i1, i2);

assert(*i1 == 'e');
assert(*i2 == 'h');
}
}

0 comments on commit fc2c151

Please sign in to comment.