Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

PrevUpHomeNext

basic_static_string

A fixed-capacity string.

Synopsis

Defined in header <boost/static_string/static_string.hpp>

template<
    std::size_t N,
    typename CharT,
    typename Traits = std::char_traits<CharT>>
class basic_static_string
Types

Name

Description

const_iterator

The constant iterator type.

const_pointer

The constant pointer type.

const_reference

The constant reference type.

const_reverse_iterator

The constant reverse iterator type.

difference_type

The difference type.

iterator

The iterator type.

pointer

The pointer type.

reference

The reference type.

reverse_iterator

The reverse iterator type.

size_type

The size type.

string_view_type

The string view type.

traits_type

The traits type.

value_type

The character type.

Member Functions

Name

Description

append

Append to the string.

assign

Assign to the string.

at

Access a character with bounds checking.

back

Return the last character.

basic_static_string

Constructor.

begin

Return an iterator to the beginning.

c_str

Return a pointer to the string.

capacity

Return the number of characters that can be stored.

cbegin

Return an iterator to the beginning.

cend

Return an iterator to the end.

clear

Clear the contents.

compare

Compare a string with the string.

copy

Copy a substring to another string.

crbegin

Return a reverse iterator to the beginning.

crend

Return a reverse iterator to the end.

data

Return a pointer to the string.

empty

Return if the string is empty.

end

Return an iterator to the end.

ends_with

Return whether the string ends with a string.

Return whether the string ends with a character.

erase

Erase from the string.

find

Find the first occurrence of a string within the string.

Find the first occurrence of a character within the string.

find_first_not_of

Find the first occurrence of a character not within the string.

Find the first occurrence of any of the characters not within the string.

Find the first occurrence of a character not equal to c.

find_first_of

Find the first occurrence of any of the characters within the string.

Find the first occurrence of a character within the string.

find_last_not_of

Find the last occurrence of a character not within the string.

Find the last occurrence of a character not equal to c.

find_last_of

Find the last occurrence of any of the characters within the string.

Find the last occurrence of a character within the string.

front

Return the first character.

insert

Insert into the string.

length

Return the size of the string.

max_size

Return the number of characters that can be stored.

operator string_view_type

Convert to a string view referring to the string.

operator+=

Append to the string.

operator=

Assign to the string.

operator[]

Access a character.

pop_back

Remove the last character.

push_back

Append a character.

rbegin

Return a reverse iterator to the beginning.

rend

Return a reverse iterator to the end.

replace

Replace a part of the string.

reserve

Increase the capacity.

resize

Change the size of the string.

rfind

Find the last occurrence of a string within the string.

Find the last occurrence of a character within the string.

shrink_to_fit

Request the removal of unused capacity.

size

Return the size of the string.

starts_with

Return whether the string begins with a string.

Return whether the string begins with a character.

substr

Return a substring.

subview

Return a string view of a substring.

swap

Swap two strings.

Data Members

Name

Description

npos

A special index.

static_capacity

Maximum size of the string excluding any null terminator.

Description

These objects behave like std::string except that the storage is not dynamically allocated but rather fixed in size, and stored in the object itself. These strings offer performance advantages when an algorithm can execute with a reasonable upper limit on the size of a value.

Aliases

The following alias templates are provided for convenience:

template<std::size_t N>
using static_string =
  basic_static_string<N, char, std::char_traits<char>>;
template<std::size_t N>
using static_wstring =
  basic_static_string<N, wchar_t, std::char_traits<wchar_t>>;
template<std::size_t N>
using static_u16string =
  basic_static_string<N, char16_t, std::char_traits<char16_t>>;
template<std::size_t N>
using static_u32string =
  basic_static_string<N, char32_t, std::char_traits<char32_t>>;

Addtionally, the alias template static_u8string is provided in C++20

template<std::size_t N>
using static_u8string =
  basic_static_string<N, char8_t, std::char_traits<char8_t>>;
See Also

to_static_string


PrevUpHomeNext