Template Struct fixed_string

Struct Documentation

template<size_t MAX_CHARS>
struct fixed_string

Template class for non-alloc strings.

Will be truncated when assigned from a longer string.

Template Parameters:

MAX_CHARS – Maximum number of characters is specified as the template parameter. Space for an additional null terminator will be reserved.

Public Functions

inline fixed_string() noexcept

Default constructor.

inline fixed_string(const char *c_array, size_t n_chars) noexcept

Constructs from a char array.

Parameters:
  • c_array[in] Char array to be constructed from.

  • n_chars[in] Number of characters of the Char array

inline fixed_string &assign(const char *c_array, size_t n_chars) noexcept

Assigns from a char array.

Parameters:
  • c_array[in] Char array to be assigned from.

  • n_chars[in] Number of characters of the Char array.

Returns:

Reference of this instance.

inline fixed_string(const char *c_string) noexcept

Constructs from a C string.

Parameters:

c_string[in] Pointer to the C string.

inline fixed_string &operator=(const char *c_string) noexcept

Assigns from a C string.

Parameters:

c_string[in] Pointer to the C string.

Returns:

Reference of this instance.

inline fixed_string(const std::string &str) noexcept

Constructs from a std::string.

Parameters:

str[in] Reference to the std::string.

inline fixed_string &operator=(const std::string &str) noexcept

Assigns from a std::string.

Parameters:

str[in] Reference to the std::string. return Reference of this instance.

template<size_t N>
inline fixed_string &operator=(const fixed_string<N> &rhs) noexcept

Assigns from a fixed_string of any size.

Parameters:

rhs[in] Reference to the fixed_string. return Reference of this instance.

inline const char *c_str() const noexcept

Converts to C string.

Returns:

Pointer to the C string.

inline std::string to_string() const

Converts to std::string.

Returns:

Reference to the std::string.

inline bool operator==(const char *rhs) const noexcept

Compares equality with a C string.

Parameters:

rhs[in] C string to be compared with.

Returns:

true if strings are equal. false otherwise.

inline bool operator==(const std::string &rhs) const noexcept

Compares equality with a std::string.

Parameters:

rhs[in] std::string to be compared with.

Returns:

true if strings are equal. false otherwise.

template<size_t N>
inline bool operator==(const fixed_string<N> &rhs) const noexcept

Compares equality with a fixed_string of any size.

Parameters:

rhs[in] fixed_string to be compared with.

Returns:

true if strings are equal. false otherwise.

inline bool operator!=(const char *rhs) const noexcept

Compares inequality with a C string.

Parameters:

rhs[in] C string to be compared with.

Returns:

true if strings are not equal. false otherwise.

inline bool operator!=(const std::string &rhs) const noexcept

Compares inequality with a std::string.

Parameters:

rhs[in] std::string to be compared with.

Returns:

true if strings are not equal. false otherwise.

template<size_t N>
inline bool operator!=(const fixed_string<N> &rhs) const noexcept

Compares inequality with a fixed_string of any size.

Parameters:

rhs[in] fixed_string to be compared with.

Returns:

true if strings are not equal. false otherwise.

template<size_t N>
inline bool operator<(const fixed_string<N> &rhs) const noexcept

Compares relational less than with a fixed_string of any size.

Parameters:

rhs[in] fixed_string to be compared with.

Returns:

true if this string is less than the provided one. false otherwise.

template<size_t N>
inline bool operator>(const fixed_string<N> &rhs) const noexcept

Compares relational greater than with a fixed_string of any size.

Parameters:

rhs[in] fixed_string to be compared with.

Returns:

true if this string is greater than the provided one. false otherwise.

inline bool operator<(const std::string &rhs) const noexcept

Compares relational less than with a std::string of any size.

Parameters:

rhs[in] std::string to be compared with.

Returns:

true if this string is less than the provided one. false otherwise.

inline bool operator>(const std::string &rhs) const noexcept

Compares relational greater than with a std::string of any size.

Parameters:

rhs[in] std::string to be compared with.

Returns:

true if this string is greater than the provided one. false otherwise.

inline operator const char*() const noexcept

Casts to a C string.

inline size_t size() const noexcept

Returns the size of the string.

Returns:

Length of the string.

inline int compare(const char *str) const noexcept

Compares with a C string.

Parameters:

str[in] C string to be compared with.

Returns:

Integer value with the result of the comparison as described in std::string::compare().

inline int compare(const std::string &str) const noexcept

Compares with a std::string.

Parameters:

str[in] std::string to be compared with.

Returns:

Integer value with the result of the comparison as described in std::string::compare().

template<size_t N>
inline int compare(const fixed_string<N> &str) const noexcept

Compares with a fixed_string.

Parameters:

str[in] fixed_string to be compared with.

Returns:

Integer value with the result of the comparison as described in std::string::compare().

Public Static Attributes

static constexpr size_t max_size = MAX_CHARS

Maximum number of characters.