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

Fixed size string class. More...

#include <fixed-string.hpp>

Inheritance diagram for fixed_string< N >:

Public Types

using value_type = char
 Type of character in a string.
 
using const_pointer = const char*
 Type of constant pointer to the string data.
 
using const_reference = const char&
 Type of constant reference to a character in the string.
 
using const_iterator = const_pointer
 Type of constant iterator for traversing the string.
 
using const_reverse_iterator = std::reverse_iterator<const_iterator>
 Type of constant reverse iterator for traversing the string in reverse.
 

Public Member Functions

constexpr inline fixed_string () noexcept=default
 Default constructor.
 
template<typename T >
constexpr inline fixed_string (const T(&data)[N+1]) noexcept(noexcept(internal::char_reader< T >::has_throw()))
 Constructs a fixed_string from a character array.
 
template<typename T >
constexpr inline fixed_string (const T(&data)[N+1], error_code &code) noexcept
 Constructs a fixed_string from a character array.
 
constexpr inline const_iterator begin () const noexcept
 Retrieves the begin iterator of the fixed_string.
 
constexpr inline const_iterator end () const noexcept
 Retrieves the end iterator of the fixed_string.
 
constexpr inline const_reverse_iterator rbegin () const noexcept
 Retrieves the reverse begin iterator of the fixed_string.
 
constexpr inline const_reverse_iterator rend () const noexcept
 Retrieves the reverse end iterator of the fixed_string.
 
constexpr inline const_iterator cbegin () const noexcept
 Retrieves the constant begin iterator of the fixed_string.
 
constexpr inline const_iterator cend () const noexcept
 Retrieves the constant end iterator of the fixed_string.
 
constexpr inline const_reverse_iterator crbegin () const noexcept
 Retrieves the constant reverse begin iterator of the fixed_string.
 
constexpr inline const_reverse_iterator crend () const noexcept
 Retrieves the constant reverse end iterator of the fixed_string.
 
constexpr inline bool empty () const noexcept
 Checks if the fixed_string is empty.
 
constexpr inline size_t size () const noexcept
 Retrieves the size of the fixed_string.
 
constexpr inline size_t capacity () const noexcept
 Retrieves the capacity of the fixed_string.
 
constexpr inline const_reference operator[] (size_t n) const noexcept
 Accesses the character at the specified location with bounds checking.
 
constexpr inline const_reference at (size_t n) const noexcept
 Accesses the character at the specified location with bounds checking.
 
constexpr inline const_reference front () const noexcept
 Accesses the first element.
 
constexpr inline const_reference back () const noexcept
 Accesses the last element.
 
constexpr inline const_pointer data () const noexcept
 Provides a pointer to the underlying data.
 
template<size_t N2>
constexpr inline int compare (const fixed_string< N2 > &rhs) const noexcept
 Compares the string with another fixed_string.
 
constexpr inline size_t hash () const noexcept
 Calculates the hash of the string.
 
constexpr inline void swap (fixed_string &other) noexcept
 Swaps the contents with another fixed_string.
 

Detailed Description

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

Fixed size string class.

fixed_string is a template class that encapsulates a string of a fixed number of characters. It is designed to be used where strings are needed as non-type template parameters.

Template Parameters
NThe maximum number of characters the fixed_string can hold.

Constructor & Destructor Documentation

◆ fixed_string() [1/3]

template<size_t N>
constexpr inline fixed_string ( )
defaultnoexcept

Default constructor.

Constructs a fixed_string with default values, initializing the string with null characters.

◆ fixed_string() [2/3]

template<size_t N>
template<typename T >
constexpr inline fixed_string ( const T(&) data[N+1])
inlinenoexcept

Constructs a fixed_string from a character array.

This constructor template initializes a fixed_string with the contents of a given character array.

Template Parameters
TThe character type of the input array.
Parameters
[in]dataThe character array to initialize the fixed_string with.
Exceptions
parse_errorThrown if contains unexpected characters for addresses

◆ fixed_string() [3/3]

template<size_t N>
template<typename T >
constexpr inline fixed_string ( const T(&) data[N+1],
error_code & code )
inlinenoexcept

Constructs a fixed_string from a character array.

This constructor template initializes a fixed_string with the contents of a given character array.

Template Parameters
TThe character type of the input array.
Parameters
[in]dataThe character array to initialize the fixed_string with.
[out]codeA reference to an error_code object that will be set if an error occurs during parsing.

Member Function Documentation

◆ begin()

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

Retrieves the begin iterator of the fixed_string.

Returns an iterator pointing to the first character of the fixed_string. If the fixed_string is empty, the returned iterator will be equal to the one returned by end().

Returns
A constant iterator to the beginning of the fixed_string.
See also
end()

◆ end()

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

Retrieves the end iterator of the fixed_string.

Returns an iterator pointing to the past-the-end character of the fixed_string. This iterator acts as a placeholder and should not be dereferenced.

Returns
A constant iterator to the element following the last character.
See also
begin()

◆ rbegin()

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

Retrieves the reverse begin iterator of the fixed_string.

Returns a reverse iterator pointing to the last character of the fixed_string. If the fixed_string is empty, the returned iterator will be equal to rend().

Returns
A constant reverse iterator to the beginning of the reversed fixed_string.
See also
rend()

◆ rend()

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

Retrieves the reverse end iterator of the fixed_string.

Returns a reverse iterator pointing to the position preceding the first character of the fixed_string. This iterator acts as a placeholder and should not be dereferenced.

Returns
A constant reverse iterator to the end of the reversed fixed_string.
See also
rbegin()

◆ cbegin()

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

Retrieves the constant begin iterator of the fixed_string.

Returns a constant iterator pointing to the first character of the fixed_string. If the fixed_string is empty, the returned iterator will be equal to cend().

Returns
A constant iterator to the beginning of the fixed_string.
See also
cend()

◆ cend()

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

Retrieves the constant end iterator of the fixed_string.

Returns a constant iterator pointing to the past-the-end character of the fixed_string. This iterator acts as a placeholder and should not be dereferenced.

Returns
A constant iterator to the end of the fixed_string.
See also
cbegin()

◆ crbegin()

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

Retrieves the constant reverse begin iterator of the fixed_string.

Returns a constant reverse iterator pointing to the last character of the fixed_string. If the fixed_string is empty, the returned iterator will be equal to crend().

Returns
A constant reverse iterator to the beginning of the reversed fixed_string.
See also
crend()

◆ crend()

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

Retrieves the constant reverse end iterator of the fixed_string.

Returns a reverse iterator pointing to the position preceding the first character of the fixed_string when reversed. This iterator acts as a placeholder and should not be dereferenced.

Returns
A constant reverse iterator to the end of the reversed fixed_string.
See also
crbegin()

◆ empty()

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

Checks if the fixed_string is empty.

Evaluates whether the fixed_string contains no characters.

Returns
true if the fixed_string is empty, false otherwise.

◆ size()

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

Retrieves the size of the fixed_string.

Returns the number of characters currently stored in the fixed_string.

Returns
The number of characters in the fixed_string.
See also
capacity()

◆ capacity()

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

Retrieves the capacity of the fixed_string.

Returns the total number of characters that the fixed_string can hold.

Returns
The capacity of the fixed_string.
See also
size()

◆ operator[]()

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

Accesses the character at the specified location with bounds checking.

Returns a reference to the character at the specified location n. If n is out of bounds, an exception of type std::out_of_range will be thrown.

Parameters
[in]nThe position of the character to return.
Returns
A reference to the character at the specified location.
Exceptions
std::out_of_rangeWhen going beyond the bounds of the character array.
See also
at(size_t) const

◆ at()

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

Accesses the character at the specified location with bounds checking.

Returns a reference to the character at the specified location n. If n is out of bounds, an exception of type std::out_of_range will be thrown.

Parameters
[in]nThe position of the character to return.
Returns
A reference to the character at the specified location.
Exceptions
std::out_of_rangeWhen going beyond the bounds of the character array.
See also
operator[](size_t) const

◆ front()

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

Accesses the first element.

Provides a reference to the first element in the string. Undefined behavior occurs if this function is called on an empty string.

Returns
Reference to the first element.
See also
back()

◆ back()

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

Accesses the last element.

Provides a reference to the last element in the string. Undefined behavior occurs if this function is called on an empty string.

Returns
Reference to the last element.
See also
front()

◆ data()

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

Provides a pointer to the underlying data.

Returns a pointer to the underlying array serving as the string's storage. The range [data(), data() + size()) is valid even if the string is empty, but the data is not dereferenceable in that case.

Returns
Pointer to the underlying data storage.

◆ compare()

template<size_t N>
template<size_t N2>
constexpr inline int compare ( const fixed_string< N2 > & rhs) const
inlinenoexcept

Compares the string with another fixed_string.

Compares the string with another fixed_string lexicographically.

Template Parameters
N2The size of the other fixed_string.
Parameters
[in]rhsThe other fixed_string to compare with.
Returns
Negative value if less, zero if equal, positive value if greater.

◆ hash()

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

Calculates the hash of the string.

Computes a hash value for the string using a FNV-1a hash function.

Returns
The hash value of the string.

◆ swap()

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

Swaps the contents with another fixed_string.

Exchanges the contents of the string with those of another fixed_string.

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

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