gw  1.0.0
A bunch of small C++ utilities
Loading...
Searching...
No Matches
gw::basic_inplace_string< N, CharT, Traits > Class Template Reference

A fixed-size string that stores the data in-place. More...

#include <inplace_string.hpp>

Collaboration diagram for gw::basic_inplace_string< N, CharT, Traits >:
[legend]

Public Types

using traits_type = Traits
 The character traits type.
 
using value_type = CharT
 The character type.
 
using size_type = std::size_t
 The size type.
 
using difference_type = std::ptrdiff_t
 The difference type.
 
using reference = value_type &
 The reference type.
 
using const_reference = const value_type &
 The const reference type.
 
using pointer = value_type *
 The pointer type.
 
using const_pointer = const value_type *
 The const pointer type.
 
using iterator = value_type *
 The iterator type.
 
using const_iterator = const value_type *
 The const iterator type.
 
using reverse_iterator = std::reverse_iterator< iterator >
 The reverse iterator type.
 
using const_reverse_iterator = std::reverse_iterator< const_iterator >
 The const reverse iterator type.
 

Public Member Functions

constexpr basic_inplace_string () noexcept=default
 Default constructor.
 
template<std::size_t N2>
requires (N2 <= N + 1)
consteval explicit (false) basic_inplace_string(const value_type(&str)[N2]) noexcept
 Construct the string with the characters from the character string pointed to by str.
 
constexpr basic_inplace_string (size_type count, value_type ch)
 Construct the string with count copies of character ch.
 
constexpr basic_inplace_string (const value_type *str)
 Construct the string with the characters from the character string pointed to by str.
 
constexpr basic_inplace_string (const value_type *str, size_type count)
 Construct the string with the contents of the range [str, str + count).
 
template<std::input_iterator InputIt>
constexpr basic_inplace_string (InputIt first, InputIt last)
 Construct the string with the contents of the range [first, last).
 
constexpr basic_inplace_string (const std::basic_string_view< value_type, traits_type > &str)
 Construct the string with the contents of the string view.
 
template<std::ranges::range R>
requires (!std::is_convertible_v<const R&, std::basic_string_view<value_type, traits_type>> && std::convertible_to<std::ranges::range_value_t<R>, value_type>)
constexpr basic_inplace_string (const R &range)
 Construct the string with the contents of the range.
 
constexpr basic_inplace_string (const basic_inplace_string &other) noexcept=default
 Copy constructor.
 
constexpr basic_inplace_string (basic_inplace_string &&other) noexcept=default
 Move constructor.
 
constexpr ~basic_inplace_string () noexcept=default
 Destructor.
 
constexpr auto operator= (const basic_inplace_string &other) noexcept -> basic_inplace_string &=default
 Copy assignment operator.
 
constexpr auto operator= (basic_inplace_string &&other) noexcept -> basic_inplace_string &=default
 Move assignment operator.
 
constexpr auto at (size_type pos) -> reference
 Get a reference to the character at the specified position.
 
constexpr auto at (size_type pos) const -> const_reference
 Get a const reference to the character at the specified position.
 
constexpr auto operator[] (size_type pos) noexcept -> reference
 Get a reference to the character at the specified position.
 
constexpr auto operator[] (size_type pos) const noexcept -> const_reference
 Get a const reference to the character at the specified position.
 
constexpr auto front () noexcept -> reference
 Get a reference to the first character in the string.
 
constexpr auto front () const noexcept -> const_reference
 Get a const reference to the first character in the string.
 
constexpr auto back () noexcept -> reference
 Get a reference to the last character in the string.
 
constexpr auto back () const noexcept -> const_reference
 Get a const reference to the last character in the string.
 
constexpr auto data () noexcept -> pointer
 Get a pointer to the underlying character array.
 
constexpr auto data () const noexcept -> const_pointer
 Get a const pointer to the underlying character array.
 
constexpr auto c_str () const noexcept -> const_pointer
 Get a const pointer to the underlying character array.
 
constexpr operator std::basic_string_view< value_type, traits_type > () const noexcept
 Get a string view of the string.
 
constexpr auto view () const noexcept -> std::basic_string_view< value_type, traits_type >
 Get a string view of the string.
 
constexpr auto begin () noexcept -> iterator
 Get an iterator to the beginning of the string.
 
constexpr auto begin () const noexcept -> const_iterator
 Get a const iterator to the beginning of the string.
 
constexpr auto cbegin () const noexcept -> const_iterator
 Get a const iterator to the beginning of the string.
 
constexpr auto end () noexcept -> iterator
 Get an iterator to the end of the string.
 
constexpr auto end () const noexcept -> const_iterator
 Get a const iterator to the end of the string.
 
constexpr auto cend () const noexcept -> const_iterator
 Get a const iterator to the end of the string.
 
constexpr auto rbegin () noexcept -> reverse_iterator
 Get a reverse iterator to the end of the string.
 
constexpr auto rbegin () const noexcept -> const_reverse_iterator
 Get a const reverse iterator to the end of the string.
 
constexpr auto crbegin () const noexcept -> const_reverse_iterator
 Get a const reverse iterator to the end of the string.
 
constexpr auto rend () noexcept -> reverse_iterator
 Get a reverse iterator to the beginning of the string.
 
constexpr auto rend () const noexcept -> const_reverse_iterator
 Get a const reverse iterator to the beginning of the string.
 
constexpr auto crend () const noexcept -> const_reverse_iterator
 Get a const reverse iterator to the beginning of the string.
 
constexpr auto empty () const noexcept -> bool
 Check if the string is empty.
 
constexpr auto size () const noexcept -> size_type
 Get the size of the string.
 
constexpr auto length () const noexcept -> size_type
 Get the length of the string.
 
constexpr auto max_size () const noexcept -> size_type
 Get the maximum size of the string.
 
constexpr void reserve (size_type new_cap)
 Reserve storage for the string.
 
constexpr auto capacity () const noexcept -> size_type
 Get the capacity of the string.
 
constexpr void shrink_to_fit ()
 Shrink the capacity of the string to fit its size.
 
constexpr void clear () noexcept
 Clear the contents of the string.
 
constexpr void insert (size_type index, size_type count, CharT ch)
 Insert count copies of character ch at the position index.
 
auto insert (size_type index, const value_type *str) -> basic_inplace_string &
 Insert the null-terminated character string pointed to by str at the position index.
 
auto insert (size_type index, const value_type *str, size_type count) -> basic_inplace_string &
 Insert the characters in the range [str, str + count) at the position index.
 
template<std::size_t N2>
auto insert (size_type index, const basic_inplace_string< N2, value_type, traits_type > &str) -> basic_inplace_string &
 Insert the inplace string at the position index.
 
auto insert (const_iterator pos, value_type ch) -> iterator
 Insert the character ch before the element (if any) pointed by pos.
 
auto insert (const_iterator pos, size_type count, value_type ch) -> iterator
 Insert count copies of character ch before the element (if any) pointed by pos.
 
template<std::input_iterator InputIt>
requires std::convertible_to<std::iter_value_t<InputIt>, value_type>
auto insert (const_iterator pos, InputIt first, InputIt last) -> iterator
 Insert the characters from the range [first, last) before the element (if any) pointed by pos.
 
template<std::ranges::input_range R>
requires std::convertible_to<std::ranges::range_value_t<R>, value_type>
constexpr auto insert_range (const_iterator pos, R &&range) -> iterator
 Insert the characters from the range before the element (if any) pointed by pos.
 
constexpr void erase (size_type index=0U, size_type count=npos)
 Erase count characters from the position index.
 
constexpr void push_back (value_type ch)
 Append a character to the end of the string.
 
constexpr void pop_back () noexcept
 Remove the last character from the string.
 
template<std::size_t N2>
constexpr void append (const basic_inplace_string< N2, value_type, traits_type > &str)
 Append a string to the end of the string.
 
constexpr void resize (size_type count)
 Resize the string to count characters.
 
constexpr void resize (size_type count, value_type ch)
 Resize the string to count characters.
 
constexpr void swap (basic_inplace_string &other) noexcept
 Swap the string with another string.
 
template<std::size_t N2>
constexpr auto find (const basic_inplace_string< N2, value_type, traits_type > &str, size_type pos=0) const noexcept -> size_type
 Find the first substring equal to str.
 
constexpr auto find (std::basic_string_view< value_type, traits_type > str, size_type pos=0) const noexcept -> size_type
 Find the first substring equal to str.
 
constexpr auto find (const value_type *str, size_type pos, size_type count) const noexcept -> size_type
 Find the first substring equal to the range [str, str + count).
 
constexpr auto find (const value_type *str, size_type pos=0) const noexcept -> size_type
 Find the first substring equal to the character string pointed to by str.
 
constexpr auto find (value_type ch, size_type pos=0) const noexcept -> size_type
 Find the first character ch.
 
template<std::size_t N2>
constexpr auto rfind (const basic_inplace_string< N2, value_type, traits_type > &str, size_type pos=npos) const noexcept -> size_type
 Find the last substring equal to str.
 
constexpr auto rfind (std::basic_string_view< value_type, traits_type > str, size_type pos=npos) const noexcept -> size_type
 Find the last substring equal to str.
 
constexpr auto rfind (const value_type *str, size_type pos, size_type count) const noexcept -> size_type
 Find the last substring equal to the range [str, str + count).
 
constexpr auto rfind (const value_type *str, size_type pos=npos) const noexcept -> size_type
 Find the last substring equal to the character string pointed to by str.
 
constexpr auto rfind (value_type ch, size_type pos=npos) const noexcept -> size_type
 Find the last character ch.
 
template<std::size_t N2>
constexpr auto find_first_of (const basic_inplace_string< N2, value_type, traits_type > &str, size_type pos=0) const noexcept -> size_type
 Find the first character equal to one of the characters in str.
 
constexpr auto find_first_of (std::basic_string_view< value_type, traits_type > str, size_type pos=0) const noexcept -> size_type
 Find the first character equal to one of the characters in str.
 
constexpr auto find_first_of (const value_type *str, size_type pos=0) const noexcept -> size_type
 Find the first character equal to one of the characters in str.
 

Public Attributes

std::array< value_type, N+1Um_data
 The character array.
 

Static Public Attributes

static constexpr size_type npos = -1
 The maximum value for size_type.
 

Friends

template<std::size_t N2>
constexpr auto operator+ (const basic_inplace_string &lhs, const basic_inplace_string< N2, value_type, traits_type > &rhs) -> basic_inplace_string< N+N2, value_type, traits_type >
 Concatenate two strings.
 
constexpr auto operator== (const basic_inplace_string &lhs, const basic_inplace_string &rhs) noexcept -> bool
 Compare the string to another string.
 
constexpr auto operator== (const basic_inplace_string &lhs, std::basic_string_view< value_type, traits_type > rhs) noexcept -> bool
 Compare the string to a string view.
 
constexpr auto operator== (std::basic_string_view< value_type, traits_type > lhs, const basic_inplace_string &rhs) noexcept -> bool
 Compare the string to a string view.
 
constexpr auto operator== (const basic_inplace_string &lhs, const value_type *rhs) noexcept -> bool
 Compares the string to a character string.
 
constexpr auto operator== (const value_type *lhs, const basic_inplace_string &rhs) noexcept -> bool
 Compares the string to a character string.
 
auto operator<< (std::basic_ostream< value_type, traits_type > &ostream, const basic_inplace_string &rhs) -> std::basic_ostream< value_type, traits_type > &
 Write the string to an output stream.
 
auto operator>> (std::basic_istream< value_type, traits_type > &istream, basic_inplace_string &rhs) -> std::basic_istream< value_type, traits_type > &
 Read the string from an input stream.
 

Detailed Description

template<std::size_t N, class CharT, class Traits = std::char_traits<CharT>>
class gw::basic_inplace_string< N, CharT, Traits >

A fixed-size string that stores the data in-place.

Template Parameters
NThe size of the string.
CharTThe character type.
TraitsThe character traits type.
Examples
inplace_string_example.cpp.

Constructor & Destructor Documentation

◆ basic_inplace_string() [1/6]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr gw::basic_inplace_string< N, CharT, Traits >::basic_inplace_string ( size_type  count,
value_type  ch 
)
inlineconstexpr

Construct the string with count copies of character ch.

Parameters
countThe number of characters to initialize the string with.
chThe character to initialize the string with.
Exceptions
std::length_errorIf count is greater than max_size.

◆ basic_inplace_string() [2/6]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr gw::basic_inplace_string< N, CharT, Traits >::basic_inplace_string ( const value_type str)
inlineexplicitconstexpr

Construct the string with the characters from the character string pointed to by str.

Parameters
strThe character string to initialize the string with.
Exceptions
std::length_errorIf the size of str would exceed max_size.

◆ basic_inplace_string() [3/6]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr gw::basic_inplace_string< N, CharT, Traits >::basic_inplace_string ( const value_type str,
size_type  count 
)
inlineexplicitconstexpr

Construct the string with the contents of the range [str, str + count).

Parameters
strThe beginning of the range.
countThe number of characters to initialize the string with.
Exceptions
std::length_errorIf count is greater than max_size.

◆ basic_inplace_string() [4/6]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
template<std::input_iterator InputIt>
constexpr gw::basic_inplace_string< N, CharT, Traits >::basic_inplace_string ( InputIt  first,
InputIt  last 
)
inlineexplicitconstexpr

Construct the string with the contents of the range [first, last).

Template Parameters
InputItThe type of the iterators.
Parameters
firstThe beginning of the range.
lastThe end of the range.
Exceptions
std::length_errorIf the size of the range would exceed max_size.

◆ basic_inplace_string() [5/6]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr gw::basic_inplace_string< N, CharT, Traits >::basic_inplace_string ( const std::basic_string_view< value_type, traits_type > &  str)
inlineexplicitconstexpr

Construct the string with the contents of the string view.

Parameters
strThe string view to initialize the string with.
Exceptions
std::length_errorIf the size of the string view would exceed max_size.

◆ basic_inplace_string() [6/6]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
template<std::ranges::range R>
requires (!std::is_convertible_v<const R&, std::basic_string_view<value_type, traits_type>> && std::convertible_to<std::ranges::range_value_t<R>, value_type>)
constexpr gw::basic_inplace_string< N, CharT, Traits >::basic_inplace_string ( const R range)
inlineexplicitconstexpr

Construct the string with the contents of the range.

Template Parameters
RThe type of the range.
Parameters
rangeThe range to initialize the string with.

Member Function Documentation

◆ append()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
template<std::size_t N2>
constexpr void gw::basic_inplace_string< N, CharT, Traits >::append ( const basic_inplace_string< N2, value_type, traits_type > &  str)
inlineconstexpr

Append a string to the end of the string.

Template Parameters
N2The size of the string.
Parameters
strThe string to append.
Exceptions
std::length_errorIf the size of the string would exceed max_size.

◆ at() [1/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::at ( size_type  pos) -> reference
inlineconstexpr

Get a reference to the character at the specified position.

Parameters
posThe position of the character to get.
Returns
A reference to the character at the specified position.
Exceptions
std::out_of_rangeIf pos is out of range.

◆ at() [2/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::at ( size_type  pos) const -> const_reference
inlineconstexpr

Get a const reference to the character at the specified position.

Parameters
posThe position of the character to get.
Returns
A const reference to the character at the specified position.
Exceptions
std::out_of_rangeIf pos is out of range.

◆ back() [1/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::back ( ) const -> const_reference
inlineconstexprnoexcept

Get a const reference to the last character in the string.

Returns
A const reference to the last character in the string.

◆ back() [2/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::back ( ) -> reference
inlineconstexprnoexcept

Get a reference to the last character in the string.

Returns
A reference to the last character in the string.

◆ begin() [1/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::begin ( ) const -> const_iterator
inlineconstexprnoexcept

Get a const iterator to the beginning of the string.

Returns
A const iterator to the beginning of the string.

◆ begin() [2/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::begin ( ) -> iterator
inlineconstexprnoexcept

Get an iterator to the beginning of the string.

Returns
An iterator to the beginning of the string.

◆ c_str()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::c_str ( ) const -> const_pointer
inlineconstexprnoexcept

Get a const pointer to the underlying character array.

Returns
A const pointer to the underlying character array.

◆ capacity()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::capacity ( ) const -> size_type
inlineconstexprnoexcept

Get the capacity of the string.

Returns
The capacity of the string.

◆ cbegin()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::cbegin ( ) const -> const_iterator
inlineconstexprnoexcept

Get a const iterator to the beginning of the string.

Returns
A const iterator to the beginning of the string.

◆ cend()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::cend ( ) const -> const_iterator
inlineconstexprnoexcept

Get a const iterator to the end of the string.

Returns
A const iterator to the end of the string.

◆ crbegin()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::crbegin ( ) const -> const_reverse_iterator
inlineconstexprnoexcept

Get a const reverse iterator to the end of the string.

Returns
A const reverse iterator to the end of the string.

◆ crend()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::crend ( ) const -> const_reverse_iterator
inlineconstexprnoexcept

Get a const reverse iterator to the beginning of the string.

Returns
A const reverse iterator to the beginning of the string.

◆ data() [1/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::data ( ) const -> const_pointer
inlineconstexprnoexcept

Get a const pointer to the underlying character array.

Returns
A const pointer to the underlying character array.

◆ data() [2/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::data ( ) -> pointer
inlineconstexprnoexcept

Get a pointer to the underlying character array.

Returns
A pointer to the underlying character array.

◆ empty()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::empty ( ) const -> bool
inlineconstexprnoexcept

Check if the string is empty.

Returns
True if the string is empty, false otherwise.

◆ end() [1/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::end ( ) const -> const_iterator
inlineconstexprnoexcept

Get a const iterator to the end of the string.

Returns
A const iterator to the end of the string.

◆ end() [2/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::end ( ) -> iterator
inlineconstexprnoexcept

Get an iterator to the end of the string.

Returns
An iterator to the end of the string.

◆ erase()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr void gw::basic_inplace_string< N, CharT, Traits >::erase ( size_type  index = 0U,
size_type  count = npos 
)
inlineconstexpr

Erase count characters from the position index.

Parameters
indexThe position to erase the characters from.
countThe number of characters to erase.
Exceptions
std::out_of_rangeIf index is greater than or equal to the size of the string.

◆ find() [1/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
template<std::size_t N2>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::find ( const basic_inplace_string< N2, value_type, traits_type > &  str,
size_type  pos = 0 
) const -> size_type
inlineconstexprnoexcept

Find the first substring equal to str.

Template Parameters
N2The size of the string.
Parameters
strThe string to find.
posThe position to start searching from.
Returns
The position of the first occurrence of the string, or npos if the string is not found.

◆ find() [2/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::find ( const value_type str,
size_type  pos,
size_type  count 
) const -> size_type
inlineconstexprnoexcept

Find the first substring equal to the range [str, str + count).

Parameters
strThe string to find.
posThe position to start searching from.
countThe number of characters to search for.
Returns
The position of the first occurrence of the string, or npos if the string is not found.

◆ find() [3/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::find ( const value_type str,
size_type  pos = 0 
) const -> size_type
inlineconstexprnoexcept

Find the first substring equal to the character string pointed to by str.

Parameters
strThe string to find.
posThe position to start searching from.
Returns
The position of the first occurrence of the string, or npos if the string is not found.

◆ find() [4/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::find ( std::basic_string_view< value_type, traits_type str,
size_type  pos = 0 
) const -> size_type
inlineconstexprnoexcept

Find the first substring equal to str.

Parameters
strThe string view to find.
posThe position to start searching from.
Returns
The position of the first occurrence of the string, or npos if the string is not found.

◆ find() [5/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::find ( value_type  ch,
size_type  pos = 0 
) const -> size_type
inlineconstexprnoexcept

Find the first character ch.

Parameters
chThe character to find.
posThe position to start searching from.
Returns
The position of the first occurrence of the character, or npos if the character is not found.

◆ find_first_of() [1/3]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
template<std::size_t N2>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::find_first_of ( const basic_inplace_string< N2, value_type, traits_type > &  str,
size_type  pos = 0 
) const -> size_type
inlineconstexprnoexcept

Find the first character equal to one of the characters in str.

Template Parameters
N2The size of the string.
Parameters
strThe string to search for.
posThe position to start searching from.
Returns
The position of the first occurrence of any character in the string, or npos if no character is found.

◆ find_first_of() [2/3]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::find_first_of ( const value_type str,
size_type  pos = 0 
) const -> size_type
inlineconstexprnoexcept

Find the first character equal to one of the characters in str.

Parameters
strThe character string to search for.
posThe position to start searching from.
Returns
The position of the first occurrence of any character in the string, or npos if no character is found.

◆ find_first_of() [3/3]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::find_first_of ( std::basic_string_view< value_type, traits_type str,
size_type  pos = 0 
) const -> size_type
inlineconstexprnoexcept

Find the first character equal to one of the characters in str.

Parameters
strThe string view to search for.
posThe position to start searching from.
Returns
The position of the first occurrence of any character in the string, or npos if no character is found.

◆ front() [1/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::front ( ) const -> const_reference
inlineconstexprnoexcept

Get a const reference to the first character in the string.

Returns
A const reference to the first character in the string.

◆ front() [2/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::front ( ) -> reference
inlineconstexprnoexcept

Get a reference to the first character in the string.

Returns
A reference to the first character in the string.

◆ insert() [1/7]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
template<std::input_iterator InputIt>
requires std::convertible_to<std::iter_value_t<InputIt>, value_type>
auto gw::basic_inplace_string< N, CharT, Traits >::insert ( const_iterator  pos,
InputIt  first,
InputIt  last 
) -> iterator
inline

Insert the characters from the range [first, last) before the element (if any) pointed by pos.

Template Parameters
InputItThe type of the iterators.
Parameters
posThe position to insert the characters before.
firstThe beginning of the range.
lastThe end of the range.
Returns
An iterator to the first inserted character or pos if no characters were inserted.
Exceptions
std::length_errorIf the size of the string would exceed max_size.

◆ insert() [2/7]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
auto gw::basic_inplace_string< N, CharT, Traits >::insert ( const_iterator  pos,
size_type  count,
value_type  ch 
) -> iterator
inline

Insert count copies of character ch before the element (if any) pointed by pos.

Parameters
posThe position to insert the characters before.
countThe number of characters to insert.
chThe character to insert.
Returns
An iterator to the first inserted character.

◆ insert() [3/7]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
auto gw::basic_inplace_string< N, CharT, Traits >::insert ( const_iterator  pos,
value_type  ch 
) -> iterator
inline

Insert the character ch before the element (if any) pointed by pos.

Parameters
posThe position to insert the characters before.
chThe character to insert.
Returns
An iterator to the first inserted character.

◆ insert() [4/7]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
template<std::size_t N2>
auto gw::basic_inplace_string< N, CharT, Traits >::insert ( size_type  index,
const basic_inplace_string< N2, value_type, traits_type > &  str 
) -> basic_inplace_string&
inline

Insert the inplace string at the position index.

Template Parameters
N2The size of the string.
Parameters
indexThe position to insert the characters at.
strThe string to insert.
Returns
A reference to the string.
Exceptions
std::length_errorIf the size of the string would exceed max_size.

◆ insert() [5/7]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
auto gw::basic_inplace_string< N, CharT, Traits >::insert ( size_type  index,
const value_type str 
) -> basic_inplace_string&
inline

Insert the null-terminated character string pointed to by str at the position index.

Parameters
indexThe position to insert the characters at.
strThe character string to insert.
Returns
A reference to the string.
Exceptions
std::length_errorIf the size of the string would exceed max_size.

◆ insert() [6/7]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
auto gw::basic_inplace_string< N, CharT, Traits >::insert ( size_type  index,
const value_type str,
size_type  count 
) -> basic_inplace_string&
inline

Insert the characters in the range [str, str + count) at the position index.

Parameters
indexThe position to insert the characters at.
strThe character string to insert.
countThe number of characters to insert.
Returns
A reference to the string.
Exceptions
std::length_errorIf the size of the string would exceed max_size.

◆ insert() [7/7]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr void gw::basic_inplace_string< N, CharT, Traits >::insert ( size_type  index,
size_type  count,
CharT  ch 
)
inlineconstexpr

Insert count copies of character ch at the position index.

Parameters
indexThe position to insert the characters at.
countThe number of characters to insert.
chThe character to insert.
Exceptions
std::length_errorIf the size of the string would exceed max_size.

◆ insert_range()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
template<std::ranges::input_range R>
requires std::convertible_to<std::ranges::range_value_t<R>, value_type>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::insert_range ( const_iterator  pos,
R &&  range 
) -> iterator
inlineconstexpr

Insert the characters from the range before the element (if any) pointed by pos.

Template Parameters
RThe type of the range.
Parameters
posThe position to insert the characters before.
rangeThe range to insert.
Returns
An iterator to the first inserted character or pos if no characters were inserted.
Exceptions
std::length_errorIf the size of the string would exceed max_size.

◆ length()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::length ( ) const -> size_type
inlineconstexprnoexcept

Get the length of the string.

Returns
The length of the string.

◆ max_size()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::max_size ( ) const -> size_type
inlineconstexprnoexcept

Get the maximum size of the string.

Returns
The maximum size of the string.

◆ operator std::basic_string_view< value_type, traits_type >()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr gw::basic_inplace_string< N, CharT, Traits >::operator std::basic_string_view< value_type, traits_type > ( ) const
inlineexplicitconstexprnoexcept

Get a string view of the string.

Returns
A string view of the string.

◆ operator[]() [1/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::operator[] ( size_type  pos) const -> const_reference
inlineconstexprnoexcept

Get a const reference to the character at the specified position.

Parameters
posThe position of the character to get.
Returns
A const reference to the character at the specified position.

◆ operator[]() [2/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::operator[] ( size_type  pos) -> reference
inlineconstexprnoexcept

Get a reference to the character at the specified position.

Parameters
posThe position of the character to get.
Returns
A reference to the character at the specified position.

◆ push_back()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr void gw::basic_inplace_string< N, CharT, Traits >::push_back ( value_type  ch)
inlineconstexpr

Append a character to the end of the string.

Parameters
chThe character to append.
Exceptions
std::length_errorIf the size of the string would exceed max_size.

◆ rbegin() [1/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::rbegin ( ) const -> const_reverse_iterator
inlineconstexprnoexcept

Get a const reverse iterator to the end of the string.

Returns
A const reverse iterator to the end of the string.

◆ rbegin() [2/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::rbegin ( ) -> reverse_iterator
inlineconstexprnoexcept

Get a reverse iterator to the end of the string.

Returns
A reverse iterator to the end of the string.

◆ rend() [1/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::rend ( ) const -> const_reverse_iterator
inlineconstexprnoexcept

Get a const reverse iterator to the beginning of the string.

Returns
A const reverse iterator to the beginning of the string.

◆ rend() [2/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::rend ( ) -> reverse_iterator
inlineconstexprnoexcept

Get a reverse iterator to the beginning of the string.

Returns
A reverse iterator to the beginning of the string.

◆ reserve()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr void gw::basic_inplace_string< N, CharT, Traits >::reserve ( size_type  new_cap)
inlineconstexpr

Reserve storage for the string.

Parameters
new_capThe new capacity of the string.
Exceptions
std::length_errorIf new_cap is greater than max_size.
Note
This function does nothing.

◆ resize() [1/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr void gw::basic_inplace_string< N, CharT, Traits >::resize ( size_type  count)
inlineconstexpr

Resize the string to count characters.

Parameters
countThe new size of the string.
Exceptions
std::length_errorIf count is greater than max_size.

◆ resize() [2/2]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr void gw::basic_inplace_string< N, CharT, Traits >::resize ( size_type  count,
value_type  ch 
)
inlineconstexpr

Resize the string to count characters.

Parameters
countThe new size of the string.
chThe character to fill the string with.
Exceptions
std::length_errorIf count is greater than max_size.

◆ rfind() [1/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
template<std::size_t N2>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::rfind ( const basic_inplace_string< N2, value_type, traits_type > &  str,
size_type  pos = npos 
) const -> size_type
inlineconstexprnoexcept

Find the last substring equal to str.

Template Parameters
N2The size of the string.
Parameters
strThe string to find.
posThe position to start searching from.
Returns
The position of the last occurrence of the string, or npos if the string is not found.

◆ rfind() [2/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::rfind ( const value_type str,
size_type  pos,
size_type  count 
) const -> size_type
inlineconstexprnoexcept

Find the last substring equal to the range [str, str + count).

Parameters
strThe string to find.
posThe position to start searching from.
countThe number of characters to search for.
Returns
The position of the last occurrence of the string, or npos if the string is not found.

◆ rfind() [3/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::rfind ( const value_type str,
size_type  pos = npos 
) const -> size_type
inlineconstexprnoexcept

Find the last substring equal to the character string pointed to by str.

Parameters
strThe string to find.
posThe position to start searching from.
Returns
The position of the last occurrence of the string, or npos if the string is not found.

◆ rfind() [4/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::rfind ( std::basic_string_view< value_type, traits_type str,
size_type  pos = npos 
) const -> size_type
inlineconstexprnoexcept

Find the last substring equal to str.

Parameters
strThe string to find.
posThe position to start searching from.
Returns
The position of the last occurrence of the string, or npos if the string is not found.

◆ rfind() [5/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::rfind ( value_type  ch,
size_type  pos = npos 
) const -> size_type
inlineconstexprnoexcept

Find the last character ch.

Parameters
chThe character to find.
posThe position to start searching from.
Returns
The position of the last occurrence of the character, or npos if the character is not found.

◆ shrink_to_fit()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr void gw::basic_inplace_string< N, CharT, Traits >::shrink_to_fit ( )
inlineconstexpr

Shrink the capacity of the string to fit its size.

Note
This function does nothing.

◆ size()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::size ( ) const -> size_type
inlineconstexprnoexcept

Get the size of the string.

Returns
The size of the string.

◆ swap()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr void gw::basic_inplace_string< N, CharT, Traits >::swap ( basic_inplace_string< N, CharT, Traits > &  other)
inlineconstexprnoexcept

Swap the string with another string.

Parameters
otherThe string to swap with.

◆ view()

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto gw::basic_inplace_string< N, CharT, Traits >::view ( ) const -> std::basic_string_view<value_type, traits_type>
inlineconstexprnoexcept

Get a string view of the string.

Returns
A string view of the string.

Friends And Related Symbol Documentation

◆ operator+

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
template<std::size_t N2>
constexpr auto operator+ ( const basic_inplace_string< N, CharT, Traits > &  lhs,
const basic_inplace_string< N2, value_type, traits_type > &  rhs 
) -> basic_inplace_string<N + N2, value_type, traits_type>
friend

Concatenate two strings.

Template Parameters
N2The size of the second string.
Parameters
lhsThe first string to concatenate.
rhsThe second string to concatenate.
Returns
The concatenated string.

◆ operator<<

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
auto operator<< ( std::basic_ostream< value_type, traits_type > &  ostream,
const basic_inplace_string< N, CharT, Traits > &  rhs 
) -> std::basic_ostream<value_type, traits_type>&
friend

Write the string to an output stream.

Parameters
ostreamThe output stream to write to.
rhsThe string to write.
Returns
The output stream.

◆ operator== [1/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto operator== ( const basic_inplace_string< N, CharT, Traits > &  lhs,
const basic_inplace_string< N, CharT, Traits > &  rhs 
) -> bool
friend

Compare the string to another string.

Parameters
lhsThe first string to compare.
rhsThe second string to compare.
Returns
True if the strings are equal, false otherwise.

◆ operator== [2/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto operator== ( const basic_inplace_string< N, CharT, Traits > &  lhs,
const value_type rhs 
) -> bool
friend

Compares the string to a character string.

Parameters
lhsThe first string to compare.
rhsThe second string to compare.
Returns
True if the strings are equal, false otherwise.

◆ operator== [3/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto operator== ( const basic_inplace_string< N, CharT, Traits > &  lhs,
std::basic_string_view< value_type, traits_type rhs 
) -> bool
friend

Compare the string to a string view.

Parameters
lhsThe first string to compare.
rhsThe second string to compare.
Returns
True if the strings are equal, false otherwise.

◆ operator== [4/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto operator== ( const value_type lhs,
const basic_inplace_string< N, CharT, Traits > &  rhs 
) -> bool
friend

Compares the string to a character string.

Parameters
lhsThe first string to compare.
rhsThe second string to compare.
Returns
True if the strings are equal, false otherwise.

◆ operator== [5/5]

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
constexpr auto operator== ( std::basic_string_view< value_type, traits_type lhs,
const basic_inplace_string< N, CharT, Traits > &  rhs 
) -> bool
friend

Compare the string to a string view.

Parameters
lhsThe first string to compare.
rhsThe second string to compare.
Returns
True if the strings are equal, false otherwise.

◆ operator>>

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
auto operator>> ( std::basic_istream< value_type, traits_type > &  istream,
basic_inplace_string< N, CharT, Traits > &  rhs 
) -> std::basic_istream<value_type, traits_type>&
friend

Read the string from an input stream.

Parameters
istreamThe input stream to read from.
rhsThe string to read into.
Returns
The input stream.

Member Data Documentation

◆ m_data

template<std::size_t N, class CharT , class Traits = std::char_traits<CharT>>
std::array<value_type, N + 1U> gw::basic_inplace_string< N, CharT, Traits >::m_data

The character array.

Note
The array must be public to allow use of basic_inplace_string as a non-type template parameter.

The documentation for this class was generated from the following file: