diff --git a/Redcraft.Utility/Source/Public/Iterator/BidirectionalIterator.h b/Redcraft.Utility/Source/Public/Iterator/BidirectionalIterator.h index 49495f0..7f7231d 100644 --- a/Redcraft.Utility/Source/Public/Iterator/BidirectionalIterator.h +++ b/Redcraft.Utility/Source/Public/Iterator/BidirectionalIterator.h @@ -31,38 +31,30 @@ concept CBidirectionalIterator = CForwardIterator template struct IBidirectionalIterator /* : IForwardIterator */ { - /** The element type of the indirectly readable type. See 'IIndirectlyReadable'. */ + // ~Begin CForwardIterator. + using ElementType = TRemoveCVRef; - /** Default constructor. See 'IIncrementable' and 'ISentinelFor'. */ IBidirectionalIterator(); - - /** Copy constructor. See 'IIncrementable' and 'ISentinelFor'. */ IBidirectionalIterator(const IBidirectionalIterator&); - - /** Copy assignment operator. See 'IIncrementable' and 'ISentinelFor'. */ + IBidirectionalIterator(IBidirectionalIterator&&); IBidirectionalIterator* operator=(const IBidirectionalIterator&); + IBidirectionalIterator* operator=(IBidirectionalIterator&&); - /** Equality operator. See 'IIncrementable' and 'ISentinelFor'. */ friend bool operator==(const IBidirectionalIterator&, const IBidirectionalIterator&); - /** Dereference operator. See 'IForwardIterator'. */ T operator*() const; - /** Pre-increment operator. See 'IWeaklyIncrementable'. */ - IBidirectionalIterator& operator++(); + // ~End CForwardIterator. - /** Pre-decrement operator. */ + IBidirectionalIterator& operator++(); // Also satisfies CForwardIterator. IBidirectionalIterator& operator--(); - /** Post-increment operator. See 'IIncrementable'. */ - IBidirectionalIterator operator++(int); - - /** Post-decrement operator. */ + IBidirectionalIterator operator++(int); // Also satisfies CForwardIterator. IBidirectionalIterator operator--(int); }; -// Use 'IBidirectionalIterator' represents a bidirectional iterator. +// Use IBidirectionalIterator represents a bidirectional iterator. static_assert(CBidirectionalIterator>); static_assert( COutputIterator, int>); diff --git a/Redcraft.Utility/Source/Public/Iterator/ContiguousIterator.h b/Redcraft.Utility/Source/Public/Iterator/ContiguousIterator.h index 8825e28..5707115 100644 --- a/Redcraft.Utility/Source/Public/Iterator/ContiguousIterator.h +++ b/Redcraft.Utility/Source/Public/Iterator/ContiguousIterator.h @@ -17,7 +17,7 @@ NAMESPACE_MODULE_BEGIN(Utility) /** * A concept specifies a type is a contiguous iterator. - * Add the 'operator->' to the random access iterator and requires the 'operator*' returns a true reference type. + * Add the operator-> to the random access iterator and requires the operator* returns a true reference type. */ template concept CContiguousIterator = CRandomAccessIterator && CLValueReference> @@ -30,74 +30,62 @@ concept CContiguousIterator = CRandomAccessIterator && CLValueReference -struct IContiguousIterator /* : IBidirectionalIterator */ +struct IContiguousIterator /* : IRandomAccessIterator */ { - /** The element type of the indirectly readable type. See 'IIndirectlyReadable'. */ + // ~Begin CRandomAccessIterator. + using ElementType = TRemoveCVRef; - /** Default constructor. See 'IIncrementable' and 'ISentinelFor'. */ IContiguousIterator(); - - /** Copy constructor. See 'IIncrementable' and 'ISentinelFor'. */ IContiguousIterator(const IContiguousIterator&); - - /** Copy assignment operator. See 'IIncrementable' and 'ISentinelFor'. */ + IContiguousIterator(IContiguousIterator&&); IContiguousIterator* operator=(const IContiguousIterator&); + IContiguousIterator* operator=(IContiguousIterator&&); - /** Equality operator. See 'IIncrementable' and 'ISentinelFor'. */ friend bool operator==(const IContiguousIterator&, const IContiguousIterator&); - /** Three-way comparison operator. See 'IRandomAccessIterator'. */ - friend strong_ordering operator<=>(const IContiguousIterator& LHS, const IContiguousIterator& RHS); + friend strong_ordering operator<=>(const IContiguousIterator&, const IContiguousIterator&); + + // ~End CRandomAccessIterator. /** - * Dereference operator. See 'IForwardIterator'. + * Dereference operator. See IForwardIterator. * Specify, the return type must be a true reference type and refer to an element of a contiguous sequence, not a proxy class. + * Also satisfies CRandomAccessIterator. */ T operator*() const; /** Indirection operator. Return the address of the element that the iterator is pointing to. */ TAddPointer operator->() const; - /** Pre-increment operator. See 'IWeaklyIncrementable'. */ - IContiguousIterator& operator++(); + // ~Begin CRandomAccessIterator. - /** Pre-decrement operator. See 'IBidirectionalIterator'. */ + T operator[](ptrdiff) const; + + IContiguousIterator& operator++(); IContiguousIterator& operator--(); - /** Post-increment operator. See 'IIncrementable'. */ IContiguousIterator operator++(int); - - /** Post-decrement operator. See 'IBidirectionalIterator'. */ IContiguousIterator operator--(int); - /** Addition assignment operator. See 'IRandomAccessIterator'. */ IContiguousIterator& operator+=(ptrdiff); - - /** Subtraction assignment operator. See 'IRandomAccessIterator'. */ IContiguousIterator& operator-=(ptrdiff); - /** Addition operator. See 'IRandomAccessIterator'. */ IContiguousIterator operator+(ptrdiff) const; - - /** Subtraction operator. See 'IRandomAccessIterator'. */ IContiguousIterator operator-(ptrdiff) const; - /** Addition operator. See 'IRandomAccessIterator'. */ friend IContiguousIterator operator+(ptrdiff, const IContiguousIterator&); - /** Subtraction operator. See 'IRandomAccessIterator'. */ friend ptrdiff operator-(const IContiguousIterator&, const IContiguousIterator&); - /** Subscript operator. See 'IRandomAccessIterator'. */ - T operator[](ptrdiff) const; + // ~End CRandomAccessIterator. }; -// Use 'IContiguousIterator' represents a contiguous iterator +// Use IContiguousIterator represents a contiguous iterator static_assert(CContiguousIterator>); static_assert( COutputIterator, int>); -// The 'int*' is the most typical example of a contiguous iterator +// The int* is the most typical example of a contiguous iterator static_assert(CContiguousIterator); #if PLATFORM_COMPILER_GCC diff --git a/Redcraft.Utility/Source/Public/Iterator/ForwardIterator.h b/Redcraft.Utility/Source/Public/Iterator/ForwardIterator.h index d6b9f08..4688afe 100644 --- a/Redcraft.Utility/Source/Public/Iterator/ForwardIterator.h +++ b/Redcraft.Utility/Source/Public/Iterator/ForwardIterator.h @@ -20,37 +20,38 @@ concept CForwardIterator = CInputIterator && CIncrementable && CSentinelFo /** This is an example of a forward iterator, indicate the traits that define a forward iterator. */ template -struct IForwardIterator /* : IInputIterator, IIncrementable, ISentinelFor */ +struct IForwardIterator /* : IInputIterator, IIncrementable, ISentinelFor */ { - /** The element type of the indirectly readable type. See 'IIndirectlyReadable'. */ + // ~Begin CInputIterator. + using ElementType = TRemoveCVRef; - /** Default constructor. See 'IIncrementable' and 'ISentinelFor'. */ + // ~End CInputIterator. + + // ~Begin CIncrementable and CSentinelFor. + IForwardIterator(); - - /** Copy constructor. See 'IIncrementable' and 'ISentinelFor'. */ IForwardIterator(const IForwardIterator&); - - /** Copy assignment operator. See 'IIncrementable' and 'ISentinelFor'. */ + IForwardIterator(IForwardIterator&&); // Also satisfies IInputIterator. IForwardIterator* operator=(const IForwardIterator&); + IForwardIterator* operator=(IForwardIterator&&); // Also satisfies IInputIterator. - /** Equality operator. See 'IIncrementable' and 'ISentinelFor'. */ friend bool operator==(const IForwardIterator&, const IForwardIterator&); - /** - * Indirectly read the element from the indirectly readable type. See 'IIndirectlyReadable'. - * Indirectly write the element if the type is also an indirectly writable type. See 'IIndirectlyWritable'. - */ - T operator*() const; + // ~End CIncrementable and CSentinelFor. - /** Pre-increment operator. See 'IWeaklyIncrementable'. */ - IForwardIterator& operator++(); + // ~Begin CInputIterator. - /** Post-increment operator. See 'IIncrementable'. */ - IForwardIterator operator++(int); + T operator*() const; // Optional satisfies CIndirectlyWritable. + + IForwardIterator& operator++(); // Also satisfies CIncrementable. + + IForwardIterator operator++(int); // Also satisfies CIncrementable. + + // ~End CInputIterator. }; -// Use 'IForwardIterator' represents a forward iterator. +// Use IForwardIterator represents a forward iterator. static_assert(CForwardIterator>); static_assert( COutputIterator, int>); diff --git a/Redcraft.Utility/Source/Public/Iterator/RandomAccessIterator.h b/Redcraft.Utility/Source/Public/Iterator/RandomAccessIterator.h index 46c282d..2795202 100644 --- a/Redcraft.Utility/Source/Public/Iterator/RandomAccessIterator.h +++ b/Redcraft.Utility/Source/Public/Iterator/RandomAccessIterator.h @@ -33,64 +33,54 @@ concept CRandomAccessIterator = CBidirectionalIterator && CTotallyOrdered /** This is an example of a random access iterator, indicate the traits that define a random access iterator. */ template -struct IRandomAccessIterator /* : IBidirectionalIterator */ +struct IRandomAccessIterator /* : IBidirectionalIterator, ISizedSentinelFor */ { - /** The element type of the indirectly readable type. See 'IIndirectlyReadable'. */ + // ~Begin CBidirectionalIterator. + using ElementType = TRemoveCVRef; - /** Default constructor. See 'IIncrementable' and 'ISentinelFor'. */ + // ~End CBidirectionalIterator. + + // ~Begin CBidirectionalIterator and CSizedSentinelFor. + IRandomAccessIterator(); - - /** Copy constructor. See 'IIncrementable' and 'ISentinelFor'. */ IRandomAccessIterator(const IRandomAccessIterator&); - - /** Copy assignment operator. See 'IIncrementable' and 'ISentinelFor'. */ + IRandomAccessIterator(IRandomAccessIterator&&); IRandomAccessIterator* operator=(const IRandomAccessIterator&); + IRandomAccessIterator* operator=(IRandomAccessIterator&&); - /** Equality operator. See 'IIncrementable' and 'ISentinelFor'. */ friend bool operator==(const IRandomAccessIterator&, const IRandomAccessIterator&); - /** Three-way comparison operator. */ - friend strong_ordering operator<=>(const IRandomAccessIterator& LHS, const IRandomAccessIterator& RHS); + // ~End CBidirectionalIterator and CSizedSentinelFor. - /** Dereference operator. See 'IForwardIterator'. */ - T operator*() const; + friend strong_ordering operator<=>(const IRandomAccessIterator&, const IRandomAccessIterator&); + + T operator*() const; // Also satisfies CBidirectionalIterator. + + T operator[](ptrdiff) const; + + // ~Begin CBidirectionalIterator. - /** Pre-increment operator. See 'IWeaklyIncrementable'. */ IRandomAccessIterator& operator++(); - - /** Pre-decrement operator. See 'IBidirectionalIterator'. */ IRandomAccessIterator& operator--(); - /** Post-increment operator. See 'IIncrementable'. */ IRandomAccessIterator operator++(int); - - /** Post-decrement operator. See 'IBidirectionalIterator'. */ IRandomAccessIterator operator--(int); - /** Addition assignment operator. */ - IRandomAccessIterator& operator+=(ptrdiff); + // ~End CBidirectionalIterator. - /** Subtraction assignment operator. */ + IRandomAccessIterator& operator+=(ptrdiff); IRandomAccessIterator& operator-=(ptrdiff); - /** Addition operator. */ IRandomAccessIterator operator+(ptrdiff) const; - - /** Subtraction operator. */ IRandomAccessIterator operator-(ptrdiff) const; - /** Addition operator. */ friend IRandomAccessIterator operator+(ptrdiff, const IRandomAccessIterator&); - /** Subtraction operator. */ - friend ptrdiff operator-(const IRandomAccessIterator&, const IRandomAccessIterator&); - - /** Subscript operator. */ - T operator[](ptrdiff) const; + friend ptrdiff operator-(const IRandomAccessIterator&, const IRandomAccessIterator&); // Also satisfies CSizedSentinelFor. }; -// Use 'IRandomAccessIterator' represents a random access iterator +// Use IRandomAccessIterator represents a random access iterator static_assert(CRandomAccessIterator>); static_assert( COutputIterator, int>); diff --git a/Redcraft.Utility/Source/Public/Iterator/Sentinel.h b/Redcraft.Utility/Source/Public/Iterator/Sentinel.h index c8c0615..99eead8 100644 --- a/Redcraft.Utility/Source/Public/Iterator/Sentinel.h +++ b/Redcraft.Utility/Source/Public/Iterator/Sentinel.h @@ -24,23 +24,17 @@ concept CSentinelFor = CSemiregular && CInputOrOutputIterator && CWeaklyEq template struct ISentinelFor { - /** Default constructor. */ ISentinelFor(); - - /** Copy constructor. */ ISentinelFor(const ISentinelFor&); - - /** Copy assignment operator. */ ISentinelFor* operator=(const ISentinelFor&); - /** Equality operator. */ bool operator==(const I&) const&; }; -// Use 'ISentinelFor' represents a sentinel for an iterator. +// Use ISentinelFor represents a sentinel for an iterator. static_assert(CSentinelFor>, IInputOrOutputIterator>); -// The 'CSentinelFor' requires this code is valid. +// The CSentinelFor requires this code is valid. static_assert( requires(ISentinelFor> Sentinel, IInputOrOutputIterator Iter) { @@ -49,7 +43,7 @@ static_assert( } ); -/** Disable the 'CSizedSentinelFor' concept for specific types. */ +/** Disable the CSizedSentinelFor concept for specific types. */ template inline constexpr bool bDisableSizedSentinelFor = false; @@ -71,27 +65,23 @@ concept CSizedSentinelFor = CSentinelFor template struct ISizedSentinelFor /* : ISentinelFor */ { - /** Default constructor. */ - ISizedSentinelFor(); - - /** Copy constructor. */ + ISizedSentinelFor(); // Also satisfies ISentinelFor. ISizedSentinelFor(const ISizedSentinelFor&); - - /** Copy assignment operator. */ + ISizedSentinelFor(ISizedSentinelFor&&); // Also satisfies ISentinelFor. ISizedSentinelFor& operator=(const ISizedSentinelFor&); + ISizedSentinelFor& operator=(ISizedSentinelFor&&); // Also satisfies ISentinelFor. - /** Equality operator. */ - bool operator==(const I&) const&; + bool operator==(const I&) const&; // Also satisfies ISentinelFor. /** Subtraction operator. The 'Sentinel - Iter' is equal to negative 'Iter - Sentinel'. */ friend ptrdiff operator-(const I&, const ISizedSentinelFor&); friend ptrdiff operator-(const ISizedSentinelFor&, const I&); }; -// Use 'ISizedSentinelFor' represents a sized sentinel for an iterator. +// Use ISizedSentinelFor represents a sized sentinel for an iterator. static_assert(CSizedSentinelFor>, IInputOrOutputIterator>); -// The 'CSentinelFor' requires this code is valid. +// The CSentinelFor requires this code is valid. static_assert( requires(ISizedSentinelFor> Sentinel, IInputOrOutputIterator Iter) { diff --git a/Redcraft.Utility/Source/Public/Iterator/Utility.h b/Redcraft.Utility/Source/Public/Iterator/Utility.h index bd24d4b..5a26064 100644 --- a/Redcraft.Utility/Source/Public/Iterator/Utility.h +++ b/Redcraft.Utility/Source/Public/Iterator/Utility.h @@ -76,18 +76,18 @@ struct IIndirectlyReadable /** * Indirectly read the element from the indirectly readable type. - * The return type may not be 'const ElementType&', this concept only requires that the return type - * and 'ElementType' has some relationship, such as copy constructible to 'ElementType' if the type is copyable. - * This means that returning a proxy class castable to 'ElementType' is also valid. - * If this is an iterator adaptor, use 'decltype(auto)' to forward the return value. + * The return type may not be const ElementType&, this concept only requires that the return type + * and ElementType has some relationship, such as copy constructible to ElementType if the type is copyable. + * This means that returning a proxy class castable to ElementType is also valid. + * If this is an iterator adaptor, use decltype(auto) to forward the return value. */ T operator*() const; }; -// Use 'IIndirectlyReadable' represents an indirectly readable type and 'int' is the regular element type. +// Use IIndirectlyReadable represents an indirectly readable type and int is the regular element type. static_assert(CIndirectlyReadable> && CRegular); -// The 'CIndirectlyReadable' requires this code is valid. +// The CIndirectlyReadable requires this code is valid. static_assert( requires(IIndirectlyReadable Iter, int& A) { @@ -112,19 +112,19 @@ struct IIndirectlyWritable { /** * Indirectly write the element from the indirectly writable type. - * The return type may not be 'T&', this concept only requires that the return type and 'T' has some relationship, - * such as can be assigned from 'T&' if the type is copyable or 'T&&' if the type is movable. - * This means that returning a proxy class can be assigned from 'T' is also valid. + * The return type may not be T&, this concept only requires that the return type and T has some relationship, + * such as can be assigned from T& if the type is copyable or T&& if the type is movable. + * This means that returning a proxy class can be assigned from T is also valid. * If this is also an indirectly readable type, the equivalent value is read after writing. - * If this is an iterator adaptor, use 'decltype(auto)' to forward the return value. + * If this is an iterator adaptor, use decltype(auto) to forward the return value. */ T operator*() const; }; -// Use 'IIndirectlyWritable' represents an indirectly writable type and 'int' is the regular element type. +// Use IIndirectlyWritable represents an indirectly writable type and int is the regular element type. static_assert(CIndirectlyWritable, int> && CRegular); -// The 'CIndirectlyWritable' requires this code is valid. +// The CIndirectlyWritable requires this code is valid. static_assert( requires(IIndirectlyWritable Iter, int& A) { @@ -140,23 +140,16 @@ concept CWeaklyIncrementable = CMovable /** This is an example of a weakly incrementable type, indicate the traits that define a weakly incrementable type. */ struct IWeaklyIncrementable { - /** Move constructor. */ IWeaklyIncrementable(IWeaklyIncrementable&&); - - /** Move assignment operator. */ IWeaklyIncrementable* operator=(IWeaklyIncrementable&&); - /** Pre-increment operator. */ IWeaklyIncrementable& operator++(); - /** - * Post-increment operator. - * Specify, the concept not requires the return type is any specific type, so the return type can be 'void'. - */ + /** Post-increment operator. Specify, the concept not requires the return type is any specific type, so the return type can be void. */ void operator++(int); }; -// Use 'IWeaklyIncrementable' represents a weakly incrementable type. +// Use IWeaklyIncrementable represents a weakly incrementable type. static_assert(CWeaklyIncrementable); /** @@ -174,26 +167,21 @@ concept CIncrementable = CRegular && CWeaklyIncrementable */ struct IIncrementable /* : IWeaklyIncrementable */ { - /** Default constructor. */ IIncrementable(); - - /** Copy constructor. */ IIncrementable(const IIncrementable&); - - /** Copy assignment operator. */ + IIncrementable(IIncrementable&&); // Also satisfies IWeaklyIncrementable. IIncrementable* operator=(const IIncrementable&); + IIncrementable* operator=(IIncrementable&&); // Also satisfies IWeaklyIncrementable. - /** Equality operator. */ friend bool operator==(const IIncrementable&, const IIncrementable&); - /** Pre-increment operator. See 'IWeaklyIncrementable'. */ - IIncrementable& operator++(); + IIncrementable& operator++(); // Also satisfies IWeaklyIncrementable. - /** Post-increment operator. */ + /** Post-increment operator. Specify, the concept requires the return value is the original value before incrementing. */ IIncrementable operator++(int); }; -// Use 'IIncrementable' represents an incrementable type. +// Use IIncrementable represents an incrementable type. static_assert(CIncrementable); /** @@ -208,23 +196,22 @@ concept CInputOrOutputIterator = CWeaklyIncrementable template struct IInputOrOutputIterator /* : IWeaklyIncrementable */ { - /** Move constructor. See 'IWeaklyIncrementable'. */ - IInputOrOutputIterator(IInputOrOutputIterator&&); + // ~Begin CWeklyIncrementable. - /** Move assignment operator. See 'IWeaklyIncrementable'. */ + IInputOrOutputIterator(IInputOrOutputIterator&&); IInputOrOutputIterator* operator=(IInputOrOutputIterator&&); - /** Pre-increment operator. See 'IWeaklyIncrementable'. */ IInputOrOutputIterator& operator++(); - /** Post-increment operator. See 'IWeaklyIncrementable'. */ void operator++(int); + // ~End CWeklyIncrementable. + /** Dereference operator. It does not matter what the return type is, as long as it is referenceable. */ T operator*() const; }; -// Use 'IInputOrOutputIterator' represents an input or output iterator. +// Use IInputOrOutputIterator represents an input or output iterator. static_assert(CInputOrOutputIterator>); /** A concept specifies a type is an input iterator. */ @@ -235,29 +222,30 @@ concept CInputIterator = CInputOrOutputIterator && CIndirectlyReadable; template struct IInputIterator /* : IInputOrOutputIterator, IIndirectlyReadable */ { - /** The element type of the indirectly readable type. See 'IIndirectlyReadable'. */ + // ~Begin CIndirectlyReadable. + using ElementType = TRemoveCVRef; - /** Move constructor. See 'IWeaklyIncrementable'. */ - IInputIterator(IInputIterator&&); + // ~End CIndirectlyReadable. - /** Move assignment operator. See 'IWeaklyIncrementable'. */ + // ~Begin CInputOrOutputIterator. + + IInputIterator(IInputIterator&&); IInputIterator* operator=(IInputIterator&&); - /** Indirectly read the element from the indirectly readable type. See 'IIndirectlyReadable'. */ - T operator*() const; + T operator*() const; // Also satisfies CIndirectlyReadable. - /** Pre-increment operator. See 'IWeaklyIncrementable'. */ IInputIterator& operator++(); - /** Post-increment operator. See 'IWeaklyIncrementable'. */ void operator++(int); + + // ~End CInputOrOutputIterator. }; -// Use 'IInputIterator' represents an input iterator and 'int' is the regular element type. +// Use IInputIterator represents an input iterator and int is the regular element type. static_assert(CInputIterator> && CRegular); -// The 'CInputIterator' requires this code is valid. +// The CInputIterator requires this code is valid. static_assert( requires(IInputIterator Iter, int& A) { @@ -277,32 +265,31 @@ concept COutputIterator = CInputOrOutputIterator && CIndirectlyWritable template struct IOutputIterator /* : IInputOrOutputIterator, IIndirectlyWritable */ { - /** Move constructor. See 'IWeaklyIncrementable'. */ - IOutputIterator(IOutputIterator&&); + // ~Begin CIndirectlyWritable. - /** Move assignment operator. See 'IWeaklyIncrementable'. */ + IOutputIterator(IOutputIterator&&); IOutputIterator* operator=(IOutputIterator&&); - /** Indirectly write the element from the indirectly writable type. See 'IIndirectlyWritable'. */ - T operator*() const; + T operator*() const; // Also satisfies CIndirectlyWritable. - /** Pre-increment operator. See 'IWeaklyIncrementable'. */ IOutputIterator& operator++(); /** * Post-increment operator. * Specify, the concept not requires the return type is self type, * but requires the expression '*Iter++ = A;' is equivalent to '*Iter = A; ++Iter;'. - * This means that returning a proxy class that satisfies 'CIndirectlyWritable' is also valid. - * See 'IWeaklyIncrementable'. + * This means that returning a proxy class that satisfies CIndirectlyWritable is also valid. + * Also satisfies CIndirectlyWritable. */ IIndirectlyWritable operator++(int); + + // ~End CIndirectlyWritable. }; -// Use 'IOutputIterator' represents an output iterator and 'int' is the regular element type. +// Use IOutputIterator represents an output iterator and int is the regular element type. static_assert(COutputIterator, int> && CRegular); -// The 'CInputIterator' requires this code is valid. +// The CInputIterator requires this code is valid. static_assert( requires(IOutputIterator Iter, int& A) {