Skip to content

Commit

Permalink
Implement LWG-3712: chunk_view and slide_view should not be `defa…
Browse files Browse the repository at this point in the history
…ult_initializable` (#2943)

Co-authored-by: Casey Carter <[email protected]>
  • Loading branch information
frederick-vs-ja and CaseyCarter authored Jul 28, 2022
1 parent f8a9c6f commit 374fc90
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
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 @@ -5431,10 +5431,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 @@ -5478,8 +5474,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 @@ -5691,10 +5687,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 @@ -5819,8 +5811,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 @@ -6053,10 +6045,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
8 changes: 8 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,10 @@ 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>);

// Validate borrowed_range
STATIC_ASSERT(ranges::borrowed_range<R> == (ranges::borrowed_range<V> && forward_range<V>) );

Expand All @@ -59,6 +63,8 @@ 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(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,8 @@ 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(same_as<decltype(views::chunk(move(rng), 2)), RS>);
STATIC_ASSERT(noexcept(views::chunk(move(rng), 2)) == is_noexcept);

Expand Down
7 changes: 7 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,9 @@ 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>);

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

Expand All @@ -63,6 +66,8 @@ 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(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 +81,8 @@ 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(same_as<decltype(views::slide(move(rng), 4)), RS>);
STATIC_ASSERT(noexcept(views::slide(move(rng), 4)) == is_noexcept);

Expand Down

0 comments on commit 374fc90

Please sign in to comment.