Skip to content

Commit

Permalink
Implement LWG-4035 single_view should provide empty (#4525)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan T. Lavavej <stl@nuwen.net>
  • Loading branch information
grcm10 and StephanTLavavej authored Mar 28, 2024
1 parent e0a75b3 commit 53f95ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions stl/inc/ranges
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,10 @@ namespace ranges {
return data() + 1;
}

_NODISCARD static constexpr bool empty() noexcept {
return false;
}

_NODISCARD static constexpr size_t size() noexcept {
return 1;
}
Expand Down
7 changes: 7 additions & 0 deletions tests/std/tests/P0896R4_views_single/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ constexpr bool test_one_type(T value, Args&&... args) {
same_as<R> auto r0 = ranges::single_view{value};
const R& cr0 = r0;

// validate member empty
static_assert(same_as<decltype(R::empty()), bool>);
static_assert(R::empty() == false);
static_assert(noexcept(R::empty()));
static_assert(noexcept(ranges::empty(r0)));
static_assert(noexcept(ranges::empty(cr0)));

// validate member size
static_assert(same_as<decltype(R::size()), size_t>);
static_assert(R::size() == 1);
Expand Down

0 comments on commit 53f95ba

Please sign in to comment.