Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make join_view and join_with_view iterators default-constructible (the forgotten part of P2770R0) #4264

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -3809,9 +3809,7 @@ namespace ranges {
using value_type = range_value_t<_InnerRng<_Const>>;
using difference_type = common_type_t<range_difference_t<_Base>, range_difference_t<_InnerRng<_Const>>>;

// clang-format off
_Iterator() requires default_initializable<_OuterIter> = default;
// clang-format on
_Iterator() = default;

constexpr _Iterator(_Iterator<!_Const> _It)
requires _Const && convertible_to<iterator_t<_Vw>, _OuterIter>
Expand Down Expand Up @@ -4265,9 +4263,7 @@ namespace ranges {
using value_type = common_type_t<iter_value_t<_InnerIter>, iter_value_t<_PatternIter>>;
using difference_type = _Common_diff_t<_OuterIter, _InnerIter, _PatternIter>;

// clang-format off
_Iterator() requires default_initializable<_OuterIter> = default;
// clang-format on
_Iterator() = default;

constexpr _Iterator(_Iterator<!_Const> _It)
requires _Const && convertible_to<iterator_t<_Vw>, _OuterIter>
Expand Down
3 changes: 0 additions & 3 deletions tests/libcxx/expected_results.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1206,9 +1206,6 @@ std/ranges/range.adaptors/range.join/range.join.iterator/star.pass.cpp:0 FAIL
# Not analyzed. constexpr evaluation fails in ranges::swap.
std/ranges/range.adaptors/range.join/range.join.iterator/iter.swap.pass.cpp:0 FAIL

# Not analyzed. Fails static_assert(std::is_default_constructible_v<JoinIterator>).
std/ranges/range.adaptors/range.join/range.join.iterator/ctor.default.pass.cpp FAIL

# Not analyzed. constexpr evaluation fails in assert(element_moved == 1).
std/ranges/range.adaptors/range.lazy.split/ctor.range.pass.cpp:0 FAIL
std/ranges/range.adaptors/range.split/ctor.range.pass.cpp:0 FAIL
Expand Down
10 changes: 10 additions & 0 deletions tests/std/tests/P0896R4_views_join/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,16 @@ constexpr bool test_one(Outer&& rng, Expected&& expected) {
}
}

// Also validate that join_view iterators are default-constructible
{
STATIC_ASSERT(is_default_constructible_v<iterator_t<R>>);
[[maybe_unused]] iterator_t<R> i;
if constexpr (CanMemberBegin<const R>) {
STATIC_ASSERT(is_default_constructible_v<iterator_t<const R>>);
[[maybe_unused]] iterator_t<const R> ci;
}
}

// Validate join_view::end
static_assert(CanMemberEnd<R>);
static_assert(CanMemberEnd<const R>
Expand Down
10 changes: 10 additions & 0 deletions tests/std/tests/P2441R2_views_join_with/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ constexpr void test_one(Outer&& rng, Delimiter&& delimiter, Expected&& expected)
}
}

// Also validate that join_with_view iterators are default-constructible
{
STATIC_ASSERT(is_default_constructible_v<iterator_t<R>>);
[[maybe_unused]] iterator_t<R> i;
if constexpr (CanMemberBegin<const R>) {
STATIC_ASSERT(is_default_constructible_v<iterator_t<const R>>);
[[maybe_unused]] iterator_t<const R> ci;
}
}

// Validate join_with_view::end
static_assert(CanMemberEnd<R>);
static_assert(CanMemberEnd<const R>
Expand Down