xentara-utils v1.2.1
Xentara utilities library
Loading...
Searching...
No Matches
xentara::utils::string::BasicFixedString< Char, kSize, CharTraits > Class Template Reference

A string with a fixed size. More...

#include <string/FixedString.hpp>

Public Types

using traits_type = CharTraits
 The character traits.
 
using value_type = Char
 The character type.
 
using size_type = std::size_t
 The type used for sizes.
 
using difference_type = std::ptrdiff_t
 The type used for distances.
 
using reference = value_type &
 A reference to an character.
 
using const_reference = const value_type &
 A const reference to an character.
 
using pointer = value_type *
 A pointer to an character.
 
using const_pointer = const value_type *
 A const pointer to an character.
 
using iterator = core::ContiguousIterator< pointer, BasicFixedString >
 An iterator.
 
using const_iterator = core::ContiguousIterator< const_pointer, BasicFixedString >
 A const iterator.
 
using reverse_iterator = std::reverse_iterator< iterator >
 An iterator for iterating in reverse order.
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 A const iterator for iterating in reverse order.
 

Public Member Functions

constexpr BasicFixedString (Char character=0) noexcept
 Constructor for a string filled with a specific character.
 
constexpr BasicFixedString (UninitializedTag tag) noexcept
 Constructor for a containing uninitialized characters.
 
Character Access
constexpr operator std::basic_string_view< Char, CharTraits > () const noexcept
 conversion to a string view
 
template<typename Allocator >
constexpr operator std::basic_string< Char, CharTraits, Allocator > () const noexcept
 conversion to an std::string
 
constexpr auto view () const noexcept -> std::basic_string_view< Char, CharTraits >
 Gets the data as a string view.
 
template<typename Allocator = std::allocator<Char>>
constexpr auto str (const Allocator &allocator=Allocator()) const noexcept -> std::basic_string< Char, CharTraits, Allocator >
 Gets the data as an std::string.
 
constexpr auto at (size_type index) const -> const_reference
 Accesses the character at a certain index.
 
constexpr auto at (size_type index) -> reference
 Accesses the character at a certain index.
 
constexpr auto operator[] (size_type index) const noexcept -> const_reference
 Subscript operator.
 
constexpr auto operator[] (size_type index) noexcept -> reference
 Subscript operator.
 
constexpr auto front () const noexcept -> const_reference
 Returns the first character.
 
constexpr auto front () noexcept -> reference
 Returns the first character.
 
constexpr auto back () const noexcept -> const_reference
 Returns the last character.
 
constexpr auto back () noexcept -> reference
 Returns the last character.
 
constexpr auto data () const noexcept -> const Char *
 Gets a pointer to the data.
 
constexpr auto data () noexcept -> Char *
 Gets a pointer to the data.
 
constexpr auto c_str () const noexcept -> const Char *
 Gets the data as a null terminated string.
 
Iterators
constexpr auto begin () noexcept -> iterator
 Creates a begin iterator.
 
constexpr auto begin () const noexcept -> const_iterator
 Creates a begin iterator.
 
constexpr auto cbegin () const noexcept -> const_iterator
 Creates a begin iterator.
 
constexpr auto end () noexcept -> iterator
 Creates an end iterator.
 
constexpr auto end () const noexcept -> const_iterator
 Creates an end iterator.
 
constexpr auto cend () const noexcept -> const_iterator
 Creates an end iterator.
 
constexpr auto rbegin () noexcept -> reverse_iterator
 Creates a reverse begin iterator.
 
constexpr auto rbegin () const noexcept -> const_reverse_iterator
 Creates a reverse begin iterator.
 
constexpr auto crbegin () const noexcept -> const_reverse_iterator
 Creates a reverse begin iterator.
 
constexpr auto rend () noexcept -> reverse_iterator
 Creates a reverse end iterator.
 
constexpr auto rend () const noexcept -> const_reverse_iterator
 Creates a reverse end iterator.
 
constexpr auto crend () const noexcept -> const_reverse_iterator
 Creates a reverse end iterator.
 

Related Symbols

(Note that these are not member symbols.)

template<typename Char , typename CharTraits , std::size_t kSize, std::size_t kCapacity>
auto operator== (const BasicFixedString< Char, kSize, CharTraits > &lhs, const BasicStaticString< Char, kCapacity, CharTraits > &rhs) -> bool
 Comparison operator with a static string.
 
template<typename Char , typename CharTraits , std::size_t kSize, std::size_t kCapacity>
auto operator (const BasicFixedString< Char, kSize, CharTraits > &lhs, const BasicStaticString< Char, kCapacity, CharTraits > &rhs) -> auto
 Comparison operator with a static string.
 

Size and Capacity

constexpr auto empty () const noexcept -> bool
 Determines whether the string is empty.
 
constexpr auto size () const noexcept -> std::size_t
 Gets the current size.
 
constexpr auto capacity () const noexcept -> std::size_t
 Gets the capacity of the string.
 
static constexpr auto max_size () noexcept -> std::size_t
 Gets the maximum size.
 

Detailed Description

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
class xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >

A string with a fixed size.

Template Parameters
CharThe character type
kSizeThe size of the string
CharTraitsThe char traits used for interacting with the standard C++ library

Member Typedef Documentation

◆ const_iterator

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::const_iterator = core::ContiguousIterator<const_pointer, BasicFixedString>

A const iterator.

◆ const_pointer

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::const_pointer = const value_type *

A const pointer to an character.

◆ const_reference

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::const_reference = const value_type &

A const reference to an character.

◆ const_reverse_iterator

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::const_reverse_iterator = std::reverse_iterator<const_iterator>

A const iterator for iterating in reverse order.

◆ difference_type

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::difference_type = std::ptrdiff_t

The type used for distances.

◆ iterator

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::iterator = core::ContiguousIterator<pointer, BasicFixedString>

An iterator.

◆ pointer

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::pointer = value_type *

A pointer to an character.

◆ reference

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::reference = value_type &

A reference to an character.

◆ reverse_iterator

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::reverse_iterator = std::reverse_iterator<iterator>

An iterator for iterating in reverse order.

◆ size_type

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::size_type = std::size_t

The type used for sizes.

◆ traits_type

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::traits_type = CharTraits

The character traits.

◆ value_type

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
using xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::value_type = Char

The character type.

Constructor & Destructor Documentation

◆ BasicFixedString() [1/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::BasicFixedString ( Char  character = 0)
constexprnoexcept

Constructor for a string filled with a specific character.

◆ BasicFixedString() [2/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::BasicFixedString ( UninitializedTag  tag)
constexprnoexcept

Constructor for a containing uninitialized characters.

This constructor constructs a string with unitialized string data. You should overwrite the data with valid characters before using the string.

Parameters
tagAlways pass kUninitialized as this parameter

Member Function Documentation

◆ at() [1/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::at ( size_type  index) -> reference
constexpr

Accesses the character at a certain index.

Parameters
indexThe index
Returns
A reference to the character at the given index
Exceptions
std::out_of_rangeindex is out of range

◆ at() [2/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::at ( size_type  index) const -> const_reference
constexpr

Accesses the character at a certain index.

Parameters
indexThe index
Returns
A reference to the character at the given index
Exceptions
std::out_of_rangeindex is out of range

◆ back() [1/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::back ( ) const -> const_reference
constexprnoexcept

Returns the last character.

Note
Must not be called on an empty string
Returns
A reference to last character

◆ back() [2/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::back ( ) -> reference
constexprnoexcept

Returns the last character.

Note
Must not be called on an empty string
Returns
A reference to last character

◆ begin() [1/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits >
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::begin ( ) const -> const_iterator
constexprnoexcept

Creates a begin iterator.

Returns
An iterator pointing at the first character, or end(), if the data is empty

◆ begin() [2/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits >
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::begin ( ) -> iterator
constexprnoexcept

Creates a begin iterator.

Returns
An iterator pointing at the first character, or end(), if the data is empty

◆ c_str()

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::c_str ( ) const -> const Char *
constexprnoexcept

Gets the data as a null terminated string.

Returns
The data as a null terminated string. The returned string will always be null terminated, even if the string data is still uninitialized. The uninitialized data may of course contain additional embedded null characters.

◆ capacity()

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::capacity ( ) const -> std::size_t
constexprnoexcept

Gets the capacity of the string.

Returns
The capacity, as defined by the kSize template parameter.

◆ cbegin()

template<tools::CharType Char, std::size_t kSize, typename CharTraits >
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::cbegin ( ) const -> const_iterator
constexprnoexcept

Creates a begin iterator.

Returns
An iterator pointing at the first character, or end(), if the data is empty

◆ cend()

template<tools::CharType Char, std::size_t kSize, typename CharTraits >
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::cend ( ) const -> const_iterator
constexprnoexcept

Creates an end iterator.

Returns
An iterator pointing at the position past the last character

◆ crbegin()

template<tools::CharType Char, std::size_t kSize, typename CharTraits >
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::crbegin ( ) const -> const_reverse_iterator
constexprnoexcept

Creates a reverse begin iterator.

Returns
A reverse iterator pointing at the last character, or rend(), if the data is empty

◆ crend()

template<tools::CharType Char, std::size_t kSize, typename CharTraits >
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::crend ( ) const -> const_reverse_iterator
constexprnoexcept

Creates a reverse end iterator.

Returns
A reverse iterator pointing at the position before the first character

◆ data() [1/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::data ( ) const -> const Char *
constexprnoexcept

Gets a pointer to the data.

Returns
A pointer to the data.

◆ data() [2/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::data ( ) -> Char *
constexprnoexcept

Gets a pointer to the data.

The returned pointer points to a buffer that has enough room for size() characters, plus a terminating null character. It is safe to write to the position after the last character, but only a null character way be written there, or the null termination will be lost.

Returns
A pointer to the data.

◆ empty()

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::empty ( ) const -> bool
constexprnoexcept

Determines whether the string is empty.

Since the string has a fixed size, this function will only return true for template instations with a kSize-parameter of 0.

Returns
Whether the string is empty

◆ end() [1/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits >
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::end ( ) const -> const_iterator
constexprnoexcept

Creates an end iterator.

Returns
An iterator pointing at the position past the last character

◆ end() [2/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits >
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::end ( ) -> iterator
constexprnoexcept

Creates an end iterator.

Returns
An iterator pointing at the position past the last character

◆ front() [1/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::front ( ) const -> const_reference
constexprnoexcept

Returns the first character.

Note
Must not be called on an empty string
Returns
A reference to first character

◆ front() [2/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::front ( ) -> reference
constexprnoexcept

Returns the first character.

Note
Must not be called on an empty string
Returns
A reference to first character

◆ max_size()

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
static constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::max_size ( ) -> std::size_t
staticconstexprnoexcept

Gets the maximum size.

Returns
The maximum size, as defined by the kSize template parameter.

◆ operator std::basic_string< Char, CharTraits, Allocator >()

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
template<typename Allocator >
constexpr xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::operator std::basic_string< Char, CharTraits, Allocator > ( ) const
constexprnoexcept

conversion to an std::string

Returns
A copy to the data

◆ operator std::basic_string_view< Char, CharTraits >()

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::operator std::basic_string_view< Char, CharTraits > ( ) const
constexprnoexcept

conversion to a string view

Returns
A view to the data

◆ operator[]() [1/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::operator[] ( size_type  index) const -> const_reference
constexprnoexcept

Subscript operator.

Returns a reference to the character at a certain index

Parameters
indexThe index
Returns
A reference to the value at the given offset

◆ operator[]() [2/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::operator[] ( size_type  index) -> reference
constexprnoexcept

Subscript operator.

Returns a reference to the character at a certain index

Parameters
indexThe index
Returns
A reference to the value at the given offset

◆ rbegin() [1/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits >
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::rbegin ( ) const -> const_reverse_iterator
constexprnoexcept

Creates a reverse begin iterator.

Returns
A reverse iterator pointing at the last character, or rend(), if the data is empty

◆ rbegin() [2/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits >
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::rbegin ( ) -> reverse_iterator
constexprnoexcept

Creates a reverse begin iterator.

Returns
A reverse iterator pointing at the last character, or rend(), if the data is empty

◆ rend() [1/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits >
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::rend ( ) const -> const_reverse_iterator
constexprnoexcept

Creates a reverse end iterator.

Returns
A reverse iterator pointing at the position before the first character

◆ rend() [2/2]

template<tools::CharType Char, std::size_t kSize, typename CharTraits >
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::rend ( ) -> reverse_iterator
constexprnoexcept

Creates a reverse end iterator.

Returns
A reverse iterator pointing at the position before the first character

◆ size()

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::size ( ) const -> std::size_t
constexprnoexcept

Gets the current size.

Returns
The curent size

◆ str()

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
template<typename Allocator = std::allocator<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::str ( const Allocator &  allocator = Allocator()) const -> std::basic_string<Char, CharTraits, Allocator>
constexprnoexcept

Gets the data as an std::string.

Returns
The data as a null terminated string.

◆ view()

template<tools::CharType Char, std::size_t kSize, typename CharTraits = std::char_traits<Char>>
constexpr auto xentara::utils::string::BasicFixedString< Char, kSize, CharTraits >::view ( ) const -> std::basic_string_view<Char, CharTraits>
constexprnoexcept

Gets the data as a string view.

Returns
The data as a string view.

Friends And Related Symbol Documentation

◆ operator()

template<typename Char , typename CharTraits , std::size_t kSize, std::size_t kCapacity>
auto operator<=> ( const BasicFixedString< Char, kSize, CharTraits > &  lhs,
const BasicStaticString< Char, kCapacity, CharTraits > &  rhs 
) -> auto
related

Comparison operator with a static string.

Note
This operator is necessary to avoid ambiguities resolving the comparison operator when comparing a BasicFixedString with a BasicStaticString.

◆ operator==()

template<typename Char , typename CharTraits , std::size_t kSize, std::size_t kCapacity>
auto operator== ( const BasicFixedString< Char, kSize, CharTraits > &  lhs,
const BasicStaticString< Char, kCapacity, CharTraits > &  rhs 
) -> bool
related

Comparison operator with a static string.

Note
This operator is necessary to avoid ambiguities resolving the comparison operator when comparing a BasicFixedString with a BasicStaticString.