ipaddress 1.2.0
Loading...
Searching...
No Matches
fixed_vector< T, N > Class Template Reference

A fixed-size vector class template. More...

#include <fixed-vector.hpp>

Public Types

using value_type = T
 type of the elements in the vector.
 
using size_type = size_t
 type used for size representation.
 
using difference_type = ptrdiff_t
 type used for representing differences between iterators.
 
using pointer = value_type*
 type used for pointer to elements.
 
using const_pointer = const value_type*
 type used for pointer to constant elements.
 
using reference = value_type&
 type used for reference to elements.
 
using const_reference = const value_type&
 type used for reference to constant elements.
 
using iterator = fixed_vector_iterator<value_type>
 type used for iterator to elements.
 
using const_iterator = fixed_vector_iterator<const value_type>
 type used for iterator to constant elements.
 
using reverse_iterator = std::reverse_iterator<iterator>
 type used for reverse iterator.
 
using const_reverse_iterator = std::reverse_iterator<const_iterator>
 type used for reverse iterator to constant elements.
 

Public Member Functions

constexpr inline fixed_vector () noexcept=default
 Default constructor.
 
constexpr inline fixed_vector (size_type n) noexcept
 Constructs a fixed_vector with the specified number of default-initialized elements.
 
constexpr inline fixed_vector (size_type n, const_reference value) noexcept
 Constructs a fixed_vector with the specified number of elements initialized to the given value.
 
template<class It >
constexpr inline fixed_vector (It first, It last) noexcept
 Constructs a fixed_vector from a range of elements.
 
constexpr inline fixed_vector (std::initializer_list< value_type > init_list) noexcept
 Constructs a fixed_vector from an initializer list.
 
constexpr inline void assign (size_type n, const_reference value) noexcept
 Replaces the contents with the specified number of copies of the given value.
 
template<class It >
constexpr inline void assign (It first, It last) noexcept
 Replaces the contents with the elements in the specified range.
 
constexpr inline void assign (std::initializer_list< value_type > init_list) noexcept
 Replaces the contents with the elements in the specified initializer list.
 
constexpr inline reference at (size_type n) noexcept
 Accesses an element by index.
 
constexpr inline const_reference at (size_type n) const noexcept
 Accesses an element by index.
 
constexpr inline reference operator[] (size_type n) noexcept
 Accesses an element by index.
 
constexpr inline const_reference operator[] (size_type n) const noexcept
 Accesses an element by index.
 
constexpr inline reference front () noexcept
 Accesses the first element in the vector.
 
constexpr inline const_reference front () const noexcept
 Accesses the first element in the vector.
 
constexpr inline reference back () noexcept
 Accesses the last element in the vector.
 
constexpr inline const_reference back () const noexcept
 Accesses the last element in the vector.
 
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 iterator begin () noexcept
 Return iterator to the first element.
 
constexpr inline const_iterator begin () const noexcept
 Return const iterator to the first element.
 
constexpr inline const_iterator cbegin () const noexcept
 Return const iterator to the first element.
 
constexpr inline reverse_iterator rbegin () noexcept
 Returns an reverse iterator to the first element.
 
constexpr inline const_reverse_iterator rbegin () const noexcept
 Returns a const iterator to the first element.
 
constexpr inline const_reverse_iterator crbegin () const noexcept
 Returns a const reverse iterator to the first element.
 
constexpr inline iterator end () noexcept
 Returns an iterator to the element following the last element.
 
constexpr inline const_iterator end () const noexcept
 Returns a const iterator to the element following the last element.
 
constexpr inline const_iterator cend () const noexcept
 Returns a const iterator to the element following the last element.
 
constexpr inline reverse_iterator rend () noexcept
 Returns a reverse iterator to the element following the last element.
 
constexpr inline const_reverse_iterator rend () const noexcept
 Returns a const reverse iterator to the element following the last element.
 
constexpr inline const_reverse_iterator crend () const noexcept
 Returns a const reverse iterator to the element following the last element.
 
constexpr inline bool empty () const noexcept
 Determines whether the container is empty.
 
constexpr inline size_type size () const noexcept
 Returns the number of elements in the container.
 
constexpr inline void resize (size_type n) noexcept
 Resizes the container to the specified size.
 
constexpr inline void resize (size_type n, const_reference value) noexcept
 Resizes the container to the specified size and initializes new elements with the given value.
 
constexpr inline iterator insert (const_iterator pos, const_reference value) noexcept
 Inserts copies of the given value at the specified position.
 
constexpr inline iterator insert (const_iterator pos, value_type &&value) noexcept
 Moves the given value at the specified position.
 
constexpr inline iterator insert (const_iterator pos, size_type n, const_reference value) noexcept
 Inserts copies of the given value at the specified position.
 
template<typename It >
constexpr inline iterator insert (const_iterator pos, It first, It last) noexcept
 Inserts range of elements at the specified position.
 
constexpr inline iterator insert (const_iterator pos, std::initializer_list< value_type > init_list) noexcept
 Inserts initializer list of elements at the specified position.
 
template<typename... Args>
constexpr inline iterator emplace (const_iterator pos, Args &&... args) noexcept
 Inserts a new element at the specified position, constructed in-place with the given arguments.
 
template<typename... Args>
constexpr inline reference emplace_back (Args &&... args) noexcept
 Inserts a new element at the end of the vector, constructed in-place with the given arguments.
 
template<typename... Args>
constexpr inline pointer try_emplace_back (Args &&... args) noexcept
 Inserts a new element at the end of the vector, constructed in-place with the given arguments.
 
template<typename... Args>
constexpr inline reference unchecked_emplace_back (Args &&... args) noexcept
 Inserts a new element at the end of the vector, constructed in-place with the given arguments.
 
constexpr inline reference push_back (const_reference value) noexcept
 Adds a new element at the end of the vector.
 
constexpr inline reference push_back (value_type &&value) noexcept
 Adds a new element at the end of the vector.
 
constexpr inline pointer try_push_back (const_reference value) noexcept
 Adds a new element at the end of the vector.
 
constexpr inline pointer try_push_back (value_type &&value) noexcept
 Adds a new element at the end of the vector.
 
constexpr inline reference unchecked_push_back (const_reference value) noexcept
 Adds a new element at the end of the vector without checking the size.
 
constexpr inline reference unchecked_push_back (value_type &&value) noexcept
 Adds a new element at the end of the vector without checking the size.
 
constexpr inline void pop_back () noexcept
 Removes the last element from the vector.
 
constexpr inline void clear () noexcept
 Removes all elements from the vector.
 
constexpr inline iterator erase (const_iterator pos) noexcept
 Removes the element at the specified position.
 
constexpr inline iterator erase (const_iterator first, const_iterator last) noexcept
 Remove range of elements from the vector.
 
constexpr inline void swap (fixed_vector &other) noexcept
 Swaps the contents of this vector with another vector.
 

Static Public Member Functions

static constexpr inline size_type max_size () noexcept
 Returns the maximum number of elements that the container can hold.
 
static constexpr inline size_type capacity () noexcept
 Returns the maximum number of elements that the container can hold.
 
static constexpr inline void reserve (size_type n) noexcept
 Reserves space for the specified number of elements.
 
static constexpr inline void shrink_to_fit () noexcept
 Shrinks the container to fit its current size.
 

Detailed Description

template<typename T, size_t N>
class ipaddress::fixed_vector< T, N >

A fixed-size vector class template.

The fixed_vector class template provides a simple fixed-size array wrapper that allows for compile-time operations.

Template Parameters
Ttype of the elements in the vector.
Ncapacity of the vector.
Remarks
The fixed_vector class is a simple fixed-size array wrapper that provides a subset of the functionality of std::vector. This class is designed to work in constexpr contexts, allowing compile-time operations on fixed-size arrays.

Member Typedef Documentation

◆ iterator

template<typename T , size_t N>
using iterator = fixed_vector_iterator<value_type>

type used for iterator to elements.


Constructor & Destructor Documentation

◆ fixed_vector() [1/4]

template<typename T , size_t N>
inline fixed_vector ( size_type n)
inlineexplicitnoexcept

Constructs a fixed_vector with the specified number of default-initialized elements.

Parameters
[in]nThe number of elements to initialize.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ fixed_vector() [2/4]

template<typename T , size_t N>
inline fixed_vector ( size_type n,
const_reference value )
inlinenoexcept

Constructs a fixed_vector with the specified number of elements initialized to the given value.

Parameters
[in]nThe number of elements to initialize.
[in]valueThe value to initialize the elements with.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ fixed_vector() [3/4]

template<typename T , size_t N>
template<class It >
inline fixed_vector ( It first,
It last )
inlinenoexcept

Constructs a fixed_vector from a range of elements.

Template Parameters
ItThe iterator type.
Parameters
[in]firstThe beginning iterator of the range.
[in]lastThe ending iterator of the range.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ fixed_vector() [4/4]

template<typename T , size_t N>
inline fixed_vector ( std::initializer_list< value_type > init_list)
inlinenoexcept

Constructs a fixed_vector from an initializer list.

Parameters
[in]init_listThe initializer list of elements.
Remarks
The number of elements must not exceed the maximum size of the vector.

Member Function Documentation

◆ assign() [1/3]

template<typename T , size_t N>
inline void assign ( size_type n,
const_reference value )
inlinenoexcept

Replaces the contents with the specified number of copies of the given value.

Parameters
[in]nThe number of elements to assign.
[in]valueThe value to assign to the elements.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ assign() [2/3]

template<typename T , size_t N>
template<class It >
inline void assign ( It first,
It last )
inlinenoexcept

Replaces the contents with the elements in the specified range.

Template Parameters
ItThe iterator type.
Parameters
[in]firstThe beginning iterator of the range.
[in]lastThe ending iterator of the range.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ assign() [3/3]

template<typename T , size_t N>
inline void assign ( std::initializer_list< value_type > init_list)
inlinenoexcept

Replaces the contents with the elements in the specified initializer list.

Parameters
[in]init_listThe initializer list of elements.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ at() [1/2]

template<typename T , size_t N>
inline reference at ( size_type n)
inlinenodiscardnoexcept

Accesses an element by index.

Parameters
[in]nThe index of the element.
Returns
The element at the specified index.
Remarks
n must be less than the size of the vector.

◆ at() [2/2]

template<typename T , size_t N>
inline const_reference at ( size_type n) const
inlinenodiscardnoexcept

Accesses an element by index.

Parameters
[in]nThe index of the element.
Returns
The element at the specified index.
Remarks
n must be less than the size of the vector.

◆ operator[]() [1/2]

template<typename T , size_t N>
inline reference operator[] ( size_type n)
inlinenodiscardnoexcept

Accesses an element by index.

Parameters
[in]nThe index of the element.
Returns
The element at the specified index.
Remarks
n must be less than the size of the vector.

◆ operator[]() [2/2]

template<typename T , size_t N>
inline const_reference operator[] ( size_type n) const
inlinenodiscardnoexcept

Accesses an element by index.

Parameters
[in]nThe index of the element.
Returns
The element at the specified index.
Remarks
n must be less than the size of the vector.

◆ front() [1/2]

template<typename T , size_t N>
inline reference front ( )
inlinenodiscardnoexcept

Accesses the first element in the vector.

Returns
A reference to the first element in the vector.

◆ front() [2/2]

template<typename T , size_t N>
inline const_reference front ( ) const
inlinenodiscardnoexcept

Accesses the first element in the vector.

Returns
A reference to the first element in the vector.

◆ back() [1/2]

template<typename T , size_t N>
inline reference back ( )
inlinenodiscardnoexcept

Accesses the last element in the vector.

Returns
A reference to the last element in the vector.

◆ back() [2/2]

template<typename T , size_t N>
inline const_reference back ( ) const
inlinenodiscardnoexcept

Accesses the last element in the vector.

Returns
A reference to the last element in the vector.

◆ data() [1/2]

template<typename T , size_t N>
inline pointer data ( )
inlinenodiscardnoexcept

Returns a pointer to the underlying array.

Returns
A pointer to the underlying array of type value_type.

◆ data() [2/2]

template<typename T , size_t N>
inline const_pointer data ( ) const
inlinenodiscardnoexcept

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

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

◆ begin() [1/2]

template<typename T , size_t N>
inline iterator begin ( )
inlinenodiscardnoexcept

Return iterator to the first element.

Returns
An iterator to the first element in the vector.

◆ begin() [2/2]

template<typename T , size_t N>
inline const_iterator begin ( ) const
inlinenodiscardnoexcept

Return const iterator to the first element.

Returns
A const iterator to the first element in the vector.

◆ cbegin()

template<typename T , size_t N>
inline const_iterator cbegin ( ) const
inlinenodiscardnoexcept

Return const iterator to the first element.

Returns
A const iterator to the first element in the vector.

◆ rbegin() [1/2]

template<typename T , size_t N>
inline reverse_iterator rbegin ( )
inlinenodiscardnoexcept

Returns an reverse iterator to the first element.

Returns
A reverse iterator to the first element in the vector.

◆ rbegin() [2/2]

template<typename T , size_t N>
inline const_reverse_iterator rbegin ( ) const
inlinenodiscardnoexcept

Returns a const iterator to the first element.

Returns
A const reverse iterator to the first element in the vector.

◆ crbegin()

template<typename T , size_t N>
inline const_reverse_iterator crbegin ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator to the first element.

Returns
A const reverse iterator to the first element in the vector.

◆ end() [1/2]

template<typename T , size_t N>
inline iterator end ( )
inlinenodiscardnoexcept

Returns an iterator to the element following the last element.

Returns
An iterator to the element following the last element in the vector.

◆ end() [2/2]

template<typename T , size_t N>
inline const_iterator end ( ) const
inlinenodiscardnoexcept

Returns a const iterator to the element following the last element.

Returns
A const iterator to the element following the last element in the vector.

◆ cend()

template<typename T , size_t N>
inline const_iterator cend ( ) const
inlinenodiscardnoexcept

Returns a const iterator to the element following the last element.

Returns
A const iterator to the element following the last element in the vector.

◆ rend() [1/2]

template<typename T , size_t N>
inline reverse_iterator rend ( )
inlinenodiscardnoexcept

Returns a reverse iterator to the element following the last element.

Returns
A reverse iterator to the element following the last element in the vector.

◆ rend() [2/2]

template<typename T , size_t N>
inline const_reverse_iterator rend ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator to the element following the last element.

Returns
A const reverse iterator to the element following the last element in the vector.

◆ crend()

template<typename T , size_t N>
inline const_reverse_iterator crend ( ) const
inlinenodiscardnoexcept

Returns a const reverse iterator to the element following the last element.

Returns
A const reverse iterator to the element following the last element in the vector.

◆ empty()

template<typename T , size_t N>
inline bool empty ( ) const
inlinenodiscardnoexcept

Determines whether the container is empty.

Returns
true if the container is empty; otherwise, false.

◆ size()

template<typename T , size_t N>
inline size_type size ( ) const
inlinenodiscardnoexcept

Returns the number of elements in the container.

Returns
The number of elements in the container.

◆ max_size()

template<typename T , size_t N>
static constexpr inline size_type max_size ( )
inlinestaticnodiscardnoexcept

Returns the maximum number of elements that the container can hold.

Returns
The maximum number of elements that the container can hold.

◆ capacity()

template<typename T , size_t N>
static constexpr inline size_type capacity ( )
inlinestaticnodiscardnoexcept

Returns the maximum number of elements that the container can hold.

Returns
The maximum number of elements that the container can hold.

◆ resize() [1/2]

template<typename T , size_t N>
inline void resize ( size_type n)
inlinenoexcept

Resizes the container to the specified size.

If n is less than the current size, the container is truncated. If n is greater, default-inserted elements are added.

Parameters
[in]nThe new size of the container.
Remarks
n must not exceed the maximum size.

◆ resize() [2/2]

template<typename T , size_t N>
inline void resize ( size_type n,
const_reference value )
inlinenoexcept

Resizes the container to the specified size and initializes new elements with the given value.

If n is less than the current size, the container is truncated. If n is greater, copies of value are appended.

Parameters
[in]nThe new size of the container.
[in]valueThe value to initialize new elements with.
Remarks
n must not exceed the maximum size.

◆ reserve()

template<typename T , size_t N>
static constexpr inline void reserve ( size_type n)
inlinestaticnoexcept

Reserves space for the specified number of elements.

Parameters
[in]nThe number of elements to reserve space for.
Note
This function does not change the size of the container. It is a no-op for fixed_vector, as the size is fixed at compile time. The function is provided for compatibility with std::vector.
Remarks
n must not exceed the maximum size.

◆ shrink_to_fit()

template<typename T , size_t N>
static constexpr inline void shrink_to_fit ( )
inlinestaticnoexcept

Shrinks the container to fit its current size.

Note
This function does not change the size of the container. It is a no-op for fixed_vector, as the size is fixed at compile time. The function is provided for compatibility with std::vector.

◆ insert() [1/5]

template<typename T , size_t N>
inline iterator insert ( const_iterator pos,
const_reference value )
inlinenoexcept

Inserts copies of the given value at the specified position.

Parameters
[in]posThe position to insert the value at.
[in]valueThe value to insert.
Returns
An iterator to the inserted element.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ insert() [2/5]

template<typename T , size_t N>
inline iterator insert ( const_iterator pos,
value_type && value )
inlinenoexcept

Moves the given value at the specified position.

Parameters
[in]posThe position to insert the value at.
[in]valueThe value to insert.
Returns
An iterator to the inserted element.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ insert() [3/5]

template<typename T , size_t N>
inline iterator insert ( const_iterator pos,
size_type n,
const_reference value )
inlinenoexcept

Inserts copies of the given value at the specified position.

Parameters
[in]posThe position to insert the value at.
[in]nThe number of copies to insert.
[in]valueThe value to insert.
Returns
An iterator pointing to the first inserted element.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ insert() [4/5]

template<typename T , size_t N>
template<typename It >
inline iterator insert ( const_iterator pos,
It first,
It last )
inlinenoexcept

Inserts range of elements at the specified position.

Template Parameters
ItThe iterator type.
Parameters
[in]posThe position to insert the elements at.
[in]firstThe beginning iterator of the range.
[in]lastThe ending iterator of the range.
Returns
An iterator pointing to the first inserted element.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ insert() [5/5]

template<typename T , size_t N>
inline iterator insert ( const_iterator pos,
std::initializer_list< value_type > init_list )
inlinenoexcept

Inserts initializer list of elements at the specified position.

Parameters
[in]posThe position to insert the elements at.
[in]init_listThe initializer list of elements.
Returns
An iterator pointing to the first inserted element.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ emplace()

template<typename T , size_t N>
template<typename... Args>
inline iterator emplace ( const_iterator pos,
Args &&... args )
inlinenoexcept

Inserts a new element at the specified position, constructed in-place with the given arguments.

Template Parameters
ArgsThe argument types for constructing the element.
Parameters
[in]posThe position to insert the element at.
[in]argsThe arguments for constructing the element.
Returns
An iterator pointing to the inserted element.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ emplace_back()

template<typename T , size_t N>
template<typename... Args>
inline reference emplace_back ( Args &&... args)
inlinenoexcept

Inserts a new element at the end of the vector, constructed in-place with the given arguments.

Template Parameters
ArgsThe argument types for constructing the element.
Parameters
[in]argsThe arguments for constructing the element.
Returns
A reference to the inserted element.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ try_emplace_back()

template<typename T , size_t N>
template<typename... Args>
inline pointer try_emplace_back ( Args &&... args)
inlinenoexcept

Inserts a new element at the end of the vector, constructed in-place with the given arguments.

Template Parameters
ArgsThe argument types for constructing the element.
Parameters
[in]argsThe arguments for constructing the element.
Returns
A pointer to the inserted element, or nullptr if the insertion failed.

◆ unchecked_emplace_back()

template<typename T , size_t N>
template<typename... Args>
inline reference unchecked_emplace_back ( Args &&... args)
inlinenoexcept

Inserts a new element at the end of the vector, constructed in-place with the given arguments.

Template Parameters
ArgsThe argument types for constructing the element.
Parameters
[in]argsThe arguments for constructing the element.
Returns
A reference to the inserted element.
Remarks
The condition size() < capacity() must hold true before calling this function. Otherwise, the behavior is undefined.

◆ push_back() [1/2]

template<typename T , size_t N>
inline reference push_back ( const_reference value)
inlinenoexcept

Adds a new element at the end of the vector.

Parameters
[in]valueThe value to add.
Returns
A reference to the added element.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ push_back() [2/2]

template<typename T , size_t N>
inline reference push_back ( value_type && value)
inlinenoexcept

Adds a new element at the end of the vector.

Parameters
[in]valueThe value to add.
Returns
A reference to the added element.
Remarks
The number of elements must not exceed the maximum size of the vector.

◆ try_push_back() [1/2]

template<typename T , size_t N>
inline pointer try_push_back ( const_reference value)
inlinenoexcept

Adds a new element at the end of the vector.

Parameters
[in]valueThe value to add.
Returns
A pointer to the added element, or nullptr if the insertion failed.

◆ try_push_back() [2/2]

template<typename T , size_t N>
inline pointer try_push_back ( value_type && value)
inlinenoexcept

Adds a new element at the end of the vector.

Parameters
[in]valueThe value to add.
Returns
A pointer to the added element, or nullptr if the insertion failed.

◆ unchecked_push_back() [1/2]

template<typename T , size_t N>
inline reference unchecked_push_back ( const_reference value)
inlinenoexcept

Adds a new element at the end of the vector without checking the size.

Parameters
[in]valueThe value to add.
Returns
A reference to the added element.
Remarks
The condition size() < capacity() must hold true before calling this function. Otherwise, the behavior is undefined.

◆ unchecked_push_back() [2/2]

template<typename T , size_t N>
inline reference unchecked_push_back ( value_type && value)
inlinenoexcept

Adds a new element at the end of the vector without checking the size.

Parameters
[in]valueThe value to add.
Returns
A reference to the added element.
Remarks
The condition size() < capacity() must hold true before calling this function. Otherwise, the behavior is undefined.

◆ pop_back()

template<typename T , size_t N>
inline void pop_back ( )
inlinenoexcept

Removes the last element from the vector.

Remarks
The vector must not be empty before calling this function.

◆ clear()

template<typename T , size_t N>
inline void clear ( )
inlinenoexcept

Removes all elements from the vector.

Remarks
The vector will be empty after calling this function.

◆ erase() [1/2]

template<typename T , size_t N>
inline iterator erase ( const_iterator pos)
inlinenoexcept

Removes the element at the specified position.

Parameters
[in]posThe position of the element to remove.
Returns
An iterator to the next element after the removed element.
Remarks
The vector must not be empty before calling this function.

◆ erase() [2/2]

template<typename T , size_t N>
inline iterator erase ( const_iterator first,
const_iterator last )
inlinenoexcept

Remove range of elements from the vector.

Parameters
[in]firstThe position of the first element to remove.
[in]lastThe position of the last element to remove.
Returns
An iterator to the next element after the last removed element.

◆ swap()

template<typename T , size_t N>
inline void swap ( fixed_vector< T, N > & other)
inlinenoexcept

Swaps the contents of this vector with another vector.

Parameters
[in]otherThe other vector to swap with.

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