From 2e4f38b176a0d314f603df506609287a8cd9a952 Mon Sep 17 00:00:00 2001 From: grcm10 Date: Sun, 24 Mar 2024 09:56:29 +0900 Subject: [PATCH 1/3] Add empty to single_view --- stl/inc/ranges | 3 +++ tests/std/tests/P0896R4_views_single/test.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/stl/inc/ranges b/stl/inc/ranges index 30d22d9c4f..0e10e1f96a 100644 --- a/stl/inc/ranges +++ b/stl/inc/ranges @@ -1042,6 +1042,9 @@ namespace ranges { return _STD addressof(*_Val); } + _NODISCARD static constexpr bool empty() noexcept { + return false; + } private: /* [[no_unique_address]] */ _Movable_box<_Ty> _Val{}; }; diff --git a/tests/std/tests/P0896R4_views_single/test.cpp b/tests/std/tests/P0896R4_views_single/test.cpp index 8671a90105..ccf315b8d2 100644 --- a/tests/std/tests/P0896R4_views_single/test.cpp +++ b/tests/std/tests/P0896R4_views_single/test.cpp @@ -52,6 +52,13 @@ constexpr bool test_one_type(T value, Args&&... args) { same_as auto r0 = ranges::single_view{value}; const R& cr0 = r0; + // validate member empty + static_assert(same_as); + 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); static_assert(R::size() == 1); From 6373ccdc7d1876d9935acd8352124215b15671e5 Mon Sep 17 00:00:00 2001 From: grcm10 Date: Sun, 24 Mar 2024 10:57:05 +0900 Subject: [PATCH 2/3] Fix the formatting error --- stl/inc/ranges | 1 + 1 file changed, 1 insertion(+) diff --git a/stl/inc/ranges b/stl/inc/ranges index 0e10e1f96a..dcae94a040 100644 --- a/stl/inc/ranges +++ b/stl/inc/ranges @@ -1045,6 +1045,7 @@ namespace ranges { _NODISCARD static constexpr bool empty() noexcept { return false; } + private: /* [[no_unique_address]] */ _Movable_box<_Ty> _Val{}; }; From 93d7299fbcbe646e96f452cd601f7585708635a4 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Mon, 25 Mar 2024 14:40:29 -0700 Subject: [PATCH 3/3] Follow the Standard's declaration order. --- stl/inc/ranges | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stl/inc/ranges b/stl/inc/ranges index dcae94a040..d2949c677a 100644 --- a/stl/inc/ranges +++ b/stl/inc/ranges @@ -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; } @@ -1042,10 +1046,6 @@ namespace ranges { return _STD addressof(*_Val); } - _NODISCARD static constexpr bool empty() noexcept { - return false; - } - private: /* [[no_unique_address]] */ _Movable_box<_Ty> _Val{}; };