![]() |
aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
|
Safe iterators for Lists. More...
#include <agrum/tools/core/list.h>
Public Member Functions | |
template<typename Alloc > | |
INLINE | ListIteratorSafe (const List< Val, Alloc > &theList) |
template<typename Alloc > | |
INLINE | ListIteratorSafe (const List< Val, Alloc > &theList, Size ind_elt) |
Constructors / Destructors | |
ListIteratorSafe () noexcept | |
Default constructor. More... | |
template<typename Alloc > | |
ListIteratorSafe (const List< Val, Alloc > &theList) | |
Constructor for a begin. More... | |
ListIteratorSafe (const ListIteratorSafe< Val > &src) | |
Copy constructor. More... | |
template<typename Alloc > | |
ListIteratorSafe (const List< Val, Alloc > &theList, Size ind_elt) | |
Constructor for an iterator pointing to the ind_eltth element of a List. More... | |
ListIteratorSafe (ListIteratorSafe< Val > &&src) | |
Move constructor. More... | |
~ListIteratorSafe () | |
Class Desctructor. More... | |
Operators | |
ListIteratorSafe< Val > & | operator= (const ListIteratorSafe< Val > &src) |
Copy operator. More... | |
ListIteratorSafe< Val > & | operator= (ListIteratorSafe< Val > &&src) |
Move operator. More... | |
ListIteratorSafe< Val > & | operator++ () noexcept |
Makes the iterator point to the next element in the List. More... | |
ListIteratorSafe< Val > & | operator+= (difference_type i) noexcept |
Makes the iterator point to i elements further in the List. More... | |
ListIteratorSafe< Val > & | operator-- () noexcept |
Makes the iterator point to the preceding element in the List. More... | |
ListIteratorSafe< Val > & | operator-= (difference_type i) noexcept |
Makes the iterator point to i elements befor in the List. More... | |
ListIteratorSafe< Val > | operator+ (difference_type i) noexcept |
Returns a new iterator pointing to i further elements in the gum::List. More... | |
ListIteratorSafe< Val > | operator- (difference_type i) noexcept |
Returns a new iterator pointing to i preceding elements in the gum::List. More... | |
Val & | operator* () |
Gives access to the content of the iterator. More... | |
Val * | operator-> () |
Dereferences the value pointed to by the iterator. More... | |
Accessors / Modifiers | |
void | clear () |
Makes the iterator point toward nothing. More... | |
void | setToEnd () |
Positions the iterator to the end of the list. More... | |
bool | isEnd () const |
Returns a bool indicating whether the iterator points to the end of the list. More... | |
Operators | |
bool | operator!= (const ListConstIteratorSafe< Val > &src) const |
Checks whether two iterators point toward different elements. More... | |
bool | operator== (const ListConstIteratorSafe< Val > &src) const |
Checks whether two iterators point toward the same elements. More... | |
const Val & | operator* () const |
Gives access to the content of the iterator. More... | |
const Val * | operator-> () const |
Dereferences the value pointed to by the iterator. More... | |
Public Types | |
using | iterator_category = std::bidirectional_iterator_tag |
Types for STL compliance. More... | |
using | value_type = Val |
Types for STL compliance. More... | |
using | reference = Val & |
Types for STL compliance. More... | |
using | const_reference = const Val & |
Types for STL compliance. More... | |
using | pointer = Val * |
Types for STL compliance. More... | |
using | const_pointer = const Val * |
Types for STL compliance. More... | |
using | difference_type = std::ptrdiff_t |
Types for STL compliance. More... | |
Safe iterators for Lists.
Class ListIteratorSafe implements iterators for List. However, developers may consider using List<x>::iterator_safe instead of ListIteratorSafe<x>.
These iterators ensure that whenever they point to an element that is being deleted from memory, their accessing this element will never produce a segmentation fault but rather throw an exception. Similarly, incrementing or decrementing an iterator pointing to a deleted element is guaranteed to make the iterator point on the next (or preceding) element that has not been deleted. This enables safely writing code like:
Val | The gum::List values type. |
using gum::ListIteratorSafe< Val >::const_pointer = const Val* |
using gum::ListIteratorSafe< Val >::const_reference = const Val& |
using gum::ListIteratorSafe< Val >::difference_type = std::ptrdiff_t |
using gum::ListIteratorSafe< Val >::iterator_category = std::bidirectional_iterator_tag |
using gum::ListIteratorSafe< Val >::pointer = Val* |
using gum::ListIteratorSafe< Val >::reference = Val& |
using gum::ListIteratorSafe< Val >::value_type = Val |
|
noexcept |
Default constructor.
Returns an iterator pointing toward nothing.
Definition at line 944 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
gum::ListIteratorSafe< Val >::ListIteratorSafe | ( | const List< Val, Alloc > & | theList | ) |
Constructor for a begin.
Alloc | The gum::List allocator. |
INLINE gum::ListIteratorSafe< Val >::ListIteratorSafe | ( | const ListIteratorSafe< Val > & | src | ) |
Copy constructor.
src | The gum::ListConstIteratorSafe to copy. |
Definition at line 958 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
gum::ListIteratorSafe< Val >::ListIteratorSafe | ( | const List< Val, Alloc > & | theList, |
Size | ind_elt | ||
) |
Constructor for an iterator pointing to the ind_eltth element of a List.
theList | The list to iterate over. |
ind_elt | The iterator starting position. |
UndefinedIteratorValue | Raised if the element does not exist in the list. |
INLINE gum::ListIteratorSafe< Val >::ListIteratorSafe | ( | ListIteratorSafe< Val > && | src | ) |
Move constructor.
src | The gum::ListConstIterator to move. |
Definition at line 975 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE gum::ListIteratorSafe< Val >::~ListIteratorSafe | ( | ) |
Class Desctructor.
Definition at line 1002 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE gum::ListIteratorSafe< Val >::ListIteratorSafe | ( | const List< Val, Alloc > & | theList | ) |
Definition at line 951 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE gum::ListIteratorSafe< Val >::ListIteratorSafe | ( | const List< Val, Alloc > & | theList, |
Size | ind_elt | ||
) |
Definition at line 967 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Makes the iterator point toward nothing.
A method for detaching the iterator from the List it is attached to. It is mainly used by the List when the latter is deleted while the iterator is still alive. After being detached, the iterator does not point to any element, i.e., trying to access its content will raise an exception.
Definition at line 676 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Returns a bool indicating whether the iterator points to the end of the list.
Definition at line 695 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Checks whether two iterators point toward different elements.
list1.end()
== list2.rend()
.src | The gum::ListConstIteratorSafe to test for inequality. |
Definition at line 888 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Gives access to the content of the iterator.
UndefinedIteratorValue | Raised if the iterator points to nothing. |
Definition at line 915 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE Val & gum::ListIteratorSafe< Val >::operator* | ( | ) |
Gives access to the content of the iterator.
UndefinedIteratorValue | Raised if the iterator points to nothing. |
Definition at line 1058 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
noexcept |
Returns a new iterator pointing to i further elements in the gum::List.
i | The number of steps to move the iterator. |
Definition at line 1038 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
noexcept |
Makes the iterator point to the next element in the List.
The above loop is guaranteed to parse the whole List as long as no element is added to or deleted from the List while being in the loop. Runs in constant time.
Definition at line 1008 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
noexcept |
Makes the iterator point to i elements further in the List.
i | The number of steps to move the iterator. |
Definition at line 1015 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
noexcept |
Returns a new iterator pointing to i preceding elements in the gum::List.
i | The number of steps to move the iterator. |
Definition at line 1045 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
noexcept |
Makes the iterator point to the preceding element in the List.
The above loop is guaranteed to parse the whole List as long as no element is added to or deleted from the List while being in the loop. Runs in constant time.
Definition at line 1023 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
noexcept |
Makes the iterator point to i elements befor in the List.
i | The number of steps to move the iterator. |
Definition at line 1030 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Dereferences the value pointed to by the iterator.
UndefinedIteratorValue | Raised if the iterator points to nothing. |
Definition at line 905 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE Val * gum::ListIteratorSafe< Val >::operator-> | ( | ) |
Dereferences the value pointed to by the iterator.
UndefinedIteratorValue | Raised if the iterator points to nothing. |
Definition at line 1052 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE ListIteratorSafe< Val > & gum::ListIteratorSafe< Val >::operator= | ( | const ListIteratorSafe< Val > & | src | ) |
Copy operator.
The current iterator now points to the same element as iterator from.
src | The gum::ListIteratorSafe to copy. |
Definition at line 983 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
INLINE ListIteratorSafe< Val > & gum::ListIteratorSafe< Val >::operator= | ( | ListIteratorSafe< Val > && | src | ) |
Move operator.
src | The gum::ListIteratorSafe to move. |
Definition at line 993 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Checks whether two iterators point toward the same elements.
list1.end()
== list2.rend()
.src | The gum::ListConstIteratorSafe to test for equality. |
Definition at line 897 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().
|
inherited |
Positions the iterator to the end of the list.
Definition at line 688 of file list_tpl.h.
References gum::Set< Key, Alloc >::emplace().