ipaddress 1.1.0
Loading...
Searching...
No Matches
ip_any_iterator< T, Ipv4Iter, Ipv6Iter > Class Template Reference

An iterator for unified traversal over IPv4 and IPv6 address spaces. More...

#include <ip-any-iterator.hpp>

Public Types

using iterator_category = std::random_access_iterator_tag
 Iterator category.
 
using value_type = T
 Value type iterated over.
 
using difference_type = int64_t
 Difference type between iterators.
 
using pointer = const value_type*
 Pointer to value type.
 
using reference = const value_type&
 Reference to value type.
 
using uint_type = uint128_t
 Unsigned integer type for addressing.
 

Public Member Functions

constexpr inline ip_any_iterator () noexcept=default
 Default constructor.
 
constexpr inline ip_any_iterator (Ipv4Iter iter) noexcept
 Constructs an ip_any_iterator from an Ipv4Iter iterator.
 
constexpr inline ip_any_iterator (Ipv6Iter iter) noexcept
 Constructs an ip_any_iterator from an Ipv6Iter iterator.
 
constexpr inline uint128_t uint_diff (const ip_any_iterator &other) const noexcept
 Calculates the difference in the number of elements between this and another ip_any_iterator.
 
constexpr inline reference operator* () const noexcept
 Returns a reference to the current element.
 
constexpr inline pointer operator-> () const noexcept
 Returns a pointer to the current element.
 
constexpr inline value_type operator[] (difference_type n) const noexcept
 Accesses an element by index.
 
constexpr inline value_type operator[] (const uint128_t &n) const noexcept
 Accesses an element by index.
 
constexpr inline ip_any_iteratoroperator++ () noexcept
 Pre-increment operator.
 
constexpr inline ip_any_iterator operator++ (int) noexcept
 Post-increment operator.
 
constexpr inline ip_any_iteratoroperator-- () noexcept
 Pre-decrement operator.
 
constexpr inline ip_any_iterator operator-- (int) noexcept
 Post-decrement operator.
 
constexpr inline ip_any_iteratoroperator+= (difference_type n) noexcept
 Addition assignment operator.
 
constexpr inline ip_any_iteratoroperator+= (const uint128_t &n) noexcept
 Addition assignment operator.
 
constexpr inline ip_any_iteratoroperator-= (difference_type n) noexcept
 Subtraction assignment operator.
 
constexpr inline ip_any_iteratoroperator-= (const uint128_t &n) noexcept
 Subtraction assignment operator.
 
constexpr inline ip_any_iterator operator+ (difference_type n) const noexcept
 Addition operator.
 
constexpr inline ip_any_iterator operator+ (const uint128_t &n) const noexcept
 Addition operator.
 
constexpr inline ip_any_iterator operator- (difference_type n) const noexcept
 Subtraction operator.
 
constexpr inline ip_any_iterator operator- (const uint128_t &n) const noexcept
 Subtraction operator.
 
constexpr inline difference_type operator- (const ip_any_iterator &other) const noexcept
 Subtraction operator.
 
constexpr inline bool operator== (const ip_any_iterator &other) const noexcept
 Equality operator.
 
constexpr inline bool operator!= (const ip_any_iterator &other) const noexcept
 Inequality operator.
 
constexpr inline bool operator< (const ip_any_iterator &other) const noexcept
 Less-than operator.
 
constexpr inline bool operator<= (const ip_any_iterator &other) const noexcept
 Less-than-or-equal-to operator.
 
constexpr inline bool operator> (const ip_any_iterator &other) const noexcept
 Greater-than operator.
 
constexpr inline bool operator>= (const ip_any_iterator &other) const noexcept
 Greater-than-or-equal-to operator.
 

Detailed Description

template<typename T, typename Ipv4Iter, typename Ipv6Iter>
class ipaddress::ip_any_iterator< T, Ipv4Iter, Ipv6Iter >

An iterator for unified traversal over IPv4 and IPv6 address spaces.

The ip_any_iterator class template provides a mechanism to iterate over both IPv4 and IPv6 addresses using a single, unified interface. It abstracts the complexities associated with handling the two different IP versions, allowing for code that is agnostic to the IP version it operates on. This is particularly useful for applications that must work with both IPv4 and IPv6 networks, such as dual-stack network configurations, without the need for separate code paths. The iterator supports random access, which enables efficient traversal and manipulation of IP address ranges in various network operations.

Template Parameters
TThe type of IP address or network (IPv4 or IPv6) the iterator will handle.
Ipv4IterThe type of IPv4 iterator
Ipv6IterThe type of IPv6 iterator

Constructor & Destructor Documentation

◆ ip_any_iterator() [1/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator ( Ipv4Iter iter)
inlinenoexcept

Constructs an ip_any_iterator from an Ipv4Iter iterator.

Parameters
[in]iterThe underlying iterator to reverse.

◆ ip_any_iterator() [2/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator ( Ipv6Iter iter)
inlinenoexcept

Constructs an ip_any_iterator from an Ipv6Iter iterator.

Parameters
[in]iterThe underlying iterator to reverse.

Member Function Documentation

◆ uint_diff()

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline uint128_t uint_diff ( const ip_any_iterator< T, Ipv4Iter, Ipv6Iter > & other) const
inlinenoexcept

Calculates the difference in the number of elements between this and another ip_any_iterator.

Parameters
[in]otherThe ip_any_iterator to compare with.
Returns
The number of elements between this and the other iterator.
Remarks
This is a special function for calculate the difference between iterators, which can correctly represent all addresses using the integer number uint128_t

◆ operator*()

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline reference operator* ( ) const
inlinenoexcept

Returns a reference to the current element.

Returns
A reference to the element pointed to by the iterator.

◆ operator->()

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline pointer operator-> ( ) const
inlinenoexcept

Returns a pointer to the current element.

Returns
A pointer to the element pointed to by the iterator.

◆ operator[]() [1/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline value_type operator[] ( difference_type n) const
inlinenoexcept

Accesses an element by index.

Parameters
[in]nThe index of the element.
Returns
The element at the specified index.

◆ operator[]() [2/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline value_type operator[] ( const uint128_t & n) const
inlinenoexcept

Accesses an element by index.

Parameters
[in]nThe index of the element.
Returns
The element at the specified index.

◆ operator++() [1/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator & operator++ ( )
inlinenoexcept

Pre-increment operator.

Returns
A reference to the incremented iterator.

◆ operator++() [2/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator operator++ ( int )
inlinenoexcept

Post-increment operator.

Returns
The iterator before incrementing.

◆ operator--() [1/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator & operator-- ( )
inlinenoexcept

Pre-decrement operator.

Returns
A reference to the decremented iterator.

◆ operator--() [2/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator operator-- ( int )
inlinenoexcept

Post-decrement operator.

Returns
The iterator before decrementing.

◆ operator+=() [1/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator & operator+= ( difference_type n)
inlinenoexcept

Addition assignment operator.

Moves the iterator forward by n positions.

Parameters
[in]nThe number of positions to move the iterator forward.
Returns
A reference to the updated iterator.

◆ operator+=() [2/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator & operator+= ( const uint128_t & n)
inlinenoexcept

Addition assignment operator.

Moves the iterator forward by n positions.

Parameters
[in]nThe number of positions to move the iterator forward.
Returns
A reference to the updated iterator.

◆ operator-=() [1/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator & operator-= ( difference_type n)
inlinenoexcept

Subtraction assignment operator.

Moves the iterator backward by n positions.

Parameters
[in]nThe number of positions to move the iterator backward.
Returns
A reference to the updated iterator.

◆ operator-=() [2/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator & operator-= ( const uint128_t & n)
inlinenoexcept

Subtraction assignment operator.

Moves the iterator backward by n positions.

Parameters
[in]nThe number of positions to move the iterator backward.
Returns
A reference to the updated iterator.

◆ operator+() [1/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator operator+ ( difference_type n) const
inlinenoexcept

Addition operator.

Creates a new iterator that is n positions ahead of the current one.

Parameters
[in]nThe number of positions to move ahead.
Returns
A new iterator that is n positions ahead.

◆ operator+() [2/2]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator operator+ ( const uint128_t & n) const
inlinenoexcept

Addition operator.

Creates a new iterator that is n positions ahead of the current one.

Parameters
[in]nThe number of positions to move ahead.
Returns
A new iterator that is n positions ahead.

◆ operator-() [1/3]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator operator- ( difference_type n) const
inlinenoexcept

Subtraction operator.

Creates a new iterator that is n positions behind the current one.

Parameters
[in]nThe number of positions to move behind.
Returns
A new iterator that is n positions behind.

◆ operator-() [2/3]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline ip_any_iterator operator- ( const uint128_t & n) const
inlinenoexcept

Subtraction operator.

Creates a new iterator that is n positions behind the current one.

Parameters
[in]nThe number of positions to move behind.
Returns
A new iterator that is n positions behind.

◆ operator-() [3/3]

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline difference_type operator- ( const ip_any_iterator< T, Ipv4Iter, Ipv6Iter > & other) const
inlinenoexcept

Subtraction operator.

Calculates the difference in the number of elements between this and another ip_any_iterator.

Parameters
[in]otherThe ip_any_iterator to compare with.
Returns
The number of elements between this and the other iterator.

◆ operator==()

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline bool operator== ( const ip_any_iterator< T, Ipv4Iter, Ipv6Iter > & other) const
inlinenoexcept

Equality operator.

Compares two ip_any_iterator for equality.

Parameters
[in]otherThe ip_any_iterator to compare with.
Returns
true if the iterators are equal, false otherwise.

◆ operator!=()

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline bool operator!= ( const ip_any_iterator< T, Ipv4Iter, Ipv6Iter > & other) const
inlinenoexcept

Inequality operator.

Compares two ip_any_iterator for inequality.

Parameters
[in]otherThe ip_any_iterator to compare with.
Returns
true if the iterators are not equal, false otherwise.

◆ operator<()

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline bool operator< ( const ip_any_iterator< T, Ipv4Iter, Ipv6Iter > & other) const
inlinenoexcept

Less-than operator.

Compares two ip_any_iterator to determine if the left one is less than the right one.

Parameters
[in]otherThe ip_any_iterator to compare with.
Returns
true if the left iterator is less than the right iterator, false otherwise.

◆ operator<=()

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline bool operator<= ( const ip_any_iterator< T, Ipv4Iter, Ipv6Iter > & other) const
inlinenoexcept

Less-than-or-equal-to operator.

Compares two ip_any_iterator to determine if the left one is less than or equal to the right one.

Parameters
[in]otherThe ip_any_iterator to compare with.
Returns
true if the left iterator is less than or equal to the right iterator, false otherwise.

◆ operator>()

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline bool operator> ( const ip_any_iterator< T, Ipv4Iter, Ipv6Iter > & other) const
inlinenoexcept

Greater-than operator.

Compares two ip_any_iterator to determine if the left one is greater than the right one.

Parameters
[in]otherThe ip_any_iterator to compare with.
Returns
true if the left iterator is greater than the right iterator, false otherwise.

◆ operator>=()

template<typename T , typename Ipv4Iter , typename Ipv6Iter >
constexpr inline bool operator>= ( const ip_any_iterator< T, Ipv4Iter, Ipv6Iter > & other) const
inlinenoexcept

Greater-than-or-equal-to operator.

Compares two ip_any_iterator to determine if the left one is greater than or equal to the right one.

Parameters
[in]otherThe ip_any_iterator to compare with.
Returns
true if the left iterator is greater than or equal to the right iterator, false otherwise.

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