From e6d525f2c3b03dc29e6c247f2d4d66041ea0b766 Mon Sep 17 00:00:00 2001 From: Redstone1024 <2824517378@qq.com> Date: Thu, 19 Dec 2024 12:04:22 +0800 Subject: [PATCH] feat(range): add simple view concept and refactor related requires --- Redcraft.Utility/Source/Public/Range/MoveView.h | 16 +++++++++++----- Redcraft.Utility/Source/Public/Range/TakeView.h | 4 ++-- Redcraft.Utility/Source/Public/Range/View.h | 6 ++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Redcraft.Utility/Source/Public/Range/MoveView.h b/Redcraft.Utility/Source/Public/Range/MoveView.h index 4077b99..15d0e3f 100644 --- a/Redcraft.Utility/Source/Public/Range/MoveView.h +++ b/Redcraft.Utility/Source/Public/Range/MoveView.h @@ -34,9 +34,17 @@ public: FORCEINLINE constexpr explicit TMoveView(V InBase) : Base(MoveTemp(InBase)) { } - NODISCARD FORCEINLINE constexpr auto Begin() { return MakeMoveIterator(Range::Begin(Base)); } + NODISCARD FORCEINLINE constexpr auto Begin() requires (!CSimpleView) + { + return MakeMoveIterator(Range::Begin(Base)); + } - NODISCARD FORCEINLINE constexpr auto End() + NODISCARD FORCEINLINE constexpr auto Begin() const requires (CRange) + { + return MakeMoveIterator(Range::Begin(Base)); + } + + NODISCARD FORCEINLINE constexpr auto End() requires (!CSimpleView) { if constexpr (CCommonRange) { @@ -45,9 +53,7 @@ public: else return MakeMoveSentinel(Range::End(Base)); } - NODISCARD FORCEINLINE constexpr auto Begin() const requires (CRange) { return MakeMoveIterator(Range::Begin(Base)); } - - NODISCARD FORCEINLINE constexpr auto End() const requires (CRange) + NODISCARD FORCEINLINE constexpr auto End() const requires (CRange) { if constexpr (CCommonRange) { diff --git a/Redcraft.Utility/Source/Public/Range/TakeView.h b/Redcraft.Utility/Source/Public/Range/TakeView.h index da71aff..87dd8bd 100644 --- a/Redcraft.Utility/Source/Public/Range/TakeView.h +++ b/Redcraft.Utility/Source/Public/Range/TakeView.h @@ -36,7 +36,7 @@ public: FORCEINLINE constexpr TTakeView(V InBase, size_t InCount) : Base(MoveTemp(InBase)), Count(InCount) { } - NODISCARD FORCEINLINE constexpr auto Begin() + NODISCARD FORCEINLINE constexpr auto Begin() requires (!CSimpleView) { if constexpr (CSizedRange) { @@ -62,7 +62,7 @@ public: else return MakeCountedIterator(Range::Begin(Base), Count); } - NODISCARD FORCEINLINE constexpr auto End() + NODISCARD FORCEINLINE constexpr auto End() requires (!CSimpleView) { if constexpr (CSizedRange) { diff --git a/Redcraft.Utility/Source/Public/Range/View.h b/Redcraft.Utility/Source/Public/Range/View.h index 9f60047..f290fcf 100644 --- a/Redcraft.Utility/Source/Public/Range/View.h +++ b/Redcraft.Utility/Source/Public/Range/View.h @@ -98,6 +98,12 @@ concept CViewableRange = CRange || (!CView> && (CLValueReference || (CMovable> && !NAMESPACE_PRIVATE::TIsInitializerList>::Value)))); +/** A concept specifies that a view uses the same iterator and sentinel type for both const and non-const views. */ +template +concept CSimpleView = CView && CRange + && CSameAs, TRangeIterator> + && CSameAs, TRangeSentinel>; + NAMESPACE_BEGIN(Range) /** A simple view that combines an iterator-sentinel pair into a view. */