From 0a37460f249a7d7f471bc45d6c333524bb60aa74 Mon Sep 17 00:00:00 2001 From: Redstone1024 <2824517378@qq.com> Date: Tue, 17 Dec 2024 16:58:23 +0800 Subject: [PATCH] fix(range): fix range adapter closure behavior --- .../Source/Public/Range/AllView.h | 4 +- .../Source/Public/Range/Conversion.h | 18 +++--- .../Source/Public/Range/FilterView.h | 6 +- Redcraft.Utility/Source/Public/Range/Pipe.h | 61 +++++++++++++------ .../Source/Public/Range/TransformView.h | 6 +- 5 files changed, 66 insertions(+), 29 deletions(-) diff --git a/Redcraft.Utility/Source/Public/Range/AllView.h b/Redcraft.Utility/Source/Public/Range/AllView.h index f04d54b..2002b78 100644 --- a/Redcraft.Utility/Source/Public/Range/AllView.h +++ b/Redcraft.Utility/Source/Public/Range/AllView.h @@ -152,10 +152,12 @@ NODISCARD FORCEINLINE constexpr auto All(R&& InRange) /** Creates A view adapter that includes all elements of a range. */ NODISCARD FORCEINLINE constexpr auto All() { - return TAdaptorClosure([] requires (requires { Range::All(DeclVal()); }) (R&& Base) + using FClosure = decltype([] requires (requires { Range::All(DeclVal()); }) (R&& Base) { return Range::All(Forward(Base)); }); + + return TAdaptorClosure(); } /** A view adapter that includes all elements of a range. */ diff --git a/Redcraft.Utility/Source/Public/Range/Conversion.h b/Redcraft.Utility/Source/Public/Range/Conversion.h index 9e4b1fc..0fbd350 100644 --- a/Redcraft.Utility/Source/Public/Range/Conversion.h +++ b/Redcraft.Utility/Source/Public/Range/Conversion.h @@ -88,7 +88,7 @@ NODISCARD FORCEINLINE constexpr auto To(R&& Range, Ts&&... Args) return Result; } - else static_assert(sizeof(C) == -1, "The container type is not constructible from a range"); + else static_assert(sizeof(R) == -1, "The container type is not constructible from a range"); } else { @@ -97,7 +97,7 @@ NODISCARD FORCEINLINE constexpr auto To(R&& Range, Ts&&... Args) return Range::To(Range::All(Range) | Range::Transform([](T&& Element) { return Range::To>(Forward(Element)); }), Forward(Args)...); } - else static_assert(sizeof(C) == -1, "The container type is not constructible from a range"); + else static_assert(sizeof(R) == -1, "The container type is not constructible from a range"); } } @@ -115,27 +115,31 @@ NODISCARD FORCEINLINE constexpr auto To(R&& Range, Ts&&... Args) return Range::To>(), DeclVal>(), DeclVal()...))>(Forward(Range), Forward(Args)...); } - else static_assert(sizeof(C) == -1, "The container type is not constructible from a range"); + else static_assert(sizeof(R) == -1, "The container type is not constructible from a range"); } /** Constructs a non-view object from the elements of the range. */ template requires (!CView) NODISCARD FORCEINLINE constexpr auto To(Ts&&... Args) { - return TAdaptorClosure([&Args...] requires (requires { Range::To(DeclVal(), DeclVal()...); }) (R&& Range) + using FClosure = decltype([] requires (requires { Range::To(DeclVal(), DeclVal()...); }) (R&& Range, Us&&... Args) { - return Range::To(Forward(Range), Forward(Args)...); + return Range::To(Forward(Range), Forward(Args)...); }); + + return TAdaptorClosure...>(Forward(Args)...); } /** Constructs a non-view object from the elements of the range. */ template