Boost C++ Libraries Home Libraries People FAQ More

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

const_pointer

const_reference

const_reverse_iterator

difference_type

iterator

pointer

reference

reverse_iterator

size_type

string_view_type

The type of string_view_type returned by the interface.

traits_type

value_type

Member Functions

Name

Description

append

Appends count copies of character ch

Append to the string.

assign

Replace the contents.

at

Access specified character with bounds checking.

back

Accesses the last character.

basic_static_string

Construct a basic_static_string.

begin

Returns an iterator to the beginning.

c_str

Returns a non-modifiable standard C character array version of the string.

capacity

Returns the number of characters that can be held in currently allocated storage.

cbegin

Returns an iterator to the beginning.

cend

Returns an iterator to the end.

clear

Clears the contents.

compare

Compare the string with another.

copy

Copy a substring to another string.

crbegin

Returns a reverse iterator to the beginning.

crend

Returns a reverse iterator to the end.

data

Returns a pointer to the first character of the string.

Returns a pointer to the first character of a string.

empty

Returns true if the string is empty.

end

Returns an iterator to the end.

ends_with

Returns whether the string ends with s

Returns whether the string ends with c

erase

Removes min(count, size() - index) characters starting at index

Removes the character at pos

Removes the characters in the range (first, last)

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_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.

front

Accesses the first character.

insert

Insert a character.

Insert a string.

Insert characters.

Insert a range of characters.

Insert characters from an initializer list.

Insert characters from an object convertible to string_view_type.

length

Returns the number of characters, excluding the null terminator.

max_size

Returns the maximum number of characters that can be stored, excluding the null terminator.

operator string_view_type

Convert a static string to a string_view_type

operator+=

Append to the string.

operator=

Assign to the string.

operator[]

Access specified character.

pop_back

Removes the last character from the string.

push_back

Appends the given character ch to the end of the string.

rbegin

Returns a reverse iterator to the beginning.

read_back

rend

Returns a reverse iterator to the end.

replace

Replace a substring with a string.

Replace a substring with a substring.

Replace a substring with an object convertible to string_view_type.

Replace a substring with a substring of an object convertible to string_view_type.

Replace a substring with copies of a character.

Replace a range with a string.

Replace a range with an object convertible to string_view_type.

Replace a range with copies of a character.

Replace a range with a range.

Replace a range with an initializer list.

reserve

Reserve space for n characters, excluding the null terminator.

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

Reduces memory usage by freeing unused memory.

size

Returns the number of characters, excluding the null terminator.

starts_with

Returns whether the string begins with s

Returns whether the string begins with c

substr

Return a substring.

subview

Return a view of a substring.

swap

Exchange the contents of this string with another.

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.

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 static_u8string is provided in C++20

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

to_static_string


PrevUpHomeNext