|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Iterator on the items of array. More...
#include <tpl_dynArray.H>
Public Types | |
| using | Set_Type = DynArray |
| using | aleph_random_access_iterator = Iterator |
| Opt-in marker for StlIterator random-access promotion. | |
Public Member Functions | |
| Iterator () noexcept=default | |
| Default constructor creates an "end" iterator. | |
| Iterator (DynArray &array) noexcept | |
| Iterator on a modifiable array. | |
| bool | has_curr () const noexcept |
| Check whether the iterator refers to an item. | |
| bool | is_last () const noexcept |
| Check whether the current item is the last item. | |
| T & | get_curr_ne () const |
| Return the current item without checking the position. | |
| T & | get_curr () const |
| Return the current item. | |
| long | get_pos () const noexcept |
| Return the ordinal position of current item. | |
| void | next_ne () noexcept |
| Move the iterator one position forward guaranteeing no exception. | |
| void | next () |
| Advance one position, from the last item to the end if needed. | |
| void | prev_ne () noexcept |
| Move the iterator one position backward guaranteeing no exception. | |
| void | prev () |
| Move the current a position backward. | |
| void | reset_last () noexcept |
| Reset the iterator to the last item. | |
| void | end () noexcept |
| Put the iterator in the end state. | |
| void | reset_first () noexcept |
| Reset the iterator to the first item. | |
| void | set_pos (const long pos) noexcept |
Put the iterator on position pos, without checking it. | |
Protected Member Functions | |
| Iterator (const DynArray &array) noexcept | |
| Iterator on a constant array; it never allocates. | |
Protected Attributes | |
| DynArray * | array_ptr = nullptr |
| long | curr_idx = 0 |
| bool | modifiable = false |
| built on a modifiable array: reading an unwritten entry allocates it | |
Friends | |
| class | Aleph::Const_Iterator< Iterator > |
Iterator on the items of array.
The visit order is from the lower index 0 to current dimension minus one.
What the iterator does with an entry that was never written depends on the array it was built on:
To read a modifiable array without allocating, iterate it through a constant reference, as std::as_const(a) gives.
Definition at line 1851 of file tpl_dynArray.H.
| using Aleph::DynArray< T >::Iterator::aleph_random_access_iterator = Iterator |
Opt-in marker for StlIterator random-access promotion.
It is the iterator's own type on purpose: derived iterators that reuse this class as a base, and may redefine its positions, do NOT inherit the promotion, because their own type differs from this marker. This keeps the promotion fail-safe.
Definition at line 1866 of file tpl_dynArray.H.
| using Aleph::DynArray< T >::Iterator::Set_Type = DynArray |
Definition at line 1859 of file tpl_dynArray.H.
|
defaultnoexcept |
Default constructor creates an "end" iterator.
|
inlinenoexcept |
Iterator on a modifiable array.
Reading an entry that was never written through get_curr() allocates its block, as a[i] does.
| [in] | array | array to iterate. |
Definition at line 1878 of file tpl_dynArray.H.
|
inlineprotectednoexcept |
Iterator on a constant array; it never allocates.
An entry that was never written is seen as the default value. It is the view of DynArray::Const_Iterator, and of the iterators that derive from this one: a constant array is iterated through Const_Iterator, which hands out references to const.
| [in] | array | array to iterate. |
Definition at line 1893 of file tpl_dynArray.H.
|
inlinenoexcept |
Put the iterator in the end state.
Definition at line 2014 of file tpl_dynArray.H.
References Aleph::DynArray< T >::Iterator::array_ptr, Aleph::DynArray< T >::Iterator::curr_idx, and Aleph::DynArray< T >::size().
|
inline |
Return the current item.
| std::underflow_error | if positioned before the first item. |
| std::overflow_error | if singular or at or past the end. |
| std::bad_alloc | only on a modifiable array, if the block of an entry never written cannot be allocated. |
Definition at line 1956 of file tpl_dynArray.H.
References ah_overflow_error_if, ah_underflow_error_if, Aleph::DynArray< T >::Iterator::array_ptr, Aleph::DynArray< T >::Iterator::curr_idx, Aleph::DynArray< T >::Iterator::get_curr_ne(), and Aleph::DynArray< T >::size().
|
inline |
Return the current item without checking the position.
Same as get_curr(), without the check of the position, for the pattern for (...; it.has_curr(); it.next_ne()).
| std::bad_alloc | only on a modifiable array, if the block of an entry never written cannot be allocated. |
Definition at line 1936 of file tpl_dynArray.H.
References Aleph::DynArray< T >::Iterator::array_ptr, Aleph::DynArray< T >::Iterator::curr_idx, Aleph::DynArray< T >::default_initial_value, Aleph::DynArray< T >::Iterator::modifiable, Aleph::DynArray< T >::test(), and Aleph::DynArray< T >::touch().
Referenced by Aleph::DynArray< T >::Iterator::get_curr().
|
inlinenoexcept |
Return the ordinal position of current item.
Definition at line 1966 of file tpl_dynArray.H.
References Aleph::DynArray< T >::Iterator::curr_idx.
|
inlinenoexcept |
Check whether the iterator refers to an item.
A default-constructed (singular) iterator behaves as an empty sequence.
true if there is a current item; false for singular, empty, or out-of-range iterators. Definition at line 1907 of file tpl_dynArray.H.
References FunctionalMethods< DynArray< T >, T >::and, Aleph::DynArray< T >::Iterator::array_ptr, Aleph::DynArray< T >::Iterator::curr_idx, and Aleph::DynArray< T >::size().
Referenced by Aleph::DynArray< T >::Iterator::is_last(), main(), and main().
|
inlinenoexcept |
Check whether the current item is the last item.
true only when a current item exists and it is the last; false for singular or empty iterators. Definition at line 1918 of file tpl_dynArray.H.
References FunctionalMethods< DynArray< T >, T >::and, Aleph::DynArray< T >::Iterator::array_ptr, Aleph::DynArray< T >::Iterator::curr_idx, Aleph::DynArray< T >::Iterator::has_curr(), and Aleph::DynArray< T >::size().
|
inline |
Advance one position, from the last item to the end if needed.
| std::overflow_error | if the iterator is singular or already at or past the end. |
Definition at line 1983 of file tpl_dynArray.H.
References ah_overflow_error_if, FunctionalMethods< DynArray< T >, T >::and, Aleph::DynArray< T >::Iterator::array_ptr, Aleph::DynArray< T >::Iterator::curr_idx, Aleph::DynArray< T >::Iterator::next_ne(), and Aleph::DynArray< T >::size().
|
inlinenoexcept |
Move the iterator one position forward guaranteeing no exception.
Be careful.
Definition at line 1973 of file tpl_dynArray.H.
References Aleph::DynArray< T >::Iterator::curr_idx.
Referenced by Aleph::DynArray< T >::Iterator::next().
|
inline |
Move the current a position backward.
Throw underflow_error if current is the first item
Definition at line 2001 of file tpl_dynArray.H.
References ah_underflow_error_if, Aleph::DynArray< T >::Iterator::curr_idx, and Aleph::DynArray< T >::Iterator::prev_ne().
Referenced by main().
|
inlinenoexcept |
Move the iterator one position backward guaranteeing no exception.
Be careful.
Definition at line 1994 of file tpl_dynArray.H.
References Aleph::DynArray< T >::Iterator::curr_idx.
Referenced by Aleph::DynArray< T >::Iterator::prev().
|
inlinenoexcept |
Reset the iterator to the first item.
Definition at line 2020 of file tpl_dynArray.H.
References Aleph::DynArray< T >::Iterator::curr_idx.
|
inlinenoexcept |
Reset the iterator to the last item.
Definition at line 2008 of file tpl_dynArray.H.
References Aleph::DynArray< T >::Iterator::array_ptr, Aleph::DynArray< T >::Iterator::curr_idx, and Aleph::DynArray< T >::size().
Referenced by main().
|
inlinenoexcept |
Put the iterator on position pos, without checking it.
Definition at line 2026 of file tpl_dynArray.H.
References Aleph::DynArray< T >::Iterator::curr_idx.
Referenced by Aleph::DynArray< T >::get_it().
|
friend |
Definition at line 1893 of file tpl_dynArray.H.
|
protected |
Definition at line 1854 of file tpl_dynArray.H.
Referenced by Aleph::DynArray< T >::Iterator::end(), Aleph::DynArray< T >::Iterator::get_curr(), Aleph::DynArray< T >::Iterator::get_curr_ne(), Aleph::DynArray< T >::Iterator::has_curr(), Aleph::DynArray< T >::Iterator::is_last(), Aleph::DynArray< T >::Iterator::next(), and Aleph::DynArray< T >::Iterator::reset_last().
|
protected |
Definition at line 1855 of file tpl_dynArray.H.
Referenced by Aleph::DynArray< T >::Iterator::end(), Aleph::DynArray< T >::Iterator::get_curr(), Aleph::DynArray< T >::Iterator::get_curr_ne(), Aleph::DynArray< T >::Iterator::get_pos(), Aleph::DynArray< T >::Iterator::has_curr(), Aleph::DynArray< T >::Iterator::is_last(), Aleph::DynArray< T >::Iterator::next(), Aleph::DynArray< T >::Iterator::next_ne(), Aleph::DynArray< T >::Iterator::prev(), Aleph::DynArray< T >::Iterator::prev_ne(), Aleph::DynArray< T >::Iterator::reset_first(), Aleph::DynArray< T >::Iterator::reset_last(), and Aleph::DynArray< T >::Iterator::set_pos().
|
protected |
built on a modifiable array: reading an unwritten entry allocates it
Definition at line 1856 of file tpl_dynArray.H.
Referenced by Aleph::DynArray< T >::Iterator::get_curr_ne().