ipaddress 1.1.0
Loading...
Searching...
No Matches
ip_network_iterator< T > Class Template Reference

An iterator for traversing IP addresses within a network range. More...

#include <ip-network-iterator.hpp>

Inheritance diagram for ip_network_iterator< T >:

Public Types

using iterator_category = std::random_access_iterator_tag
 The category of the iterator.
 
using value_type = T
 The type of value iterated over.
 
using difference_type = int64_t
 Type to represent the difference between two iterators.
 
using pointer = const value_type*
 Pointer to the value type.
 
using reference = const value_type&
 Reference to the value type.
 
using ip_address_type = typename value_type::ip_address_type
 The underlying IP address type.
 
using uint_type = typename value_type::uint_type
 Unsigned integer type used for addressing.
 

Public Member Functions

constexpr inline ip_network_iterator () noexcept=default
 Default constructor.
 
constexpr inline ip_network_iterator (const ip_address_type &ref, const uint_type &step, size_t prefixlen, int carry=0) noexcept
 Constructs an iterator with a reference IP address, step size, prefix length, and carry.
 
constexpr inline uint_type uint_diff (const ip_network_iterator &other) const noexcept
 Calculates the difference in the number of elements between this and another ip_network_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 uint_type &n) const noexcept
 Accesses an element by index.
 
constexpr inline ip_network_iteratoroperator++ () noexcept
 Pre-increment operator.
 
constexpr inline ip_network_iterator operator++ (int) noexcept
 Post-increment operator.
 
constexpr inline ip_network_iteratoroperator-- () noexcept
 Pre-decrement operator.
 
constexpr inline ip_network_iterator operator-- (int) noexcept
 Post-decrement operator.
 
constexpr inline ip_network_iteratoroperator+= (difference_type n) noexcept
 Addition assignment operator.
 
constexpr inline ip_network_iteratoroperator+= (const uint_type &n) noexcept
 Addition assignment operator.
 
constexpr inline ip_network_iteratoroperator-= (difference_type n) noexcept
 Subtraction assignment operator.
 
constexpr inline ip_network_iteratoroperator-= (const uint_type &n) noexcept
 Subtraction assignment operator.
 
constexpr inline ip_network_iterator operator+ (difference_type n) const noexcept
 Addition operator.
 
constexpr inline ip_network_iterator operator+ (const uint_type &n) const noexcept
 Addition operator.
 
constexpr inline ip_network_iterator operator- (difference_type n) const noexcept
 Subtraction operator.
 
constexpr inline ip_network_iterator operator- (const uint_type &n) const noexcept
 Subtraction operator.
 
constexpr inline difference_type operator- (const ip_network_iterator &other) const noexcept
 Subtraction operator.
 
constexpr inline bool operator== (const ip_network_iterator &other) const noexcept
 Equality operator.
 
constexpr inline bool operator!= (const ip_network_iterator &other) const noexcept
 Inequality operator.
 
constexpr inline bool operator< (const ip_network_iterator &other) const noexcept
 Less-than operator.
 
constexpr inline bool operator<= (const ip_network_iterator &other) const noexcept
 Less-than-or-equal-to operator.
 
constexpr inline bool operator> (const ip_network_iterator &other) const noexcept
 Greater-than operator.
 
constexpr inline bool operator>= (const ip_network_iterator &other) const noexcept
 Greater-than-or-equal-to operator.
 

Detailed Description

template<typename T>
class ipaddress::ip_network_iterator< T >

An iterator for traversing IP addresses within a network range.

This class template provides a random-access iterator that allows traversal over a range of IP addresses within a network. It supports operations typical of random-access iterators, such as increment, decrement, and direct access to elements at a specific offset.

Template Parameters
TThe type of IPv4 or IPv6 network to iterate over.

Constructor & Destructor Documentation

◆ ip_network_iterator()

template<typename T >
constexpr inline ip_network_iterator ( const ip_address_type & ref,
const uint_type & step,
size_t prefixlen,
int carry = 0 )
inlinenoexcept

Constructs an iterator with a reference IP address, step size, prefix length, and carry.

Parameters
[in]refThe reference IP address for the iterator.
[in]stepThe step size for each iteration.
[in]prefixlenThe prefix length defining the network.
[in]carryAn optional carry value for overflow handling.

Member Function Documentation

◆ uint_diff()

template<typename T >
constexpr inline uint_type uint_diff ( const ip_network_iterator< T > & other) const
inlinenoexcept

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

Parameters
[in]otherThe ip_network_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 >
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 >
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 >
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 >
constexpr inline value_type operator[] ( const uint_type & 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 >
constexpr inline ip_network_iterator & operator++ ( )
inlinenoexcept

Pre-increment operator.

Increments the iterator to the next element.

Returns
A reference to the incremented iterator.

◆ operator++() [2/2]

template<typename T >
constexpr inline ip_network_iterator operator++ ( int )
inlinenoexcept

Post-increment operator.

Increments the iterator to the next element and returns the iterator before the increment.

Returns
The iterator before the increment.

◆ operator--() [1/2]

template<typename T >
constexpr inline ip_network_iterator & operator-- ( )
inlinenoexcept

Pre-decrement operator.

Decrements the iterator to the previous element.

Returns
A reference to the decremented iterator.

◆ operator--() [2/2]

template<typename T >
constexpr inline ip_network_iterator operator-- ( int )
inlinenoexcept

Post-decrement operator.

Decrements the iterator to the previous element and returns the iterator before the decrement.

Returns
The iterator before the decrement.

◆ operator+=() [1/2]

template<typename T >
constexpr inline ip_network_iterator & operator+= ( difference_type n)
inlinenoexcept

Addition assignment operator.

Adds a difference_type value to the iterator.

Parameters
[in]nThe number to add.
Returns
A reference to the updated iterator.

◆ operator+=() [2/2]

template<typename T >
constexpr inline ip_network_iterator & operator+= ( const uint_type & n)
inlinenoexcept

Addition assignment operator.

Adds a uint_type value to the iterator.

Parameters
[in]nThe number to add.
Returns
A reference to the updated iterator.

◆ operator-=() [1/2]

template<typename T >
constexpr inline ip_network_iterator & operator-= ( difference_type n)
inlinenoexcept

Subtraction assignment operator.

Subtracts a difference_type value from the iterator.

Parameters
[in]nThe number to subtract.
Returns
A reference to the updated iterator.

◆ operator-=() [2/2]

template<typename T >
constexpr inline ip_network_iterator & operator-= ( const uint_type & n)
inlinenoexcept

Subtraction assignment operator.

Subtracts a uint_type value from the iterator.

Parameters
[in]nThe number to subtract.
Returns
A reference to the updated iterator.

◆ operator+() [1/2]

template<typename T >
constexpr inline ip_network_iterator operator+ ( difference_type n) const
inlinenoexcept

Addition operator.

Creates a new iterator that is the sum of the iterator and a difference_type value.

Parameters
[in]nThe number to add.
Returns
A new iterator that is the sum of the iterator and the number.

◆ operator+() [2/2]

template<typename T >
constexpr inline ip_network_iterator operator+ ( const uint_type & n) const
inlinenoexcept

Addition operator.

Creates a new iterator that is the sum of the iterator and a uint_type value.

Parameters
[in]nThe number to add.
Returns
A new iterator that is the sum of the iterator and the number.

◆ operator-() [1/3]

template<typename T >
constexpr inline ip_network_iterator operator- ( difference_type n) const
inlinenoexcept

Subtraction operator.

Creates a new iterator that is the difference of the iterator and a difference_type value.

Parameters
[in]nThe number to subtract.
Returns
A new iterator that is the difference of the iterator and the number.

◆ operator-() [2/3]

template<typename T >
constexpr inline ip_network_iterator operator- ( const uint_type & n) const
inlinenoexcept

Subtraction operator.

Creates a new iterator that is the difference of the iterator and a uint_type value.

Parameters
[in]nThe number to subtract.
Returns
A new iterator that is the difference of the iterator and the number.

◆ operator-() [3/3]

template<typename T >
constexpr inline difference_type operator- ( const ip_network_iterator< T > & other) const
inlinenoexcept

Subtraction operator.

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

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

◆ operator==()

template<typename T >
constexpr inline bool operator== ( const ip_network_iterator< T > & other) const
inlinenoexcept

Equality operator.

Compares two ip_network_iterators for equality.

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

◆ operator!=()

template<typename T >
constexpr inline bool operator!= ( const ip_network_iterator< T > & other) const
inlinenoexcept

Inequality operator.

Compares two ip_network_iterators for inequality.

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

◆ operator<()

template<typename T >
constexpr inline bool operator< ( const ip_network_iterator< T > & other) const
inlinenoexcept

Less-than operator.

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

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

◆ operator<=()

template<typename T >
constexpr inline bool operator<= ( const ip_network_iterator< T > & other) const
inlinenoexcept

Less-than-or-equal-to operator.

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

Parameters
[in]otherThe ip_network_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 >
constexpr inline bool operator> ( const ip_network_iterator< T > & other) const
inlinenoexcept

Greater-than operator.

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

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

◆ operator>=()

template<typename T >
constexpr inline bool operator>= ( const ip_network_iterator< T > & other) const
inlinenoexcept

Greater-than-or-equal-to operator.

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

Parameters
[in]otherThe ip_network_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: