Skip to content
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: 6 additions & 2 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -5285,7 +5285,9 @@ namespace ranges {
}

_NODISCARD constexpr auto begin() noexcept(
noexcept(_RANGES begin(_Base)) && is_nothrow_move_constructible_v<iterator_t<_Vw>>) /* strengthened */ {
noexcept(_RANGES begin(_Base)) && is_nothrow_move_constructible_v<iterator_t<_Vw>>) /* strengthened */
requires (!_Simple_view<_Vw>)
{
if constexpr (random_access_range<_Vw> && sized_range<_Vw>) {
return _RANGES begin(_Base);
} else {
Expand All @@ -5304,7 +5306,9 @@ namespace ranges {
}
}

_NODISCARD constexpr auto end() {
_NODISCARD constexpr auto end()
requires (!_Simple_view<_Vw>)
{
if constexpr (random_access_range<_Vw> && sized_range<_Vw>) {
return _RANGES begin(_Base) + _RANGES distance(_Base);
} else {
Expand Down
31 changes: 31 additions & 0 deletions tests/std/tests/P0896R4_views_common/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,34 @@ constexpr bool test_lwg3717() {
return true;
}

constexpr bool test_lwg_4012() {
struct simple_view_with_difference_on_const : ranges::view_interface<simple_view_with_difference_on_const> {
constexpr difference_type_only_iterator<int> begin() noexcept {
return {nullptr};
}
constexpr difference_type_only_sentinel<int> end() noexcept {
return {nullptr};
}
constexpr difference_type_only_iterator<int> begin() const noexcept {
return {p_};
}
constexpr difference_type_only_sentinel<int> end() const noexcept {
return {p_};
}

int* p_;
};

int n{};
auto cv = views::common(simple_view_with_difference_on_const{{}, &n});

assert(cv.begin() == as_const(cv).begin());
assert(cv.begin() == as_const(cv).end());
assert(as_const(cv).begin() == cv.end());

return true;
}

int main() {
// Get full instantiation coverage
static_assert((test_in<instantiator, const int>(), true));
Expand All @@ -551,4 +579,7 @@ int main() {

assert(test_lwg3717<int>());
assert(test_lwg3717<const int>());

static_assert(test_lwg_4012());
test_lwg_4012();
}