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

Implement LWG-3712: chunk_view and slide_view should not be default_initializable #2943

Merged
merged 6 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
24 changes: 6 additions & 18 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -5248,8 +5248,8 @@ namespace ranges {
requires input_range<_Vw>
class chunk_view : public view_interface<chunk_view<_Vw>> {
private:
/* [[no_unique_address]] */ _Vw _Range{};
range_difference_t<_Vw> _Count = 0;
/* [[no_unique_address]] */ _Vw _Range;
range_difference_t<_Vw> _Count;
range_difference_t<_Vw> _Remainder = 0;
_Non_propagating_cache<iterator_t<_Vw>> _Current{};

Expand Down Expand Up @@ -5430,10 +5430,6 @@ namespace ranges {
};

public:
// clang-format off
chunk_view() requires default_initializable<_Vw> = default;
// clang-format on

constexpr explicit chunk_view(_Vw _Range_, const range_difference_t<_Vw> _Count_) noexcept(
is_nothrow_move_constructible_v<_Vw>) /* strengthened */
: _Range(_STD move(_Range_)), _Count{_Count_} {
Expand Down Expand Up @@ -5477,8 +5473,8 @@ namespace ranges {
requires forward_range<_Vw>
class chunk_view<_Vw> : public view_interface<chunk_view<_Vw>> {
private:
/* [[no_unique_address]] */ _Vw _Range{};
range_difference_t<_Vw> _Count = 0;
/* [[no_unique_address]] */ _Vw _Range;
range_difference_t<_Vw> _Count;

template <bool _Const>
class _Iterator {
Expand Down Expand Up @@ -5690,10 +5686,6 @@ namespace ranges {
};

public:
// clang-format off
chunk_view() requires default_initializable<_Vw> = default;
// clang-format on

constexpr explicit chunk_view(_Vw _Range_, const range_difference_t<_Vw> _Count_) noexcept(
is_nothrow_move_constructible_v<_Vw>) /* strengthened */
: _Range(_STD move(_Range_)), _Count{_Count_} {
Expand Down Expand Up @@ -5818,8 +5810,8 @@ namespace ranges {
requires view<_Vw>
class slide_view : public _Cached_position_t<!_Slide_caches_nothing<_Vw>, _Vw, slide_view<_Vw>> {
private:
/* [[no_unique_address]] */ _Vw _Range{};
range_difference_t<_Vw> _Count = 0;
/* [[no_unique_address]] */ _Vw _Range;
range_difference_t<_Vw> _Count;

template <class>
class _Iter_base {};
Expand Down Expand Up @@ -6052,10 +6044,6 @@ namespace ranges {
};

public:
// clang-format off
slide_view() requires default_initializable<_Vw> = default;
// clang-format on

constexpr explicit slide_view(_Vw _Range_, const range_difference_t<_Vw> _Count_) noexcept(
is_nothrow_move_constructible_v<_Vw>) /* strengthened */
: _Range(_STD move(_Range_)), _Count{_Count_} {}
Expand Down
9 changes: 9 additions & 0 deletions tests/std/tests/P2442R1_views_chunk/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ constexpr bool test_one(Rng&& rng, Expected&& expected) {
STATIC_ASSERT(forward_range<R> == forward_range<Rng>);
STATIC_ASSERT(bidirectional_range<R> == bidirectional_range<Rng>);
STATIC_ASSERT(random_access_range<R> == random_access_range<Rng>);
// Validate non-default-initializability
STATIC_ASSERT(!is_default_constructible_v<R>);
STATIC_ASSERT(!default_initializable<R>);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change requested: test_one() is called for both input-only and forward ranges, so this covers the LWG issue's modifications to both the primary template and the specialization for forward ranges.

CaseyCarter marked this conversation as resolved.
Show resolved Hide resolved
// Validate borrowed_range
STATIC_ASSERT(ranges::borrowed_range<R> == (ranges::borrowed_range<V> && forward_range<V>) );

Expand All @@ -59,6 +62,9 @@ constexpr bool test_one(Rng&& rng, Expected&& expected) {
using RC = chunk_view<views::all_t<const remove_reference_t<Rng>&>>;
constexpr bool is_noexcept = !is_view || is_nothrow_copy_constructible_v<V>;

STATIC_ASSERT(!is_default_constructible_v<RC>);
STATIC_ASSERT(!default_initializable<RC>);

STATIC_ASSERT(same_as<decltype(views::chunk(as_const(rng), 2)), RC>);
STATIC_ASSERT(noexcept(views::chunk(as_const(rng), 2)) == is_noexcept);

Expand All @@ -72,6 +78,9 @@ constexpr bool test_one(Rng&& rng, Expected&& expected) {
using RS = chunk_view<views::all_t<remove_reference_t<Rng>>>;
constexpr bool is_noexcept = is_nothrow_move_constructible_v<V>;

STATIC_ASSERT(!is_default_constructible_v<RS>);
STATIC_ASSERT(!default_initializable<RS>);

STATIC_ASSERT(same_as<decltype(views::chunk(move(rng), 2)), RS>);
STATIC_ASSERT(noexcept(views::chunk(move(rng), 2)) == is_noexcept);

Expand Down
10 changes: 10 additions & 0 deletions tests/std/tests/P2442R1_views_slide/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ constexpr bool test_one(Rng&& rng, Expected&& expected) {
STATIC_ASSERT(bidirectional_range<R> == bidirectional_range<Rng>);
STATIC_ASSERT(random_access_range<R> == random_access_range<Rng>);

// Validate non-default-initializability
STATIC_ASSERT(!is_default_constructible_v<R>);
STATIC_ASSERT(!default_initializable<R>);

// Validate borrowed_range
static_assert(ranges::borrowed_range<R> == ranges::borrowed_range<V>);

Expand All @@ -63,6 +67,9 @@ constexpr bool test_one(Rng&& rng, Expected&& expected) {
using RC = slide_view<views::all_t<const remove_reference_t<Rng>&>>;
constexpr bool is_noexcept = !is_view || is_nothrow_copy_constructible_v<V>;

STATIC_ASSERT(!is_default_constructible_v<RC>);
STATIC_ASSERT(!default_initializable<RC>);

STATIC_ASSERT(same_as<decltype(views::slide(as_const(rng), 4)), RC>);
STATIC_ASSERT(noexcept(views::slide(as_const(rng), 4)) == is_noexcept);

Expand All @@ -76,6 +83,9 @@ constexpr bool test_one(Rng&& rng, Expected&& expected) {
using RS = slide_view<views::all_t<remove_reference_t<Rng>>>;
constexpr bool is_noexcept = is_nothrow_move_constructible_v<V>;

STATIC_ASSERT(!is_default_constructible_v<RS>);
STATIC_ASSERT(!default_initializable<RS>);

STATIC_ASSERT(same_as<decltype(views::slide(move(rng), 4)), RS>);
STATIC_ASSERT(noexcept(views::slide(move(rng), 4)) == is_noexcept);

Expand Down