iffl  1.3.4
Implements Intrusive Flat Forward List container
Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
iffl::flat_forward_list_iterator_t< T, TT > Class Template Referencefinal

THis class implements forward iterator for intrusive flat forward list. More...

#include <iffl_list.h>

Public Types

using iterator_category = std::forward_iterator_tag
 Marks iterator as a forward iterator.
 
using value_type = T
 Element value type.
 
using difference_type = ptrdiff_t
 Element pointers difference type.
 
using pointer = T *
 Pointer to element type.
 
using reference = T &
 Reference to the element type.
 
using traits = TT
 Element traits type.
 
using traits_traits = flat_forward_list_traits_traits< T, TT >
 Element traits-traits type.
 
using buffer_char_pointer = std::conditional_t< std::is_const_v< T >, char const *, char * >
 
using buffer_unsigned_char_pointer = std::conditional_t< std::is_const_v< T >, unsigned char const *, unsigned char * >
 
using buffer_void_pointer = std::conditional_t< std::is_const_v< T >, void const *, void * >
 
using size_with_padding_t = typename traits_traits::size_with_padding_t
 Vocabulary type used to describe size with padding.
 
using const_iterator = flat_forward_list_iterator_t< std::add_const_t< T >, TT >
 Const iterator is an iterator for a T const. More...
 
using non_const_iterator = flat_forward_list_iterator_t< std::remove_cv_t< T >, TT >
 [Non-const] iterator is an iterator for a T with no const qualifiers More...
 

Public Member Functions

constexpr flat_forward_list_iterator_t () noexcept=default
 Default initialize iterator. More...
 
constexpr flat_forward_list_iterator_t (flat_forward_list_iterator_t const &) noexcept=default
 Copy constructs an iterator.
 
constexpr flat_forward_list_iterator_t (flat_forward_list_iterator_t &&other) noexcept
 Move constructs iterator. More...
 
template<typename I , typename = std::enable_if_t<is_const_iterator && is_non_const_iterator_v<I>>>
constexpr flat_forward_list_iterator_t (I const &other) noexcept
 Unittest that is_non_const_iterator_v returns expected result. More...
 
template<typename I , typename = std::enable_if_t<is_const_iterator && is_non_const_iterator_v<I>>>
constexpr flat_forward_list_iterator_t (I &&other) noexcept
 Perfect forwarding constructor for const iterator from non-const iterator. More...
 
constexpr flat_forward_list_iterator_toperator= (flat_forward_list_iterator_t const &) noexcept=default
 Default generated copy constructor. More...
 
constexpr flat_forward_list_iterator_toperator= (flat_forward_list_iterator_t &&other) noexcept
 Move constructor. More...
 
template<typename I , typename = std::enable_if_t<is_const_iterator && is_non_const_iterator_v<I>>>
constexpr flat_forward_list_iterator_toperator= (I const &other) noexcept
 Assignment operator for const iterator from non-const iterator. More...
 
template<typename I , typename = std::enable_if_t<is_const_iterator && is_non_const_iterator_v<I>>>
constexpr flat_forward_list_iterator_toperator= (I &&other) noexcept
 Perfect forwarding assignment operator for const iterator from non-const iterator. More...
 
constexpr void swap (flat_forward_list_iterator_t &other) noexcept
 swaps this iterator and the other iterator More...
 
constexpr operator bool () const
 Explicit conversion iterator to bool. More...
 
template<typename I , typename = std::enable_if_t<is_comparable_iterator_v<I>>>
constexpr bool operator== (I const &other) const noexcept
 Equals operator used to compare to another iterator. More...
 
template<typename I , typename = std::enable_if_t<is_comparable_iterator_v<I>>>
constexpr bool operator != (I const &other) const noexcept
 Not equals operator used to compare to another iterator. More...
 
template<typename I , typename = std::enable_if_t<is_comparable_iterator_v<I>>>
constexpr bool operator< (I const &other) const noexcept
 Less than operator used to compare to another iterator. More...
 
template<typename I , typename = std::enable_if_t<is_comparable_iterator_v<I>>>
constexpr bool operator<= (I const &other) const noexcept
 Less than or equals operator used to compare to another iterator. More...
 
template<typename I , typename = std::enable_if_t<is_comparable_iterator_v<I>>>
constexpr bool operator > (I const &other) const noexcept
 Greater than operator used to compare to another iterator. More...
 
template<typename I , typename = std::enable_if_t<is_comparable_iterator_v<I>>>
constexpr bool operator >= (I const &other) const noexcept
 Greater or equals than operator used to compare to another iterator. More...
 
constexpr flat_forward_list_iterator_toperator++ () noexcept
 Prefix increment operator. More...
 
constexpr flat_forward_list_iterator_t operator++ (int) noexcept
 Postfix increment operator. More...
 
constexpr flat_forward_list_iterator_t operator+ (unsigned int advance_by) const noexcept
 Add operator. Advances iterator specified number of times. More...
 
constexpr T & operator * () const noexcept
 Dereference operator. More...
 
constexpr T * operator-> () const noexcept
 pointer operator. More...
 
constexpr buffer_char_pointer get_ptr () const noexcept
 

Static Public Attributes

static constexpr auto const is_const_iterator { std::is_const_v<T> }
 Is std::true_type{} if this iterator is an iterator for a T const, and std::false_type{} otherwise.
 
template<typename Iterator >
static constexpr auto const is_non_const_iterator_v
 Is std::true_type{} if Iterator is same as non-const equivalent of the current iterator non-const equivalent is constructed by removing CV qualifiers from T. non_const_iterator defines non-const equivalent for this iterator so we just need to make sure Iterator is the same type as non_const_iterator. More...
 
template<typename Iterator >
static constexpr auto const is_const_iterator_v
 Is std::true_type{} if Iterator is same as const equivalent of the current iterator non-const equivalent is constructed by adding CV qualifiers to T. const_iterator defines const equivalent for this iterator so we just need to make sure Iterator is the same type as const_iterator. More...
 
template<typename Iterator >
static constexpr auto const is_comparable_iterator_v
 Is std::true_type{} if Iterator is a const or non-const equivalent of this iterator and std::false_type otherwise. Comparable iterator can be used in relation operators. More...
 

Friends

template<typename TU , typename TTU , typename AU >
class flat_forward_list
 
template<typename TU , typename TTU >
class flat_forward_list_ref
 

Detailed Description

template<typename T, typename TT = flat_forward_list_traits<T>>
class iffl::flat_forward_list_iterator_t< T, TT >

THis class implements forward iterator for intrusive flat forward list.

Template Parameters
T- type of element header
TT- type trait for T that is used to get offset to the next element in the flat list. It must implement get_next_offset method.

Once iterator is incremented pass last element it becomes equal to default initialized iterator so you can use flat_forward_list_iterator_t{} as a sentinel that can be used as an end iterator.

Member Typedef Documentation

◆ buffer_char_pointer

template<typename T, typename TT = flat_forward_list_traits<T>>
iffl::flat_forward_list_iterator_t< T, TT >::buffer_char_pointer

Selects between constant and non-constant pointer to the buffer depending if T is const

◆ buffer_unsigned_char_pointer

template<typename T, typename TT = flat_forward_list_traits<T>>
iffl::flat_forward_list_iterator_t< T, TT >::buffer_unsigned_char_pointer

Selects between constant and non-constant pointer to the buffer depending if T is const

◆ buffer_void_pointer

template<typename T, typename TT = flat_forward_list_traits<T>>
iffl::flat_forward_list_iterator_t< T, TT >::buffer_void_pointer

Selects between constant and non-constant pointer to the buffer depending if T is const

◆ const_iterator

template<typename T, typename TT = flat_forward_list_traits<T>>
iffl::flat_forward_list_iterator_t< T, TT >::const_iterator

Const iterator is an iterator for a T const.

This type is used as helper for SFINAE expressions

◆ non_const_iterator

template<typename T, typename TT = flat_forward_list_traits<T>>
iffl::flat_forward_list_iterator_t< T, TT >::non_const_iterator

[Non-const] iterator is an iterator for a T with no const qualifiers

This type is used as a helper for SFINAE expressions

Constructor & Destructor Documentation

◆ flat_forward_list_iterator_t() [1/4]

template<typename T, typename TT = flat_forward_list_traits<T>>
constexpr iffl::flat_forward_list_iterator_t< T, TT >::flat_forward_list_iterator_t ( )
defaultnoexcept

Default initialize iterator.

For the types that support get_next_offset default initialized iterator is an end iterator. For the types that do not support get_next_offset it creates an invalid iterator.

◆ flat_forward_list_iterator_t() [2/4]

template<typename T, typename TT = flat_forward_list_traits<T>>
constexpr iffl::flat_forward_list_iterator_t< T, TT >::flat_forward_list_iterator_t ( flat_forward_list_iterator_t< T, TT > &&  other)
inlinenoexcept

Move constructs iterator.

Parameters
other- instance of iterator we are moving from

◆ flat_forward_list_iterator_t() [3/4]

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename I , typename = std::enable_if_t<is_const_iterator && is_non_const_iterator_v<I>>>
constexpr iffl::flat_forward_list_iterator_t< T, TT >::flat_forward_list_iterator_t ( I const &  other)
inlinenoexcept

Unittest that is_non_const_iterator_v returns expected result.

Unittest that is_non_const_iterator_v returns expected resultCopy constructor for const iterator from non-const iterator

Template Parameters
I- iterator type we are constructing from
Parameters
other- iterator we are constructing from

We are relying on SFINAE to disable this constructor if

  • this is not a const iterator
  • I not a non-const iterator

◆ flat_forward_list_iterator_t() [4/4]

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename I , typename = std::enable_if_t<is_const_iterator && is_non_const_iterator_v<I>>>
constexpr iffl::flat_forward_list_iterator_t< T, TT >::flat_forward_list_iterator_t ( I &&  other)
inlinenoexcept

Perfect forwarding constructor for const iterator from non-const iterator.

Template Parameters
I- iterator type we are constructing from
Parameters
other- iterator we are constructing from

We are relying on SFINAE to disable this constructor if

  • this is not a const iterator
  • I not a non-const iterator If other is an rvalue then it can play a role of move constructor. On move we will copy data other iterator is pointing to, but we are not going to null it out. Nulling is not required because this type is not a RAII wrapper, and there is no harm in leaving other pointing to the same element.

Member Function Documentation

◆ get_ptr()

template<typename T, typename TT = flat_forward_list_traits<T>>
constexpr buffer_char_pointer iffl::flat_forward_list_iterator_t< T, TT >::get_ptr ( ) const
inlinenoexcept
Returns
Returns a pointer to the buffer containing element.

◆ operator !=()

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename I , typename = std::enable_if_t<is_comparable_iterator_v<I>>>
constexpr bool iffl::flat_forward_list_iterator_t< T, TT >::operator != ( I const &  other) const
inlinenoexcept

Not equals operator used to compare to another iterator.

Template Parameters
I- type of the other iterator
Parameters
other- other iterator we are comparing to
Returns
false if both iterators point to the same element and true otherwise

We are using SFINAE to enable this operator only for const and non-const iterator types for the same element type

◆ operator *()

template<typename T, typename TT = flat_forward_list_traits<T>>
constexpr T& iffl::flat_forward_list_iterator_t< T, TT >::operator * ( ) const
inlinenoexcept

Dereference operator.

Returns
Returns a reference to the element pointed by iterator

◆ operator >()

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename I , typename = std::enable_if_t<is_comparable_iterator_v<I>>>
constexpr bool iffl::flat_forward_list_iterator_t< T, TT >::operator > ( I const &  other) const
inlinenoexcept

Greater than operator used to compare to another iterator.

Template Parameters
I- type of the other iterator
Parameters
other- other iterator we are comparing to
Returns
true if address of element pointed by this iterator is greater than address of element pointed by another iterator

We are using SFINAE to enable this operator only for const and non-const iterator types for the same element type

◆ operator >=()

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename I , typename = std::enable_if_t<is_comparable_iterator_v<I>>>
constexpr bool iffl::flat_forward_list_iterator_t< T, TT >::operator >= ( I const &  other) const
inlinenoexcept

Greater or equals than operator used to compare to another iterator.

Template Parameters
I- type of the other iterator
Parameters
other- other iterator we are comparing to
Returns
true if address of element pointed by this iterator is greater or equals than address of element pointed by another iterator

We are using SFINAE to enable this operator only for const and non-const iterator types for the same element type

◆ operator bool()

template<typename T, typename TT = flat_forward_list_traits<T>>
constexpr iffl::flat_forward_list_iterator_t< T, TT >::operator bool ( ) const
inlineexplicit

Explicit conversion iterator to bool.

Returns
false if it is null initialized and true otherwise

◆ operator+()

template<typename T, typename TT = flat_forward_list_traits<T>>
constexpr flat_forward_list_iterator_t iffl::flat_forward_list_iterator_t< T, TT >::operator+ ( unsigned int  advance_by) const
inlinenoexcept

Add operator. Advances iterator specified number of times.

Parameters
advance_by- number of times this iterator should be advanced
Returns
value of iterator after it was advanced

Advances iterator specified number of times caller is responsible for making sure iterator would not get advanced beyond container's end, if that happen then behavior is undefined.

◆ operator++() [1/2]

template<typename T, typename TT = flat_forward_list_traits<T>>
constexpr flat_forward_list_iterator_t& iffl::flat_forward_list_iterator_t< T, TT >::operator++ ( )
inlinenoexcept

Prefix increment operator.

Returns
reference to this iterator

Advances iterator to the next element

◆ operator++() [2/2]

template<typename T, typename TT = flat_forward_list_traits<T>>
constexpr flat_forward_list_iterator_t iffl::flat_forward_list_iterator_t< T, TT >::operator++ ( int  )
inlinenoexcept

Postfix increment operator.

Returns
value of iterator before it was advanced to the next element

Advances iterator to the next element

◆ operator->()

template<typename T, typename TT = flat_forward_list_traits<T>>
constexpr T* iffl::flat_forward_list_iterator_t< T, TT >::operator-> ( ) const
inlinenoexcept

pointer operator.

Returns
Returns a pointer to the element pointed by iterator

◆ operator<()

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename I , typename = std::enable_if_t<is_comparable_iterator_v<I>>>
constexpr bool iffl::flat_forward_list_iterator_t< T, TT >::operator< ( I const &  other) const
inlinenoexcept

Less than operator used to compare to another iterator.

Template Parameters
I- type of the other iterator
Parameters
other- other iterator we are comparing to
Returns
false if address of element pointed by this iterator is less than address of element pointed by another iterator

We are using SFINAE to enable this operator only for const and non-const iterator types for the same element type

◆ operator<=()

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename I , typename = std::enable_if_t<is_comparable_iterator_v<I>>>
constexpr bool iffl::flat_forward_list_iterator_t< T, TT >::operator<= ( I const &  other) const
inlinenoexcept

Less than or equals operator used to compare to another iterator.

Template Parameters
I- type of the other iterator
Parameters
other- other iterator we are comparing to
Returns
false if address of element pointed by this iterator is less or equal than address of element pointed by another iterator

We are using SFINAE to enable this operator only for const and non-const iterator types for the same element type

◆ operator=() [1/4]

template<typename T, typename TT = flat_forward_list_traits<T>>
constexpr flat_forward_list_iterator_t& iffl::flat_forward_list_iterator_t< T, TT >::operator= ( flat_forward_list_iterator_t< T, TT > const &  )
defaultnoexcept

Default generated copy constructor.

Returns
reference to this object

◆ operator=() [2/4]

template<typename T, typename TT = flat_forward_list_traits<T>>
constexpr flat_forward_list_iterator_t& iffl::flat_forward_list_iterator_t< T, TT >::operator= ( flat_forward_list_iterator_t< T, TT > &&  other)
inlinenoexcept

Move constructor.

Parameters
other- iterator we are moving from
Returns
reference to this object

◆ operator=() [3/4]

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename I , typename = std::enable_if_t<is_const_iterator && is_non_const_iterator_v<I>>>
constexpr flat_forward_list_iterator_t& iffl::flat_forward_list_iterator_t< T, TT >::operator= ( I const &  other)
inlinenoexcept

Assignment operator for const iterator from non-const iterator.

Template Parameters
I- iterator type we are assigning from
Parameters
other- iterator we are constructing from
Returns
reference to this object

We are relying on SFINAE to disable this assignment operator if

  • this is not a const iterator
  • I not a non-const iterator

◆ operator=() [4/4]

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename I , typename = std::enable_if_t<is_const_iterator && is_non_const_iterator_v<I>>>
constexpr flat_forward_list_iterator_t& iffl::flat_forward_list_iterator_t< T, TT >::operator= ( I &&  other)
inlinenoexcept

Perfect forwarding assignment operator for const iterator from non-const iterator.

Template Parameters
I- iterator type we are assigning from
Parameters
other- iterator we are assigning from
Returns
reference to this object

We are relying on SFINAE to disable this assignment operator if

  • this is not a const iterator
  • I not a non-const iterator If other is an rvalue then it can play a role of move assignment operator. On move we will copy data other iterator is pointing to, but we are not going to null it out. Nulling is not required because this type is not a RAII wrapper, and there is no harm in leaving other pointing to the same element.

◆ operator==()

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename I , typename = std::enable_if_t<is_comparable_iterator_v<I>>>
constexpr bool iffl::flat_forward_list_iterator_t< T, TT >::operator== ( I const &  other) const
inlinenoexcept

Equals operator used to compare to another iterator.

Template Parameters
I- type of the other iterator
Parameters
other- other iterator we are comparing to
Returns
true if both iterators point to the same element and false otherwise

We are using SFINAE to enable this operator only for const and non-const iterator types for the same element type

◆ swap()

template<typename T, typename TT = flat_forward_list_traits<T>>
constexpr void iffl::flat_forward_list_iterator_t< T, TT >::swap ( flat_forward_list_iterator_t< T, TT > &  other)
inlinenoexcept

swaps this iterator and the other iterator

Parameters
other- reference to the other iterator

Friends And Related Function Documentation

◆ flat_forward_list

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename TU , typename TTU , typename AU >
friend class flat_forward_list
friend

Forward declaration of intrusive flat forward list container.

◆ flat_forward_list_ref

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename TU , typename TTU >
friend class flat_forward_list_ref
friend

Forward declaration of intrusive flat forward list reference.

Member Data Documentation

◆ is_comparable_iterator_v

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename Iterator >
constexpr auto const iffl::flat_forward_list_iterator_t< T, TT >::is_comparable_iterator_v
static
Initial value:
{ is_non_const_iterator_v<Iterator> ||
is_const_iterator_v<Iterator> }

Is std::true_type{} if Iterator is a const or non-const equivalent of this iterator and std::false_type otherwise. Comparable iterator can be used in relation operators.

Template Parameters
Iterator- any type

◆ is_const_iterator_v

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename Iterator >
constexpr auto const iffl::flat_forward_list_iterator_t< T, TT >::is_const_iterator_v
static
Initial value:
{ std::is_same_v < std::remove_cv_t<Iterator>,

Is std::true_type{} if Iterator is same as const equivalent of the current iterator non-const equivalent is constructed by adding CV qualifiers to T. const_iterator defines const equivalent for this iterator so we just need to make sure Iterator is the same type as const_iterator.

Template Parameters
Iterator- any type

◆ is_non_const_iterator_v

template<typename T, typename TT = flat_forward_list_traits<T>>
template<typename Iterator >
constexpr auto const iffl::flat_forward_list_iterator_t< T, TT >::is_non_const_iterator_v
static
Initial value:
{ std::is_same_v < std::remove_cv_t<Iterator>,

Is std::true_type{} if Iterator is same as non-const equivalent of the current iterator non-const equivalent is constructed by removing CV qualifiers from T. non_const_iterator defines non-const equivalent for this iterator so we just need to make sure Iterator is the same type as non_const_iterator.

Template Parameters
Iterator- any type

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