Skip to main content

Class template basic_fixed_string

Defined in header <fixed_string.hpp>#
template<    typename TChar,     std::size_t N,     typename TTraits = std::char_traits<TChar>> struct basic_fixed_string;

The class template basic_fixed_string describes objects that can store a sequence consisting of a fixed number of arbitrary char-like objects with the first element of the sequence at position zero.

Several typedefs for common character types are provided:

TypeDefinition
fixstr::fixed_string<N>fixstr::basic_fixed_string<char, N>
fixstr::fixed_u8string<N>fixstr::basic_fixed_string<char8_t, N>since C++20
fixstr::fixed_u16string<N>fixstr::basic_fixed_string<char16_t, N>
fixstr::fixed_u32string<N>fixstr::basic_fixed_string<char32_t, N>
fixstr::fixed_wstring<N>fixstr::basic_fixed_string<wchar_t, N>
NOTE

In actual implementation, these are not the type aliases. Unfortunately, early GCC versions that are supported cNTTP couldn't automatically deduct size_t template parameter when an alias was used in cNTTP. So, the actual implementation is that every "typedef" is actually a separate class inherited from basic_fixed_string.

Template parameters#

NameDescription
TCharcharacter type
Nstring size
TTraitsCharTraits class specifying the operations on the character type. Like for std::basic_string or std::basic_string_view, TTraits::char_type must name the same type as TChar or the program is ill-formed.

Member types#

Member typeDefiniton
traits_typeTTraits
value_typeTChar
pointervalue_type*
const_pointerconst value_type*
referencevalue_type&
iteratorLegacyRandomAccessIterator to value_type
const_iteratorConstant LegacyRandomAccessIterator to value_type
reverse_iteratorstd::reverse_iterator<iterator>
const_reverse_iteratorstd::reverse_iterator<const_iterator>
size_typesize_t
difference_typeptrdiff_t
string_view_typestd::basic_string_view<value_type, traits_type>

Member functions#

Constructors and assignment#

NameDescription
(constructor)Constructs a basic_fixed_string
operator=assigns values to the string

Element access#

NameDescription
operator[]access specified element
ataccess specified element with bounds checking
frontaccesses the first character
backaccesses the last character
datareturns a pointer to the first character of a string
c_strreturns a non-modifiable standard C character array version of the string

Iterators#

NameDescription
begin
cbegin
returns an iterator to the beginning
end
cend
returns an iterator to the end
rbegin
crbegin
returns a reverse iterator to the beginning
rend
crend
returns a reverse iterator to the end

Capacity#

NameDescription
emptychecks whether the fixed string is empty
size
length
returns the number of characters
max_sizereturns the maximum number of characters

Operations#

NameDescription
substrreturns a substring
findfind characters in the fixed string