From fed5486b14f00ed8c28b5bbcd250e9b6efbcff17 Mon Sep 17 00:00:00 2001 From: Patrick Roberts Date: Mon, 1 Jun 2026 11:29:13 -0500 Subject: [PATCH] Mandate rather than constrain movable and copyable --- include/beman/any_view/concepts.hpp | 31 +++--------------- tests/beman/any_view/sfinae.test.cpp | 48 ++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/include/beman/any_view/concepts.hpp b/include/beman/any_view/concepts.hpp index 201fdd5..4925dc3 100644 --- a/include/beman/any_view/concepts.hpp +++ b/include/beman/any_view/concepts.hpp @@ -27,29 +27,9 @@ concept any_compatible_sized_range = template concept any_compatible_borrowed_range = - not flag_is_set or std::ranges::borrowed_range; - -template -concept any_compatible_copyable_view = not flag_is_set or std::copyable; - -template -concept any_compatible_view = - any_compatible_iterator, RefT, RValueRefT, DiffT, OptsV> and - any_compatible_sized_range and any_compatible_borrowed_range; - -template -struct make_view { - using type = std::views::all_t; -}; - -template - requires std::ranges::enable_view> -struct make_view { - using type = std::remove_cvref_t; -}; - -template -using make_view_t = typename make_view::type; + not flag_is_set or + (not std::ranges::enable_view> and std::is_lvalue_reference_v) or + std::ranges::enable_borrowed_range>; template concept different_from = not std::same_as, std::remove_cvref_t>; @@ -59,9 +39,8 @@ concept different_from = not std::same_as, std::remove_cv template concept ext_any_compatible_range = std::ranges::range and - detail::any_compatible_view, RefT, RValueRefT, DiffT, OptsV> and - (std::ranges::enable_view> or - detail::any_compatible_copyable_view, OptsV>); + detail::any_compatible_iterator, RefT, RValueRefT, DiffT, OptsV> and + detail::any_compatible_sized_range and detail::any_compatible_borrowed_range; } // namespace beman::any_view diff --git a/tests/beman/any_view/sfinae.test.cpp b/tests/beman/any_view/sfinae.test.cpp index 55e221d..8ba3f18 100644 --- a/tests/beman/any_view/sfinae.test.cpp +++ b/tests/beman/any_view/sfinae.test.cpp @@ -31,7 +31,11 @@ TEST(SfinaeTest, forward_list) { static_assert(not std::constructible_from, std::forward_list>); static_assert(not std::constructible_from, std::forward_list>); static_assert(not std::constructible_from, std::forward_list>); - static_assert(not std::constructible_from, std::forward_list>); +#ifndef _MSC_VER + // error C2280: attempting to reference a deleted function + // copyable is mandated, not required + static_assert(std::constructible_from, std::forward_list>); +#endif static_assert(std::constructible_from, std::forward_list&>); static_assert(std::constructible_from, std::forward_list&>); @@ -43,7 +47,11 @@ TEST(SfinaeTest, list) { static_assert(std::constructible_from, std::list>); static_assert(std::constructible_from, std::list>); static_assert(not std::constructible_from, std::list>); - static_assert(not std::constructible_from, std::list>); +#ifndef _MSC_VER + // error C2280: attempting to reference a deleted function + // copyable is mandated, not required + static_assert(std::constructible_from, std::list>); +#endif static_assert(std::constructible_from, std::list&>); static_assert(std::constructible_from, std::list&>); @@ -55,7 +63,11 @@ TEST(SfinaeTest, deque) { static_assert(std::constructible_from, std::deque>); static_assert(std::constructible_from, std::deque>); static_assert(not std::constructible_from, std::deque>); - static_assert(not std::constructible_from, std::deque>); +#ifndef _MSC_VER + // error C2280: attempting to reference a deleted function + // copyable is mandated, not required + static_assert(std::constructible_from, std::deque>); +#endif static_assert(std::constructible_from, std::deque&>); static_assert(std::constructible_from, std::deque&>); @@ -66,7 +78,11 @@ TEST(SfinaeTest, vector) { static_assert(std::constructible_from, std::vector>); static_assert(std::constructible_from, std::vector>); static_assert(not std::constructible_from, std::vector>); - static_assert(not std::constructible_from, std::vector>); +#ifndef _MSC_VER + // error C2280: attempting to reference a deleted function + // copyable is mandated, not required + static_assert(std::constructible_from, std::vector>); +#endif static_assert(std::constructible_from, std::vector&>); static_assert(std::constructible_from, std::vector&>); @@ -77,7 +93,11 @@ TEST(SfinaeTest, vector_of_bool) { static_assert(std::constructible_from, std::vector>); static_assert(std::constructible_from, std::vector>); static_assert(not std::constructible_from, std::vector>); - static_assert(not std::constructible_from, std::vector>); +#ifndef _MSC_VER + // error C2280: attempting to reference a deleted function + // copyable is mandated, not required + static_assert(std::constructible_from, std::vector>); +#endif static_assert(std::constructible_from, std::vector&>); static_assert(std::constructible_from, std::vector&>); @@ -109,10 +129,26 @@ TEST(SfinaeTest, iota) { TEST(SfinaeTest, any_view) { static_assert(std::constructible_from, any_view>); - // does not copy construct copyable any_view because std::views::all decays it + // any_view is not copyable + static_assert(not std::constructible_from, any_view&>); + static_assert(std::constructible_from, any_view&>); + // const any_view does not model range static_assert(not std::constructible_from, const any_view&>); } TEST(SfinaeTest, default_view) { static_assert(std::default_initializable>); } + +template +struct my_range { + my_range(T); + + int* begin(); + int* end(); +}; + +TEST(SfinaeTest, user_range) { + // R5 any_view constructor causes constraint to depend on itself + static_assert(std::ranges::viewable_range>>); +}