ipaddress 1.1.0
Loading...
Searching...
No Matches
byte_array< N > Struct Template Reference

A template class for creating and managing a fixed-size array of bytes. More...

#include <byte-array.hpp>

Public Types

using value_type = uint8_t
 The type of elements contained in the byte_array.
 
using size_type = size_t
 The type representing sizes and counts.
 
using difference_type = ptrdiff_t
 The type representing the difference between two pointers.
 
using pointer = value_type*
 A pointer to an element in the byte_array.
 
using const_pointer = const value_type*
 A pointer to a constant element in the byte_array.
 
using reference = value_type&
 A reference to an element in the byte_array.
 
using const_reference = const value_type&
 A reference to a constant element in the byte_array.
 
using iterator = pointer
 A random access iterator to byte_array that allows modification of its elements.
 
using const_iterator = const_pointer
 A random access iterator to constant byte_array that does not allow modification of its elements.
 
using reverse_iterator = std::reverse_iterator<iterator>
 A reverse random access iterator to byte_array that allows modification of its elements.
 
using const_reverse_iterator = std::reverse_iterator<const_iterator>
 A reverse random access iterator to constant byte_array that does not allow modification of its elements.
 

Public Member Functions

constexpr inline const_iterator begin () const noexcept
 Returns a const_iterator to the beginning of the byte_array.
 
constexpr inline const_iterator end () const noexcept
 Returns a const_iterator to the end of the byte_array.
 
constexpr inline const_reverse_iterator rbegin () const noexcept
 Returns a const_reverse_iterator to the beginning of the reversed byte_array.
 
constexpr inline const_reverse_iterator rend () const noexcept
 Returns a const_reverse_iterator to the end of the reversed byte_array.
 
constexpr inline const_iterator cbegin () const noexcept
 Returns a const_iterator to the beginning of the byte_array (const version).
 
constexpr inline const_iterator cend () const noexcept
 Returns a const_iterator to the end of the byte_array (const version).
 
constexpr inline const_reverse_iterator crbegin () const noexcept
 Returns a const_reverse_iterator to the beginning of the reversed byte_array (const version).
 
constexpr inline const_reverse_iterator crend () const noexcept
 Returns a const_reverse_iterator to the end of the reversed byte_array (const version).
 
constexpr inline bool empty () const noexcept
 Checks if the byte_array is empty.
 
constexpr inline size_t size () const noexcept
 Returns the size of the byte_array.
 
constexpr inline size_t max_size () const noexcept
 Returns the maximum size of the byte_array.
 
constexpr inline reference operator[] (size_t n) noexcept
 Accesses the element at the specified index with bounds checking.
 
constexpr inline const_reference operator[] (size_t n) const noexcept
 Accesses the element at the specified index with bounds checking (const version).
 
constexpr inline reference at (size_t n) noexcept
 Accesses the element at the specified index with bounds checking.
 
constexpr inline const_reference at (size_t n) const noexcept
 Accesses the element at the specified index with bounds checking (const version).
 
constexpr inline reference front () noexcept
 Accesses the first element in the byte_array.
 
constexpr inline const_reference front () const noexcept
 Accesses the first element in the byte_array (const version).
 
constexpr inline reference back () noexcept
 Accesses the last element in the byte_array.
 
constexpr inline const_reference back () const noexcept
 Accesses the last element in the byte_array (const version).
 
constexpr inline pointer data () noexcept
 Returns a pointer to the underlying array.
 
constexpr inline const_pointer data () const noexcept
 Returns a const pointer to the underlying array (const version).
 
constexpr inline void swap (byte_array &other) noexcept
 Swaps the contents of this byte_array with another byte_array.
 

Detailed Description

template<size_t N>
struct ipaddress::byte_array< N >

A template class for creating and managing a fixed-size array of bytes.

The byte_array class encapsulates a static-size array of bytes, providing type definitions for element access and iteration in both normal and reverse order. It is designed to be used where a constant size byte buffer is needed, such as in handling network addresses like IP addresses.

Template Parameters
NThe number of bytes in the array.
Remarks
The purpose of the byte_array class is to provide functionality similar to std::array in . environments where std::array cannot be used to its full extent during compile-time operations.

Member Function Documentation

◆ begin()

template<size_t N>
constexpr inline const_iterator begin ( ) const
inlinenoexcept

Returns a const_iterator to the beginning of the byte_array.

Returns
A const_iterator pointing to the first element in the array.

◆ end()

template<size_t N>
constexpr inline const_iterator end ( ) const
inlinenoexcept

Returns a const_iterator to the end of the byte_array.

Returns
A const_iterator pointing to the past-the-end element in the array.

◆ rbegin()

template<size_t N>
constexpr inline const_reverse_iterator rbegin ( ) const
inlinenoexcept

Returns a const_reverse_iterator to the beginning of the reversed byte_array.

Returns
A const_reverse_iterator pointing to the first element of the reversed array.

◆ rend()

template<size_t N>
constexpr inline const_reverse_iterator rend ( ) const
inlinenoexcept

Returns a const_reverse_iterator to the end of the reversed byte_array.

Returns
A const_reverse_iterator pointing to the past-the-end element in the reversed array.

◆ cbegin()

template<size_t N>
constexpr inline const_iterator cbegin ( ) const
inlinenoexcept

Returns a const_iterator to the beginning of the byte_array (const version).

Returns
A const_iterator pointing to the first element in the array.

◆ cend()

template<size_t N>
constexpr inline const_iterator cend ( ) const
inlinenoexcept

Returns a const_iterator to the end of the byte_array (const version).

Returns
A const_iterator pointing to the past-the-end element in the array.

◆ crbegin()

template<size_t N>
constexpr inline const_reverse_iterator crbegin ( ) const
inlinenoexcept

Returns a const_reverse_iterator to the beginning of the reversed byte_array (const version).

Returns
A const_reverse_iterator pointing to the first element of the reversed array.

◆ crend()

template<size_t N>
constexpr inline const_reverse_iterator crend ( ) const
inlinenoexcept

Returns a const_reverse_iterator to the end of the reversed byte_array (const version).

Returns
A const_reverse_iterator pointing to the past-the-end element in the reversed array.

◆ empty()

template<size_t N>
constexpr inline bool empty ( ) const
inlinenoexcept

Checks if the byte_array is empty.

Returns
true if the byte_array is empty, false otherwise.

◆ size()

template<size_t N>
constexpr inline size_t size ( ) const
inlinenoexcept

Returns the size of the byte_array.

Returns
The number of elements in the byte_array.

◆ max_size()

template<size_t N>
constexpr inline size_t max_size ( ) const
inlinenoexcept

Returns the maximum size of the byte_array.

Returns
The number of elements in the byte_array (same as size()).

◆ operator[]() [1/2]

template<size_t N>
constexpr inline reference operator[] ( size_t n)
inlinenoexcept

Accesses the element at the specified index with bounds checking.

Parameters
[in]nThe index of the element to access.
Returns
A reference to the element at the specified index.
Exceptions
std::out_of_rangeWhen going beyond the bounds of the array.

◆ operator[]() [2/2]

template<size_t N>
constexpr inline const_reference operator[] ( size_t n) const
inlinenoexcept

Accesses the element at the specified index with bounds checking (const version).

Parameters
[in]nThe index of the element to access.
Returns
A const reference to the element at the specified index.
Exceptions
std::out_of_rangeWhen going beyond the bounds of the array.

◆ at() [1/2]

template<size_t N>
constexpr inline reference at ( size_t n)
inlinenoexcept

Accesses the element at the specified index with bounds checking.

Parameters
[in]nThe index of the element to access.
Returns
A reference to the element at the specified index.
Exceptions
std::out_of_rangeWhen going beyond the bounds of the array.

◆ at() [2/2]

template<size_t N>
constexpr inline const_reference at ( size_t n) const
inlinenoexcept

Accesses the element at the specified index with bounds checking (const version).

Parameters
[in]nThe index of the element to access.
Returns
A const reference to the element at the specified index.
Exceptions
std::out_of_rangeWhen going beyond the bounds of the array.

◆ front() [1/2]

template<size_t N>
constexpr inline reference front ( )
inlinenoexcept

Accesses the first element in the byte_array.

Returns
A reference to the first element in the byte_array.

◆ front() [2/2]

template<size_t N>
constexpr inline const_reference front ( ) const
inlinenoexcept

Accesses the first element in the byte_array (const version).

Returns
A const reference to the first element in the byte_array.

◆ back() [1/2]

template<size_t N>
constexpr inline reference back ( )
inlinenoexcept

Accesses the last element in the byte_array.

Returns
A reference to the last element in the byte_array.

◆ back() [2/2]

template<size_t N>
constexpr inline const_reference back ( ) const
inlinenoexcept

Accesses the last element in the byte_array (const version).

Returns
A const reference to the last element in the byte_array.

◆ data() [1/2]

template<size_t N>
constexpr inline pointer data ( )
inlinenoexcept

Returns a pointer to the underlying array.

Returns
A pointer to the underlying array of type value_type.

◆ data() [2/2]

template<size_t N>
constexpr inline const_pointer data ( ) const
inlinenoexcept

Returns a const pointer to the underlying array (const version).

Returns
A const pointer to the underlying array of type value_type.

◆ swap()

template<size_t N>
constexpr inline void swap ( byte_array< N > & other)
inlinenoexcept

Swaps the contents of this byte_array with another byte_array.

Parameters
[in,out]otherThe other byte_array to swap contents with.

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