style(iterator): organize comments to make them more human readable

This commit is contained in:
Redstone1024 2024-12-14 14:02:26 +08:00
parent 24dd4347d1
commit 5cfde63dd4
6 changed files with 119 additions and 171 deletions

View File

@ -31,38 +31,30 @@ concept CBidirectionalIterator = CForwardIterator<I>
template <CReference T> template <CReference T>
struct IBidirectionalIterator /* : IForwardIterator<T> */ struct IBidirectionalIterator /* : IForwardIterator<T> */
{ {
/** The element type of the indirectly readable type. See 'IIndirectlyReadable'. */ // ~Begin CForwardIterator.
using ElementType = TRemoveCVRef<T>; using ElementType = TRemoveCVRef<T>;
/** Default constructor. See 'IIncrementable' and 'ISentinelFor'. */
IBidirectionalIterator(); IBidirectionalIterator();
/** Copy constructor. See 'IIncrementable' and 'ISentinelFor'. */
IBidirectionalIterator(const IBidirectionalIterator&); IBidirectionalIterator(const IBidirectionalIterator&);
IBidirectionalIterator(IBidirectionalIterator&&);
/** Copy assignment operator. See 'IIncrementable' and 'ISentinelFor'. */
IBidirectionalIterator* operator=(const IBidirectionalIterator&); IBidirectionalIterator* operator=(const IBidirectionalIterator&);
IBidirectionalIterator* operator=(IBidirectionalIterator&&);
/** Equality operator. See 'IIncrementable' and 'ISentinelFor'. */
friend bool operator==(const IBidirectionalIterator&, const IBidirectionalIterator&); friend bool operator==(const IBidirectionalIterator&, const IBidirectionalIterator&);
/** Dereference operator. See 'IForwardIterator'. */
T operator*() const; T operator*() const;
/** Pre-increment operator. See 'IWeaklyIncrementable'. */ // ~End CForwardIterator.
IBidirectionalIterator& operator++();
/** Pre-decrement operator. */ IBidirectionalIterator& operator++(); // Also satisfies CForwardIterator.
IBidirectionalIterator& operator--(); IBidirectionalIterator& operator--();
/** Post-increment operator. See 'IIncrementable'. */ IBidirectionalIterator operator++(int); // Also satisfies CForwardIterator.
IBidirectionalIterator operator++(int);
/** Post-decrement operator. */
IBidirectionalIterator operator--(int); IBidirectionalIterator operator--(int);
}; };
// Use 'IBidirectionalIterator<int>' represents a bidirectional iterator. // Use IBidirectionalIterator<int> represents a bidirectional iterator.
static_assert(CBidirectionalIterator<IBidirectionalIterator<int&>>); static_assert(CBidirectionalIterator<IBidirectionalIterator<int&>>);
static_assert( COutputIterator<IBidirectionalIterator<int&>, int>); static_assert( COutputIterator<IBidirectionalIterator<int&>, int>);

View File

@ -17,7 +17,7 @@ NAMESPACE_MODULE_BEGIN(Utility)
/** /**
* A concept specifies a type is a contiguous iterator. * 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 <typename I> template <typename I>
concept CContiguousIterator = CRandomAccessIterator<I> && CLValueReference<TIteratorReference<I>> concept CContiguousIterator = CRandomAccessIterator<I> && CLValueReference<TIteratorReference<I>>
@ -30,74 +30,62 @@ concept CContiguousIterator = CRandomAccessIterator<I> && CLValueReference<TIter
/** This is an example of a contiguous iterator, indicate the traits that define a contiguous iterator. */ /** This is an example of a contiguous iterator, indicate the traits that define a contiguous iterator. */
template <CLValueReference T> template <CLValueReference T>
struct IContiguousIterator /* : IBidirectionalIterator<T> */ struct IContiguousIterator /* : IRandomAccessIterator<T> */
{ {
/** The element type of the indirectly readable type. See 'IIndirectlyReadable'. */ // ~Begin CRandomAccessIterator.
using ElementType = TRemoveCVRef<T>; using ElementType = TRemoveCVRef<T>;
/** Default constructor. See 'IIncrementable' and 'ISentinelFor'. */
IContiguousIterator(); IContiguousIterator();
/** Copy constructor. See 'IIncrementable' and 'ISentinelFor'. */
IContiguousIterator(const IContiguousIterator&); IContiguousIterator(const IContiguousIterator&);
IContiguousIterator(IContiguousIterator&&);
/** Copy assignment operator. See 'IIncrementable' and 'ISentinelFor'. */
IContiguousIterator* operator=(const IContiguousIterator&); IContiguousIterator* operator=(const IContiguousIterator&);
IContiguousIterator* operator=(IContiguousIterator&&);
/** Equality operator. See 'IIncrementable' and 'ISentinelFor'. */
friend bool operator==(const IContiguousIterator&, const IContiguousIterator&); friend bool operator==(const IContiguousIterator&, const IContiguousIterator&);
/** Three-way comparison operator. See 'IRandomAccessIterator'. */ friend strong_ordering operator<=>(const IContiguousIterator&, const IContiguousIterator&);
friend strong_ordering operator<=>(const IContiguousIterator& LHS, const IContiguousIterator& RHS);
// ~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. * 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; T operator*() const;
/** Indirection operator. Return the address of the element that the iterator is pointing to. */ /** Indirection operator. Return the address of the element that the iterator is pointing to. */
TAddPointer<T> operator->() const; TAddPointer<T> operator->() const;
/** Pre-increment operator. See 'IWeaklyIncrementable'. */ // ~Begin CRandomAccessIterator.
IContiguousIterator& operator++();
/** Pre-decrement operator. See 'IBidirectionalIterator'. */ T operator[](ptrdiff) const;
IContiguousIterator& operator++();
IContiguousIterator& operator--(); IContiguousIterator& operator--();
/** Post-increment operator. See 'IIncrementable'. */
IContiguousIterator operator++(int); IContiguousIterator operator++(int);
/** Post-decrement operator. See 'IBidirectionalIterator'. */
IContiguousIterator operator--(int); IContiguousIterator operator--(int);
/** Addition assignment operator. See 'IRandomAccessIterator'. */
IContiguousIterator& operator+=(ptrdiff); IContiguousIterator& operator+=(ptrdiff);
/** Subtraction assignment operator. See 'IRandomAccessIterator'. */
IContiguousIterator& operator-=(ptrdiff); IContiguousIterator& operator-=(ptrdiff);
/** Addition operator. See 'IRandomAccessIterator'. */
IContiguousIterator operator+(ptrdiff) const; IContiguousIterator operator+(ptrdiff) const;
/** Subtraction operator. See 'IRandomAccessIterator'. */
IContiguousIterator operator-(ptrdiff) const; IContiguousIterator operator-(ptrdiff) const;
/** Addition operator. See 'IRandomAccessIterator'. */
friend IContiguousIterator operator+(ptrdiff, const IContiguousIterator&); friend IContiguousIterator operator+(ptrdiff, const IContiguousIterator&);
/** Subtraction operator. See 'IRandomAccessIterator'. */
friend ptrdiff operator-(const IContiguousIterator&, const IContiguousIterator&); friend ptrdiff operator-(const IContiguousIterator&, const IContiguousIterator&);
/** Subscript operator. See 'IRandomAccessIterator'. */ // ~End CRandomAccessIterator.
T operator[](ptrdiff) const;
}; };
// Use 'IContiguousIterator<int>' represents a contiguous iterator // Use IContiguousIterator<int> represents a contiguous iterator
static_assert(CContiguousIterator<IContiguousIterator<int&>>); static_assert(CContiguousIterator<IContiguousIterator<int&>>);
static_assert( COutputIterator<IContiguousIterator<int&>, int>); static_assert( COutputIterator<IContiguousIterator<int&>, 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<int*>); static_assert(CContiguousIterator<int*>);
#if PLATFORM_COMPILER_GCC #if PLATFORM_COMPILER_GCC

View File

@ -20,37 +20,38 @@ concept CForwardIterator = CInputIterator<I> && CIncrementable<I> && CSentinelFo
/** This is an example of a forward iterator, indicate the traits that define a forward iterator. */ /** This is an example of a forward iterator, indicate the traits that define a forward iterator. */
template <CReference T> template <CReference T>
struct IForwardIterator /* : IInputIterator<T>, IIncrementable, ISentinelFor<I> */ struct IForwardIterator /* : IInputIterator<T>, IIncrementable, ISentinelFor<IForwardIterator> */
{ {
/** The element type of the indirectly readable type. See 'IIndirectlyReadable'. */ // ~Begin CInputIterator.
using ElementType = TRemoveCVRef<T>; using ElementType = TRemoveCVRef<T>;
/** Default constructor. See 'IIncrementable' and 'ISentinelFor'. */ // ~End CInputIterator.
// ~Begin CIncrementable and CSentinelFor<IForwardIterator>.
IForwardIterator(); IForwardIterator();
/** Copy constructor. See 'IIncrementable' and 'ISentinelFor'. */
IForwardIterator(const IForwardIterator&); IForwardIterator(const IForwardIterator&);
IForwardIterator(IForwardIterator&&); // Also satisfies IInputIterator.
/** Copy assignment operator. See 'IIncrementable' and 'ISentinelFor'. */
IForwardIterator* operator=(const IForwardIterator&); IForwardIterator* operator=(const IForwardIterator&);
IForwardIterator* operator=(IForwardIterator&&); // Also satisfies IInputIterator.
/** Equality operator. See 'IIncrementable' and 'ISentinelFor'. */
friend bool operator==(const IForwardIterator&, const IForwardIterator&); friend bool operator==(const IForwardIterator&, const IForwardIterator&);
/** // ~End CIncrementable and CSentinelFor<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;
/** Pre-increment operator. See 'IWeaklyIncrementable'. */ // ~Begin CInputIterator.
IForwardIterator& operator++();
/** Post-increment operator. See 'IIncrementable'. */ T operator*() const; // Optional satisfies CIndirectlyWritable.
IForwardIterator operator++(int);
IForwardIterator& operator++(); // Also satisfies CIncrementable.
IForwardIterator operator++(int); // Also satisfies CIncrementable.
// ~End CInputIterator.
}; };
// Use 'IForwardIterator<int>' represents a forward iterator. // Use IForwardIterator<int> represents a forward iterator.
static_assert(CForwardIterator<IForwardIterator<int&>>); static_assert(CForwardIterator<IForwardIterator<int&>>);
static_assert( COutputIterator<IForwardIterator<int&>, int>); static_assert( COutputIterator<IForwardIterator<int&>, int>);

View File

@ -33,64 +33,54 @@ concept CRandomAccessIterator = CBidirectionalIterator<I> && CTotallyOrdered<I>
/** This is an example of a random access iterator, indicate the traits that define a random access iterator. */ /** This is an example of a random access iterator, indicate the traits that define a random access iterator. */
template <CReference T> template <CReference T>
struct IRandomAccessIterator /* : IBidirectionalIterator<T> */ struct IRandomAccessIterator /* : IBidirectionalIterator<T>, ISizedSentinelFor<IRandomAccessIterator> */
{ {
/** The element type of the indirectly readable type. See 'IIndirectlyReadable'. */ // ~Begin CBidirectionalIterator.
using ElementType = TRemoveCVRef<T>; using ElementType = TRemoveCVRef<T>;
/** Default constructor. See 'IIncrementable' and 'ISentinelFor'. */ // ~End CBidirectionalIterator.
// ~Begin CBidirectionalIterator and CSizedSentinelFor<IRandomAccessIterator>.
IRandomAccessIterator(); IRandomAccessIterator();
/** Copy constructor. See 'IIncrementable' and 'ISentinelFor'. */
IRandomAccessIterator(const IRandomAccessIterator&); IRandomAccessIterator(const IRandomAccessIterator&);
IRandomAccessIterator(IRandomAccessIterator&&);
/** Copy assignment operator. See 'IIncrementable' and 'ISentinelFor'. */
IRandomAccessIterator* operator=(const IRandomAccessIterator&); IRandomAccessIterator* operator=(const IRandomAccessIterator&);
IRandomAccessIterator* operator=(IRandomAccessIterator&&);
/** Equality operator. See 'IIncrementable' and 'ISentinelFor'. */
friend bool operator==(const IRandomAccessIterator&, const IRandomAccessIterator&); friend bool operator==(const IRandomAccessIterator&, const IRandomAccessIterator&);
/** Three-way comparison operator. */ // ~End CBidirectionalIterator and CSizedSentinelFor<IRandomAccessIterator>.
friend strong_ordering operator<=>(const IRandomAccessIterator& LHS, const IRandomAccessIterator& RHS);
/** Dereference operator. See 'IForwardIterator'. */ friend strong_ordering operator<=>(const IRandomAccessIterator&, const IRandomAccessIterator&);
T operator*() const;
T operator*() const; // Also satisfies CBidirectionalIterator.
T operator[](ptrdiff) const;
// ~Begin CBidirectionalIterator.
/** Pre-increment operator. See 'IWeaklyIncrementable'. */
IRandomAccessIterator& operator++(); IRandomAccessIterator& operator++();
/** Pre-decrement operator. See 'IBidirectionalIterator'. */
IRandomAccessIterator& operator--(); IRandomAccessIterator& operator--();
/** Post-increment operator. See 'IIncrementable'. */
IRandomAccessIterator operator++(int); IRandomAccessIterator operator++(int);
/** Post-decrement operator. See 'IBidirectionalIterator'. */
IRandomAccessIterator operator--(int); IRandomAccessIterator operator--(int);
/** Addition assignment operator. */ // ~End CBidirectionalIterator.
IRandomAccessIterator& operator+=(ptrdiff);
/** Subtraction assignment operator. */ IRandomAccessIterator& operator+=(ptrdiff);
IRandomAccessIterator& operator-=(ptrdiff); IRandomAccessIterator& operator-=(ptrdiff);
/** Addition operator. */
IRandomAccessIterator operator+(ptrdiff) const; IRandomAccessIterator operator+(ptrdiff) const;
/** Subtraction operator. */
IRandomAccessIterator operator-(ptrdiff) const; IRandomAccessIterator operator-(ptrdiff) const;
/** Addition operator. */
friend IRandomAccessIterator operator+(ptrdiff, const IRandomAccessIterator&); friend IRandomAccessIterator operator+(ptrdiff, const IRandomAccessIterator&);
/** Subtraction operator. */ friend ptrdiff operator-(const IRandomAccessIterator&, const IRandomAccessIterator&); // Also satisfies CSizedSentinelFor<IRandomAccessIterator>.
friend ptrdiff operator-(const IRandomAccessIterator&, const IRandomAccessIterator&);
/** Subscript operator. */
T operator[](ptrdiff) const;
}; };
// Use 'IRandomAccessIterator<int>' represents a random access iterator // Use IRandomAccessIterator<int> represents a random access iterator
static_assert(CRandomAccessIterator<IRandomAccessIterator<int&>>); static_assert(CRandomAccessIterator<IRandomAccessIterator<int&>>);
static_assert( COutputIterator<IRandomAccessIterator<int&>, int>); static_assert( COutputIterator<IRandomAccessIterator<int&>, int>);

View File

@ -24,23 +24,17 @@ concept CSentinelFor = CSemiregular<S> && CInputOrOutputIterator<I> && CWeaklyEq
template <CInputOrOutputIterator I> template <CInputOrOutputIterator I>
struct ISentinelFor struct ISentinelFor
{ {
/** Default constructor. */
ISentinelFor(); ISentinelFor();
/** Copy constructor. */
ISentinelFor(const ISentinelFor&); ISentinelFor(const ISentinelFor&);
/** Copy assignment operator. */
ISentinelFor* operator=(const ISentinelFor&); ISentinelFor* operator=(const ISentinelFor&);
/** Equality operator. */
bool operator==(const I&) const&; bool operator==(const I&) const&;
}; };
// Use 'ISentinelFor' represents a sentinel for an iterator. // Use ISentinelFor represents a sentinel for an iterator.
static_assert(CSentinelFor<ISentinelFor<IInputOrOutputIterator<int>>, IInputOrOutputIterator<int>>); static_assert(CSentinelFor<ISentinelFor<IInputOrOutputIterator<int>>, IInputOrOutputIterator<int>>);
// The 'CSentinelFor' requires this code is valid. // The CSentinelFor requires this code is valid.
static_assert( static_assert(
requires(ISentinelFor<IInputOrOutputIterator<int>> Sentinel, IInputOrOutputIterator<int> Iter) requires(ISentinelFor<IInputOrOutputIterator<int>> Sentinel, IInputOrOutputIterator<int> Iter)
{ {
@ -49,7 +43,7 @@ static_assert(
} }
); );
/** Disable the 'CSizedSentinelFor' concept for specific types. */ /** Disable the CSizedSentinelFor concept for specific types. */
template <typename S, typename I> template <typename S, typename I>
inline constexpr bool bDisableSizedSentinelFor = false; inline constexpr bool bDisableSizedSentinelFor = false;
@ -71,27 +65,23 @@ concept CSizedSentinelFor = CSentinelFor<S, I>
template <CInputOrOutputIterator I> template <CInputOrOutputIterator I>
struct ISizedSentinelFor /* : ISentinelFor<I> */ struct ISizedSentinelFor /* : ISentinelFor<I> */
{ {
/** Default constructor. */ ISizedSentinelFor(); // Also satisfies ISentinelFor<I>.
ISizedSentinelFor();
/** Copy constructor. */
ISizedSentinelFor(const ISizedSentinelFor&); ISizedSentinelFor(const ISizedSentinelFor&);
ISizedSentinelFor(ISizedSentinelFor&&); // Also satisfies ISentinelFor<I>.
/** Copy assignment operator. */
ISizedSentinelFor& operator=(const ISizedSentinelFor&); ISizedSentinelFor& operator=(const ISizedSentinelFor&);
ISizedSentinelFor& operator=(ISizedSentinelFor&&); // Also satisfies ISentinelFor<I>.
/** Equality operator. */ bool operator==(const I&) const&; // Also satisfies ISentinelFor<I>.
bool operator==(const I&) const&;
/** Subtraction operator. The 'Sentinel - Iter' is equal to negative 'Iter - Sentinel'. */ /** Subtraction operator. The 'Sentinel - Iter' is equal to negative 'Iter - Sentinel'. */
friend ptrdiff operator-(const I&, const ISizedSentinelFor&); friend ptrdiff operator-(const I&, const ISizedSentinelFor&);
friend ptrdiff operator-(const ISizedSentinelFor&, const I&); 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<ISizedSentinelFor<IInputOrOutputIterator<int>>, IInputOrOutputIterator<int>>); static_assert(CSizedSentinelFor<ISizedSentinelFor<IInputOrOutputIterator<int>>, IInputOrOutputIterator<int>>);
// The 'CSentinelFor' requires this code is valid. // The CSentinelFor requires this code is valid.
static_assert( static_assert(
requires(ISizedSentinelFor<IInputOrOutputIterator<int>> Sentinel, IInputOrOutputIterator<int> Iter) requires(ISizedSentinelFor<IInputOrOutputIterator<int>> Sentinel, IInputOrOutputIterator<int> Iter)
{ {

View File

@ -76,18 +76,18 @@ struct IIndirectlyReadable
/** /**
* Indirectly read the element from the indirectly readable type. * 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 * 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. * 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. * 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. * If this is an iterator adaptor, use decltype(auto) to forward the return value.
*/ */
T operator*() const; T operator*() const;
}; };
// Use 'IIndirectlyReadable<int>' represents an indirectly readable type and 'int' is the regular element type. // Use IIndirectlyReadable<int> represents an indirectly readable type and int is the regular element type.
static_assert(CIndirectlyReadable<IIndirectlyReadable<int>> && CRegular<int>); static_assert(CIndirectlyReadable<IIndirectlyReadable<int>> && CRegular<int>);
// The 'CIndirectlyReadable' requires this code is valid. // The CIndirectlyReadable requires this code is valid.
static_assert( static_assert(
requires(IIndirectlyReadable<int> Iter, int& A) requires(IIndirectlyReadable<int> Iter, int& A)
{ {
@ -112,19 +112,19 @@ struct IIndirectlyWritable
{ {
/** /**
* Indirectly write the element from the indirectly writable type. * 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, * 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. * 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. * 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 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; T operator*() const;
}; };
// Use 'IIndirectlyWritable<int>' represents an indirectly writable type and 'int' is the regular element type. // Use IIndirectlyWritable<int> represents an indirectly writable type and int is the regular element type.
static_assert(CIndirectlyWritable<IIndirectlyWritable<int&>, int> && CRegular<int>); static_assert(CIndirectlyWritable<IIndirectlyWritable<int&>, int> && CRegular<int>);
// The 'CIndirectlyWritable' requires this code is valid. // The CIndirectlyWritable requires this code is valid.
static_assert( static_assert(
requires(IIndirectlyWritable<int&> Iter, int& A) requires(IIndirectlyWritable<int&> Iter, int& A)
{ {
@ -140,23 +140,16 @@ concept CWeaklyIncrementable = CMovable<I>
/** This is an example of a weakly incrementable type, indicate the traits that define a weakly incrementable type. */ /** This is an example of a weakly incrementable type, indicate the traits that define a weakly incrementable type. */
struct IWeaklyIncrementable struct IWeaklyIncrementable
{ {
/** Move constructor. */
IWeaklyIncrementable(IWeaklyIncrementable&&); IWeaklyIncrementable(IWeaklyIncrementable&&);
/** Move assignment operator. */
IWeaklyIncrementable* operator=(IWeaklyIncrementable&&); IWeaklyIncrementable* operator=(IWeaklyIncrementable&&);
/** Pre-increment operator. */
IWeaklyIncrementable& 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); void operator++(int);
}; };
// Use 'IWeaklyIncrementable' represents a weakly incrementable type. // Use IWeaklyIncrementable represents a weakly incrementable type.
static_assert(CWeaklyIncrementable<IWeaklyIncrementable>); static_assert(CWeaklyIncrementable<IWeaklyIncrementable>);
/** /**
@ -174,26 +167,21 @@ concept CIncrementable = CRegular<I> && CWeaklyIncrementable<I>
*/ */
struct IIncrementable /* : IWeaklyIncrementable */ struct IIncrementable /* : IWeaklyIncrementable */
{ {
/** Default constructor. */
IIncrementable(); IIncrementable();
/** Copy constructor. */
IIncrementable(const IIncrementable&); IIncrementable(const IIncrementable&);
IIncrementable(IIncrementable&&); // Also satisfies IWeaklyIncrementable.
/** Copy assignment operator. */
IIncrementable* operator=(const IIncrementable&); IIncrementable* operator=(const IIncrementable&);
IIncrementable* operator=(IIncrementable&&); // Also satisfies IWeaklyIncrementable.
/** Equality operator. */
friend bool operator==(const IIncrementable&, const IIncrementable&); friend bool operator==(const IIncrementable&, const IIncrementable&);
/** Pre-increment operator. See 'IWeaklyIncrementable'. */ IIncrementable& operator++(); // Also satisfies IWeaklyIncrementable.
IIncrementable& operator++();
/** Post-increment operator. */ /** Post-increment operator. Specify, the concept requires the return value is the original value before incrementing. */
IIncrementable operator++(int); IIncrementable operator++(int);
}; };
// Use 'IIncrementable' represents an incrementable type. // Use IIncrementable represents an incrementable type.
static_assert(CIncrementable<IIncrementable>); static_assert(CIncrementable<IIncrementable>);
/** /**
@ -208,23 +196,22 @@ concept CInputOrOutputIterator = CWeaklyIncrementable<I>
template <CReferenceable T> template <CReferenceable T>
struct IInputOrOutputIterator /* : IWeaklyIncrementable */ struct IInputOrOutputIterator /* : IWeaklyIncrementable */
{ {
/** Move constructor. See 'IWeaklyIncrementable'. */ // ~Begin CWeklyIncrementable.
IInputOrOutputIterator(IInputOrOutputIterator&&);
/** Move assignment operator. See 'IWeaklyIncrementable'. */ IInputOrOutputIterator(IInputOrOutputIterator&&);
IInputOrOutputIterator* operator=(IInputOrOutputIterator&&); IInputOrOutputIterator* operator=(IInputOrOutputIterator&&);
/** Pre-increment operator. See 'IWeaklyIncrementable'. */
IInputOrOutputIterator& operator++(); IInputOrOutputIterator& operator++();
/** Post-increment operator. See 'IWeaklyIncrementable'. */
void operator++(int); void operator++(int);
// ~End CWeklyIncrementable.
/** Dereference operator. It does not matter what the return type is, as long as it is referenceable. */ /** Dereference operator. It does not matter what the return type is, as long as it is referenceable. */
T operator*() const; T operator*() const;
}; };
// Use 'IInputOrOutputIterator' represents an input or output iterator. // Use IInputOrOutputIterator represents an input or output iterator.
static_assert(CInputOrOutputIterator<IInputOrOutputIterator<int>>); static_assert(CInputOrOutputIterator<IInputOrOutputIterator<int>>);
/** A concept specifies a type is an input iterator. */ /** A concept specifies a type is an input iterator. */
@ -235,29 +222,30 @@ concept CInputIterator = CInputOrOutputIterator<I> && CIndirectlyReadable<I>;
template <CReferenceable T> template <CReferenceable T>
struct IInputIterator /* : IInputOrOutputIterator, IIndirectlyReadable */ struct IInputIterator /* : IInputOrOutputIterator, IIndirectlyReadable */
{ {
/** The element type of the indirectly readable type. See 'IIndirectlyReadable'. */ // ~Begin CIndirectlyReadable.
using ElementType = TRemoveCVRef<T>; using ElementType = TRemoveCVRef<T>;
/** Move constructor. See 'IWeaklyIncrementable'. */ // ~End CIndirectlyReadable.
IInputIterator(IInputIterator&&);
/** Move assignment operator. See 'IWeaklyIncrementable'. */ // ~Begin CInputOrOutputIterator.
IInputIterator(IInputIterator&&);
IInputIterator* operator=(IInputIterator&&); IInputIterator* operator=(IInputIterator&&);
/** Indirectly read the element from the indirectly readable type. See 'IIndirectlyReadable'. */ T operator*() const; // Also satisfies CIndirectlyReadable.
T operator*() const;
/** Pre-increment operator. See 'IWeaklyIncrementable'. */
IInputIterator& operator++(); IInputIterator& operator++();
/** Post-increment operator. See 'IWeaklyIncrementable'. */
void operator++(int); void operator++(int);
// ~End CInputOrOutputIterator.
}; };
// Use 'IInputIterator<int>' represents an input iterator and 'int' is the regular element type. // Use IInputIterator<int> represents an input iterator and int is the regular element type.
static_assert(CInputIterator<IInputIterator<int>> && CRegular<int>); static_assert(CInputIterator<IInputIterator<int>> && CRegular<int>);
// The 'CInputIterator' requires this code is valid. // The CInputIterator requires this code is valid.
static_assert( static_assert(
requires(IInputIterator<int> Iter, int& A) requires(IInputIterator<int> Iter, int& A)
{ {
@ -277,32 +265,31 @@ concept COutputIterator = CInputOrOutputIterator<I> && CIndirectlyWritable<I, T>
template <CReference T> template <CReference T>
struct IOutputIterator /* : IInputOrOutputIterator, IIndirectlyWritable<T> */ struct IOutputIterator /* : IInputOrOutputIterator, IIndirectlyWritable<T> */
{ {
/** Move constructor. See 'IWeaklyIncrementable'. */ // ~Begin CIndirectlyWritable.
IOutputIterator(IOutputIterator&&);
/** Move assignment operator. See 'IWeaklyIncrementable'. */ IOutputIterator(IOutputIterator&&);
IOutputIterator* operator=(IOutputIterator&&); IOutputIterator* operator=(IOutputIterator&&);
/** Indirectly write the element from the indirectly writable type. See 'IIndirectlyWritable'. */ T operator*() const; // Also satisfies CIndirectlyWritable.
T operator*() const;
/** Pre-increment operator. See 'IWeaklyIncrementable'. */
IOutputIterator& operator++(); IOutputIterator& operator++();
/** /**
* Post-increment operator. * Post-increment operator.
* Specify, the concept not requires the return type is self type, * Specify, the concept not requires the return type is self type,
* but requires the expression '*Iter++ = A;' is equivalent to '*Iter = A; ++Iter;'. * but requires the expression '*Iter++ = A;' is equivalent to '*Iter = A; ++Iter;'.
* This means that returning a proxy class that satisfies 'CIndirectlyWritable<T>' is also valid. * This means that returning a proxy class that satisfies CIndirectlyWritable<T> is also valid.
* See 'IWeaklyIncrementable'. * Also satisfies CIndirectlyWritable.
*/ */
IIndirectlyWritable<T> operator++(int); IIndirectlyWritable<T> operator++(int);
// ~End CIndirectlyWritable.
}; };
// Use 'IOutputIterator<int>' represents an output iterator and 'int' is the regular element type. // Use IOutputIterator<int> represents an output iterator and int is the regular element type.
static_assert(COutputIterator<IOutputIterator<int&>, int> && CRegular<int>); static_assert(COutputIterator<IOutputIterator<int&>, int> && CRegular<int>);
// The 'CInputIterator' requires this code is valid. // The CInputIterator requires this code is valid.
static_assert( static_assert(
requires(IOutputIterator<int&> Iter, int& A) requires(IOutputIterator<int&> Iter, int& A)
{ {