libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits > Class Template Referencefinal

A class to provide a representation for a null-terminated character string that utilises a small-string optimisation. More...

#include <stack_string.hpp>

Inheritance diagram for jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >:
[legend]
Collaboration diagram for jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >:
[legend]

Classes

struct  exception
 

Public Types

enum  : std::size_t { small_string_max_size }
 
typedef charT value_type
 
typedef traits traits_type
 
typedef std::iterator_traits< value_type const * > const_iterator_traits
 
typedef std::iterator_traits< value_type * > iterator_traits
 
typedef std::size_t size_type
 
typedef iterator_traits::pointer pointer
 
typedef const_iterator_traits::pointer const_pointer
 
typedef iterator_traits::pointer iterator
 
typedef const_iterator_traits::pointer const_iterator
 
typedef iterator_traits::reference reference
 
typedef const_iterator_traits::reference const_reference
 

Public Member Functions

 BOOST_MPL_ASSERT_RELATION (sizeof(pointer),<=, small_string_max_size)
 
constexpr basic_stack_string () noexcept(true) FORCE_INLINE
 
 basic_stack_string (ensure_char_ptr_argument_aligned src, std::size_t sz) noexcept(false) FORCE_INLINE
 Convert a C-style string into a basic_stack_string. More...
 
template<std::size_t SrcSz>
FORCE_INLINE basic_stack_string (value_type const (&src)[SrcSz]) noexcept(SrcSz<=small_string_max_size)
 Convert a C-style array of chars into a basic_stack_string. More...
 
 basic_stack_string (basic_stack_string const &str) noexcept(false) FORCE_INLINE
 
 basic_stack_string (basic_stack_string &&str) noexcept(true) FORCE_INLINE
 
 ~basic_stack_string () noexcept(true) FORCE_INLINE
 
basic_stack_stringoperator= (basic_stack_string const &str) noexcept(false) FORCE_INLINE
 Copy the basic_stack_string. More...
 
basic_stack_stringoperator= (basic_stack_string &&str) noexcept(true) FORCE_INLINE
 Move the basic_stack_string. More...
 
constexpr bool operator== (basic_stack_string const &) const noexcept(true) FORCE_INLINE
 
constexpr bool operator!= (basic_stack_string const &) const noexcept(true) FORCE_INLINE
 
iterator begin () noexcept(true) FORCE_INLINE
 Return an iterator to the beginning of the contained string. More...
 
const_iterator begin () const noexcept(true) FORCE_INLINE
 Return a const_iterator to the beginning of the contained string. More...
 
iterator end () noexcept(true) FORCE_INLINE
 Return an iterator to the end of the contained string. More...
 
const_iterator end () const noexcept(true) FORCE_INLINE
 Return a const_iterator to the end of the contained string. More...
 
constexpr size_type size () const noexcept(true) FORCE_INLINE
 Return the size of the contained string, excluding any null termination. More...
 
void resize (size_type s) noexcept(false) FORCE_INLINE
 Uninitialised resize of the contained string to the requested size. More...
 
void resize (size_type s, value_type i) noexcept(false) FORCE_INLINE
 Initialised resize of the contained string to the requested size. More...
 
constexpr size_type capacity () const noexcept(true) FORCE_INLINE
 Return the size of the internal buffer used to store the string, including the null termination. More...
 
void reserve (size_type s) noexcept(false) FORCE_INLINE
 Set the size of the internal buffer to at least the requested size, if the requested size is larger, then it will not be made smaller. More...
 
void clear () noexcept(true) FORCE_INLINE
 Clear the contained string. More...
 
constexpr bool empty () const noexcept(true) FORCE_INLINE
 Return is the string is empty. More...
 
reference operator[] (size_type p) noexcept(true) FORCE_INLINE
 Return an l-value to the requested element in the contained string. More...
 
const_reference operator[] (size_type p) const noexcept(true) FORCE_INLINE
 Return an r-value to the requested element in the contained string. More...
 
void push_back (value_type c) noexcept(false) FORCE_INLINE
 Append a character to the end of the contained string. More...
 
iterator insert (iterator p, const_iterator b, const_iterator e) noexcept(false) FORCE_INLINE
 Insert the characters in the range [b, e) into the contained string from the specified position, growing the contained string as necessary. More...
 
iterator erase (const_iterator b, const_iterator e) noexcept(true) FORCE_INLINE
 Remove the characters in the range [b, e). More...
 
basic_stack_stringreplace (iterator b, iterator e, const_iterator src_b, const_iterator src_e) noexcept(false) FORCE_INLINE
 Replace the characters in the range [b, e) with those in the range [src_b, src_e). More...
 
void swap (basic_stack_string &str) noexcept(true) FORCE_INLINE
 Swap the current basic_stack_string with the argument. More...
 
template<std::size_t SrcSz>
 basic_stack_string (value_type const (&src)[SrcSz]) noexcept(SrcSz<=small_string_max_size)
 

Static Public Member Functions

static constexpr size_type max_size () noexcept(true) FORCE_INLINE
 Return the maximum size of any possible contained string, including any null termination. More...
 

Detailed Description

template<unsigned int BuffN, class charT, class traits = std::char_traits<charT>>
class jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >

A class to provide a representation for a null-terminated character string that utilises a small-string optimisation.

This class is a value-type. If the string to be stored is less than small_string_max_size it is not stored on the heap, but on the stack. It is not a drop-in replacement for std::string, as it does not implement all of the member functions of the latter (because I don't like the fat interface). The optimisations assume that this class will be used for small strings, get the static branch-predictions wrong, and one can get a 50% drop in performance!

See also
__gnuxx::__vstring, std::string

Definition at line 53 of file stack_string.hpp.

Member Typedef Documentation

◆ const_iterator

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
typedef const_iterator_traits::pointer jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::const_iterator

Definition at line 68 of file stack_string.hpp.

◆ const_iterator_traits

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
typedef std::iterator_traits<value_type const *> jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::const_iterator_traits

Definition at line 62 of file stack_string.hpp.

◆ const_pointer

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
typedef const_iterator_traits::pointer jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::const_pointer

Definition at line 66 of file stack_string.hpp.

◆ const_reference

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
typedef const_iterator_traits::reference jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::const_reference

Definition at line 70 of file stack_string.hpp.

◆ iterator

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
typedef iterator_traits::pointer jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::iterator

Definition at line 67 of file stack_string.hpp.

◆ iterator_traits

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
typedef std::iterator_traits<value_type *> jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::iterator_traits

Definition at line 63 of file stack_string.hpp.

◆ pointer

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
typedef iterator_traits::pointer jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::pointer

Definition at line 65 of file stack_string.hpp.

◆ reference

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
typedef iterator_traits::reference jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::reference

Definition at line 69 of file stack_string.hpp.

◆ size_type

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
typedef std::size_t jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::size_type

Definition at line 64 of file stack_string.hpp.

◆ traits_type

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
typedef traits jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::traits_type

Definition at line 61 of file stack_string.hpp.

◆ value_type

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
typedef charT jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::value_type

Definition at line 60 of file stack_string.hpp.

Member Enumeration Documentation

◆ anonymous enum

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
anonymous enum : std::size_t
Enumerator
small_string_max_size 

Ensure that the internal, stack-based buffer is the minimum size of a pointer, or larger, in units of "native word"s. Also store the null termination char so that c_str() is fast too, trading off size for speed. In units of chars.

Definition at line 74 of file stack_string.hpp.

Constructor & Destructor Documentation

◆ basic_stack_string() [1/6]

template<unsigned int BuffN, class charT , class traits >
constexpr jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::basic_stack_string
inlineconstexprnoexcept

Complexity: O(1)

Definition at line 146 of file stack_string_impl.hpp.

◆ basic_stack_string() [2/6]

template<unsigned int BuffN, class charT , class traits >
jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::basic_stack_string ( ensure_char_ptr_argument_aligned  src,
std::size_t  sz 
)
inlineexplicitnoexcept

Convert a C-style string into a basic_stack_string.

Note the use of the opaque parameter type ensure_char_ptr_argument_aligned: this allows the user to pass in a char const * pointer, but ensures that it is suitably aligned for our purposes, without the user having to worry about alignment issues. Complexity: O(sz) best case, O(new()+sz) worst-case. May throw: std::bad_alloc, exception if pointer is nullptr

Parameters
srcA c-style null terminated string, that should have been suitably aligned, automatically, by the compiler.
szThe number of chars to copy.
See also
ensure_char_ptr_argument_aligned

Definition at line 152 of file stack_string_impl.hpp.

◆ basic_stack_string() [3/6]

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
template<std::size_t SrcSz>
FORCE_INLINE jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::basic_stack_string ( value_type const (&)  src[SrcSz])
explicitnoexcept

Convert a C-style array of chars into a basic_stack_string.

Complexity: O(1) best case, O(new()+SrcSz) worst-case. May throw: std::bad_alloc

Parameters
srcA c-style null terminated char-array.

◆ basic_stack_string() [4/6]

template<unsigned int BuffN, class charT , class traits >
jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::basic_stack_string ( basic_stack_string< BuffN, charT, traits > const &  str)
inlinenoexcept

Note that if the string contained in str can be optimised, this function will optimise the copy, i.e. place the copy on the stack from the heap. Complexity: O(1) best case, O(new()+str.size()) worst-case. May throw: std::bad_alloc

Parameters
strThe basic_stack_string to be copied.

Definition at line 174 of file stack_string_impl.hpp.

◆ basic_stack_string() [5/6]

template<unsigned int BuffN, class charT , class traits >
jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::basic_stack_string ( basic_stack_string< BuffN, charT, traits > &&  str)
inlinenoexcept

Complexity: O(1).

Parameters
strThe string to be copied.

Definition at line 185 of file stack_string_impl.hpp.

◆ ~basic_stack_string()

template<unsigned int BuffN, class charT , class traits >
jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::~basic_stack_string
inlinenoexcept

Complexity: O(1) best-case, O(delete()) worst-case.

Definition at line 194 of file stack_string_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::small_string_max_size.

◆ basic_stack_string() [6/6]

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
template<std::size_t SrcSz>
jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::basic_stack_string ( value_type const (&)  src[SrcSz])
inlinenoexcept

Definition at line 166 of file stack_string_impl.hpp.

Member Function Documentation

◆ begin() [1/2]

template<unsigned int BuffN, class charT , class traits >
basic_stack_string< BuffN, charT, traits >::const_iterator jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::begin
inlinenoexcept

Return a const_iterator to the beginning of the contained string.

Complexity: O(1)

Returns
const_iterator to the beginning of the contained string.

Definition at line 235 of file stack_string_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::small_string_max_size.

◆ begin() [2/2]

template<unsigned int BuffN, class charT , class traits >
basic_stack_string< BuffN, charT, traits >::iterator jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::begin
inlinenoexcept

Return an iterator to the beginning of the contained string.

Complexity: O(1)

Returns
iterator to the beginning of the contained string.

Definition at line 229 of file stack_string_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::small_string_max_size.

◆ BOOST_MPL_ASSERT_RELATION()

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::BOOST_MPL_ASSERT_RELATION ( sizeof(pointer ,
<=  ,
small_string_max_size   
)

◆ capacity()

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
constexpr size_type jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::capacity ( ) const
inlineconstexprnoexcept

Return the size of the internal buffer used to store the string, including the null termination.

Complexity: O(1) Constraint: capacity()>=size() && capacity()<=max_size().

Returns
Return the size of internal buffer.
See also
max_size(), size()

Definition at line 257 of file stack_string.hpp.

◆ clear()

template<unsigned int BuffN, class charT , class traits >
void jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::clear
inlinenoexcept

Clear the contained string.

Complexity: O(1) best case, O(delete()) worst case. Postcondition: size()==0 && empty()==true.

See also
empty(), size()

Definition at line 336 of file stack_string_impl.hpp.

◆ empty()

template<unsigned int BuffN, class charT , class traits >
constexpr bool jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::empty
inlineconstexprnoexcept

Return is the string is empty.

Complexity: O(1) Condition: empty()==(size()==0).

Returns
true if size()==0, false otherwise.
See also
size()

Definition at line 343 of file stack_string_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::size().

◆ end() [1/2]

template<unsigned int BuffN, class charT , class traits >
basic_stack_string< BuffN, charT, traits >::const_iterator jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::end
inlinenoexcept

Return a const_iterator to the end of the contained string.

Complexity: O(1)

Returns
const_iterator to the end of the contained string.

Definition at line 247 of file stack_string_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::small_string_max_size.

◆ end() [2/2]

template<unsigned int BuffN, class charT , class traits >
basic_stack_string< BuffN, charT, traits >::iterator jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::end
inlinenoexcept

Return an iterator to the end of the contained string.

Complexity: O(1)

Returns
iterator to the end of the contained string.

Definition at line 241 of file stack_string_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::small_string_max_size.

◆ erase()

template<unsigned int BuffN, class charT , class traits >
basic_stack_string< BuffN, charT, traits >::iterator jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::erase ( const_iterator  b,
const_iterator  e 
)
inlinenoexcept

Remove the characters in the range [b, e).

  Note that {b, e} must be within [begin(), end()).
  Complexity: O(std::distance(b, e))

  \param   b  The beginning of the range.
  \param   e  The end of the range.
  \return  An iterator which points to the element pointed to by e prior to the other elements being

erased. If no such element exists, end() is returned.

Definition at line 398 of file stack_string_impl.hpp.

Referenced by jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::replace().

◆ insert()

template<unsigned int BuffN, class charT , class traits >
basic_stack_string< BuffN, charT, traits >::iterator jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::insert ( iterator  p,
const_iterator  b,
const_iterator  e 
)
inlinenoexcept

Insert the characters in the range [b, e) into the contained string from the specified position, growing the contained string as necessary.

Note:

  • I'm not implementing the large number of overloads in std::basic_basic_stack_string, as that interface is unnecessarily fat.
  • The range inserted is [b, e).
  • If the capacity() has to be increased, all iterators are invalidated, values returned from data() & c_str() are invalidated, but the contained basic_stack_string is maintained. Complexity: O(resize()) May throw: std::bad_alloc
Parameters
pThe position immediately after the position into which the range is inserted, must be in the range [begin(), end()).
bThe beginning of the range.
eThe end of the range.
Returns
An iterator which refers to the copy of the first inserted character, or p if b==e.

Definition at line 367 of file stack_string_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::reserve(), and jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::small_string_max_size.

Referenced by jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::replace().

◆ max_size()

template<unsigned int BuffN, class charT , class traits = std::char_traits<charT>>
static constexpr size_type jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::max_size ( )
inlinestaticconstexprnoexcept

Return the maximum size of any possible contained string, including any null termination.

Complexity: O(1) Constraint: max_size()>=capacity().

Returns
Maximum possible size of a contained string.
See also
capacity()

Definition at line 213 of file stack_string.hpp.

Referenced by jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::reserve().

◆ operator!=()

template<unsigned int BuffN, class charT , class traits >
constexpr bool jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::operator!= ( basic_stack_string< BuffN, charT, traits > const &  s) const
inlineconstexprnoexcept

Definition at line 259 of file stack_string_impl.hpp.

◆ operator=() [1/2]

template<unsigned int BuffN, class charT , class traits >
basic_stack_string< BuffN, charT, traits > & jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::operator= ( basic_stack_string< BuffN, charT, traits > &&  str)
inlinenoexcept

Move the basic_stack_string.

Complexity: O(1)

Returns
An r-value to the copied basic_stack_string.

Definition at line 222 of file stack_string_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::swap().

◆ operator=() [2/2]

template<unsigned int BuffN, class charT , class traits >
basic_stack_string< BuffN, charT, traits > & jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::operator= ( basic_stack_string< BuffN, charT, traits > const &  str)
inlinenoexcept

Copy the basic_stack_string.

Complexity: O(1) best case, O(new()+str.size()) worst-case. May throw: std::bad_alloc

Returns
An r-value to the copied basic_stack_string.

Definition at line 214 of file stack_string_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::swap().

◆ operator==()

template<unsigned int BuffN, class charT , class traits >
constexpr bool jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::operator== ( basic_stack_string< BuffN, charT, traits > const &  s) const
inlineconstexprnoexcept

◆ operator[]() [1/2]

template<unsigned int BuffN, class charT , class traits >
basic_stack_string< BuffN, charT, traits >::const_reference jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::operator[] ( size_type  p) const
inlinenoexcept

Return an r-value to the requested element in the contained string.

Note that p must be less than size(), otherwise UB. Complexity: O(1)

Parameters
pThe zero-based index into the contained string.
Returns
An r-value to the requested character in the contained string.
See also
at(), size()

Definition at line 355 of file stack_string_impl.hpp.

◆ operator[]() [2/2]

template<unsigned int BuffN, class charT , class traits >
basic_stack_string< BuffN, charT, traits >::reference jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::operator[] ( size_type  p)
inlinenoexcept

Return an l-value to the requested element in the contained string.

Note that p must be less than size(), otherwise UB. Complexity: O(1)

Parameters
pThe zero-based index into the contained string.
Returns
An l-value to the requested character in the contained string.
See also
at(), size()

Definition at line 349 of file stack_string_impl.hpp.

◆ push_back()

template<unsigned int BuffN, class charT , class traits >
void jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::push_back ( value_type  c)
inlinenoexcept

Append a character to the end of the contained string.

Note:

  • If the capacity() has to be increased, all iterators are invalidated, values returned from data() & c_str() are invalidated, but the contained basic_stack_string is maintained. Complexity: O(resize()) May throw: std::bad_alloc
Parameters
cThe character to append.
See also
resize()

Definition at line 361 of file stack_string_impl.hpp.

◆ replace()

template<unsigned int BuffN, class charT , class traits >
basic_stack_string< BuffN, charT, traits > & jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::replace ( iterator  b,
iterator  e,
const_iterator  src_b,
const_iterator  src_e 
)
inlinenoexcept

Replace the characters in the range [b, e) with those in the range [src_b, src_e).

Note that {b, e} must be within [begin(), end()). Complexity: O(resize()+std::max(std::distance(b, e), std::distance(src_b, src_e))

Parameters
bThe beginning of the range.
eThe end of the range.
src_bThe beginning of the source range.
src_eThe end of the source range.
Returns
An l-value to the basic_stack_string.

Definition at line 419 of file stack_string_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::erase(), jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::insert(), jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::reserve(), and jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::small_string_max_size.

◆ reserve()

template<unsigned int BuffN, class charT , class traits >
void jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::reserve ( size_type  s)
inlinenoexcept

Set the size of the internal buffer to at least the requested size, if the requested size is larger, then it will not be made smaller.

Notes:

  • The elements in the internal buffer are not re-initialised, even if more memory has had to be allocated.
  • If the capacity() has to be increased, all iterators are invalidated, values returned from data() & c_str() are invalidated, but the contained string is maintained.
  • If capacity() has to be reduced, note that if the string has been moved to the heap it will not be moved back to the stack, for speed.
  • If an exception is thrown, then the object is unaffected. Complexity: O(1) best case, O(new()+delete()+std::max(s-size(), 0)) worst case. Constraint: capacity()==s && capacity()<=max_size(). May throw: std::bad_alloc
Parameters
sEnsure that capacity() returns s, if less than max_size(), otherwise no effect. The internal buffer in which the contained string may be stored is adjusted to ensure that it has a capacity of s.
See also
capacity(), max_size()

Definition at line 271 of file stack_string_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::max_size(), and jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::small_string_max_size.

Referenced by jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::insert(), jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::replace(), and jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::resize().

◆ resize() [1/2]

template<unsigned int BuffN, class charT , class traits >
void jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::resize ( size_type  s)
inlinenoexcept

Uninitialised resize of the contained string to the requested size.

Notes:

  • The elements in the internal buffer are not re-initialised, even if more memory has had to be allocated, for speed.
  • If capacity()>s then the internal buffer is reduced in size. Note that if the string has been moved to the heap it will not be moved back to the stack, for speed.
  • The null terminator is re-added to the end.
  • If the capacity() has to be increased, all iterators are invalidated but the contained string is maintained. Complexity: O(reserve()) Constraint: size()==s. May throw: std::bad_alloc
Parameters
sEnsure that size() returns s. The internal buffer in which the contained string may be stored is adjusted to ensure that it has a capacity of at least s.
See also
empty(), reserve(), size()

Definition at line 314 of file stack_string_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::reserve().

◆ resize() [2/2]

template<unsigned int BuffN, class charT , class traits >
void jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::resize ( size_type  s,
value_type  i 
)
inlinenoexcept

Initialised resize of the contained string to the requested size.

Notes:

  • If capacity()>s then the internal buffer is reduced in size. Note that if the string has been moved to the heap it will not be moved back to the stack, for speed.
  • The null terminator is re-added to the end.
  • If the capacity() has to be increased, all iterators are invalidated but the contained string is maintained. Complexity: O(reserve()+std::max(s-size(), 0)) Constraint: size()==s && empty()==false. May throw: std::bad_alloc
Parameters
sEnsure that size() returns s. The internal buffer in which the contained string may be stored is adjusted to ensure that it has a capacity() of at least s.
iThe value to which the s elements within the contained string should be initialised.
See also
capacity(), empty(), size()

Definition at line 323 of file stack_string_impl.hpp.

References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::reserve().

◆ size()

template<unsigned int BuffN, class charT , class traits >
constexpr basic_stack_string< BuffN, charT, traits >::size_type jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::size ( void  ) const
inlineconstexprnoexcept

Return the size of the contained string, excluding any null termination.

Complexity: O(1) Constraint: size()<=capacity() && empty==(size()==0).

Returns
Size of the contained string.
See also
capacity(), empty()

Definition at line 265 of file stack_string_impl.hpp.

Referenced by jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::empty(), and jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::operator==().

◆ swap()

template<unsigned int BuffN, class charT , class traits >
void jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::swap ( basic_stack_string< BuffN, charT, traits > &  str)
inlinenoexcept

Swap the current basic_stack_string with the argument.

Complexity: O(1)

Parameters
strThe basic_stack_string with which to swap.

Definition at line 206 of file stack_string_impl.hpp.

Referenced by jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::operator=().


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