ORIGINAL
Loading...
Searching...
No Matches
original::iterable< TYPE > Class Template Referenceabstract

A base class for iterable containers that support multiple iteration patterns. More...

#include <iterable.h>

Inheritance diagram for original::iterable< TYPE >:
Inheritance graph
Collaboration diagram for original::iterable< TYPE >:
Collaboration graph

Classes

class  iterAdaptor
 RAII wrapper for base iterators that provides standard iteration interface. More...
 

Public Member Functions

iterAdaptor begin ()
 Returns an iterator adapter pointing to the beginning of the container.
 
iterAdaptor end ()
 Returns an iterator adapter pointing to the end sentinel of the container.
 
iterAdaptor begin () const
 Returns a const iterator adapter pointing to the beginning of the container.
 
iterAdaptor end () const
 Returns a const iterator adapter pointing to the end sentinel of the container.
 
iterAdaptor first ()
 Returns an iterator adapter pointing to the first element.
 
iterAdaptor last ()
 Returns an iterator adapter pointing to the last element.
 
iterAdaptor first () const
 Returns a const iterator adapter pointing to the first element.
 
iterAdaptor last () const
 Returns a const iterator adapter pointing to the last element.
 
virtual baseIterator< TYPE > * begins () const =0
 Returns the iterator to the beginning of the container.
 
virtual baseIterator< TYPE > * ends () const =0
 Returns the iterator to the end of the container.
 
template<typename Callback = transform<TYPE>>
requires Operation<Callback, TYPE>
void forEach (Callback operation=Callback{})
 Applies a given operation to each element in the iterable container.
 
template<typename Callback = transform<TYPE>>
requires Operation<Callback, TYPE>
void forEach (const Callback &operation=Callback{}) const
 Applies a given operation to each element in the iterable container (const version).
 
template<typename Callback>
requires original::Operation<Callback, TYPE>
auto forEach (Callback operation) -> void
 
template<typename Callback>
requires original::Operation<Callback, TYPE>
auto forEach (const Callback &operation) const -> void
 

Detailed Description

template<typename TYPE>
class original::iterable< TYPE >

A base class for iterable containers that support multiple iteration patterns.

Template Parameters
TYPEThe type of elements contained in the iterable.

This class defines the complete iterable container interface with:

The class provides three levels of iteration interface:

  1. Low-level: begins()/ ends() - Factory methods returning raw base iterators
  2. Mid-level: first()/ last() - RAII-wrapped direct element access
  3. High-level: begin()/ end() - STL-compatible range iteration
Note
Derived classes must implement begins()/ends() to return their specific iterator type (covariant return types supported). All other iteration methods build upon these primitives.

Example usage patterns:

// Range-based for loop (STL compatible)
for (auto& item : container) { ... }
// Direct element access
auto first = container.first();
auto last = container.last();
// Polymorphic iteration
baseIterator<T>* it = container.begins();
A base class for basic iterators.
Definition iterator.h:296
Abstract base class for containers.
Definition container.h:28
iterAdaptor first()
Returns an iterator adapter pointing to the first element.
Definition iterable.h:561
iterAdaptor last()
Returns an iterator adapter pointing to the last element.
Definition iterable.h:567
See also
iterator.h For base iterator implementation
iterAdaptor For the RAII iterator wrapper

Member Function Documentation

◆ begin() [1/2]

template<typename TYPE>
auto original::iterable< TYPE >::begin ( )

Returns an iterator adapter pointing to the beginning of the container.

Returns
An iterAdaptor wrapping the container's begin iterator.

Provides standard library-compatible iteration support by:

  • Calling begins() to get the base iterator
  • Wrapping it in an iterAdaptor for RAII management
  • Supporting range-based for loops
Note
The iterAdaptor automatically manages the base iterator's lifetime. This is the preferred interface for standard iteration patterns.

Example:

for (auto& item : container) { ... } // Uses begin()/end()

◆ begin() [2/2]

template<typename TYPE>
auto original::iterable< TYPE >::begin ( ) const

Returns a const iterator adapter pointing to the beginning of the container.

Returns
A const iterAdaptor wrapping the container's begin iterator.

Const version of begin() with same RAII and iteration support.

◆ begins()

template<typename TYPE>
virtual baseIterator< TYPE > * original::iterable< TYPE >::begins ( ) const
pure virtual

Returns the iterator to the beginning of the container.

Returns
A pointer to the base iterator that marks the start of the container.

This method is used internally by begin(), but can be accessed directly for other purposes. Derived classes should implement this with covariant return types, returning their specific iterator type (which must inherit from baseIterator<TYPE>).

Note
This is a polymorphic factory method - each derived container should return its own specialized iterator type. The caller is responsible for managing the returned pointer.

Example:

// In derived container class:
myIterator* begins() const override { return new myIterator(...); }
virtual baseIterator< TYPE > * begins() const =0
Returns the iterator to the beginning of the container.

Implemented in original::array< TYPE, ALLOC >, original::array< underlying_type, rebind_alloc_underlying >, original::bitSet< ALLOC >, original::blocksList< TYPE, ALLOC >, original::blocksList< TYPE, allocator< TYPE > >, original::chain< TYPE, ALLOC >, original::chain< opts >, original::chain< original::strongPtr< original::filter< TYPE > > >, original::chain< original::strongPtr< original::transform< TYPE > > >, original::chain< TYPE, allocator< TYPE > >, original::forwardChain< TYPE, ALLOC >, original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >, original::hashSet< TYPE, HASH, ALLOC >, original::JMap< K_TYPE, V_TYPE, Compare, ALLOC >, original::JSet< TYPE, Compare, ALLOC >, original::treeMap< K_TYPE, V_TYPE, Compare, ALLOC >, original::treeSet< TYPE, Compare, ALLOC >, original::vector< TYPE, ALLOC >, original::vector< hashNode *, rebind_alloc_pointer >, original::vector< hashNode *, rebind_alloc_pointer >, original::vector< original::hashTable::hashNode *, rebind_alloc_pointer >, original::vector< original::skipList::skipListNode * >, and original::vector< TYPE * >.

◆ end() [1/2]

template<typename TYPE>
auto original::iterable< TYPE >::end ( )

Returns an iterator adapter pointing to the end sentinel of the container.

Returns
An iterAdaptor wrapping one past the last element.

Provides standard library-compatible iteration support by:

  • Calling ends() and advancing once to create the sentinel
  • Wrapping it in an iterAdaptor for RAII management
  • Supporting range-based for loops
Note
The iterAdaptor automatically manages the base iterator's lifetime. This is the preferred interface for standard iteration patterns.

Example:

for (auto& item : container) { ... } // Uses begin()/end()

◆ end() [2/2]

template<typename TYPE>
auto original::iterable< TYPE >::end ( ) const

Returns a const iterator adapter pointing to the end sentinel of the container.

Returns
A const iterAdaptor wrapping one past the last element.

Const version of end() with same RAII and iteration support.

◆ ends()

template<typename TYPE>
virtual baseIterator< TYPE > * original::iterable< TYPE >::ends ( ) const
pure virtual

Returns the iterator to the end of the container.

Returns
A pointer to the base iterator that marks the end of the container.

This method is used internally by end(), but can be accessed directly for other purposes. Derived classes should implement this with covariant return types, returning their specific iterator type (which must inherit from baseIterator<TYPE>).

Note
This is a polymorphic factory method - each derived container should return its own specialized iterator type. The caller is responsible for managing the returned pointer.

Example:

// In derived container class:
myIterator* ends() const override { return new myIterator(...); }
virtual baseIterator< TYPE > * ends() const =0
Returns the iterator to the end of the container.

Implemented in original::array< TYPE, ALLOC >, original::array< underlying_type, rebind_alloc_underlying >, original::bitSet< ALLOC >, original::blocksList< TYPE, ALLOC >, original::blocksList< TYPE, allocator< TYPE > >, original::chain< TYPE, ALLOC >, original::chain< opts >, original::chain< original::strongPtr< original::filter< TYPE > > >, original::chain< original::strongPtr< original::transform< TYPE > > >, original::chain< TYPE, allocator< TYPE > >, original::forwardChain< TYPE, ALLOC >, original::hashMap< K_TYPE, V_TYPE, HASH, ALLOC >, original::hashSet< TYPE, HASH, ALLOC >, original::JMap< K_TYPE, V_TYPE, Compare, ALLOC >, original::JSet< TYPE, Compare, ALLOC >, original::treeMap< K_TYPE, V_TYPE, Compare, ALLOC >, original::treeSet< TYPE, Compare, ALLOC >, original::vector< TYPE, ALLOC >, original::vector< hashNode *, rebind_alloc_pointer >, original::vector< hashNode *, rebind_alloc_pointer >, original::vector< original::hashTable::hashNode *, rebind_alloc_pointer >, original::vector< original::skipList::skipListNode * >, and original::vector< TYPE * >.

◆ first() [1/2]

template<typename TYPE>
auto original::iterable< TYPE >::first ( )

Returns an iterator adapter pointing to the first element.

Returns
An iterAdaptor wrapping begins() without position adjustment.

Provides direct access to the first element without the standard library's past-the-end semantics. Uses RAII through iterAdaptor for automatic memory management.

Note
Unlike begin()/ end(), first()/ last() provide direct element access without position adjustments. Useful when you need explicit first/last element access.

◆ first() [2/2]

template<typename TYPE>
auto original::iterable< TYPE >::first ( ) const

Returns a const iterator adapter pointing to the first element.

Returns
A const iterAdaptor wrapping begins() without position adjustment.

Const version of first() with same RAII semantics.

◆ forEach() [1/2]

template<typename TYPE>
template<typename Callback = transform<TYPE>>
requires Operation<Callback, TYPE>
void original::iterable< TYPE >::forEach ( Callback operation = Callback{})

Applies a given operation to each element in the iterable container.

Template Parameters
CallbackA callable object that defines the operation to be applied to each element.
Parameters
operationThe operation to be applied.

◆ forEach() [2/2]

template<typename TYPE>
template<typename Callback = transform<TYPE>>
requires Operation<Callback, TYPE>
void original::iterable< TYPE >::forEach ( const Callback & operation = Callback{}) const

Applies a given operation to each element in the iterable container (const version).

Template Parameters
CallbackA callable object that defines the operation to be applied to each element.
Parameters
operationThe operation to be applied.

◆ last() [1/2]

template<typename TYPE>
auto original::iterable< TYPE >::last ( )

Returns an iterator adapter pointing to the last element.

Returns
An iterAdaptor wrapping ends() without position adjustment.

Provides direct access to the last element. Uses RAII through iterAdaptor for automatic memory management.

Note
Unlike begin()/ end(), first()/ last() provide direct element access without position adjustments. Useful when you need explicit first/last element access.

◆ last() [2/2]

template<typename TYPE>
auto original::iterable< TYPE >::last ( ) const

Returns a const iterator adapter pointing to the last element.

Returns
A const iterAdaptor wrapping ends() without position adjustment.

Const version of last() with same RAII semantics.


The documentation for this class was generated from the following file: