libjmmcg
release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
|
A class to provide a representation for a null-terminated character string that utilises a small-string optimisation. More...
#include <stack_string.hpp>
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_string & | operator= (basic_stack_string const &str) noexcept(false) FORCE_INLINE |
Copy the basic_stack_string. More... | |
basic_stack_string & | operator= (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_string & | replace (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... | |
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!
Definition at line 53 of file stack_string.hpp.
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.
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.
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.
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.
typedef iterator_traits::pointer jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::iterator |
Definition at line 67 of file stack_string.hpp.
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.
typedef iterator_traits::pointer jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::pointer |
Definition at line 65 of file stack_string.hpp.
typedef iterator_traits::reference jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::reference |
Definition at line 69 of file stack_string.hpp.
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.
typedef traits jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::traits_type |
Definition at line 61 of file stack_string.hpp.
typedef charT jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::value_type |
Definition at line 60 of file stack_string.hpp.
anonymous enum : std::size_t |
Definition at line 74 of file stack_string.hpp.
|
inlineconstexprnoexcept |
Complexity: O(1)
Definition at line 146 of file stack_string_impl.hpp.
|
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
src | A c-style null terminated string, that should have been suitably aligned, automatically, by the compiler. |
sz | The number of chars to copy. |
Definition at line 152 of file stack_string_impl.hpp.
|
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
src | A c-style null terminated char-array. |
|
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
str | The basic_stack_string to be copied. |
Definition at line 174 of file stack_string_impl.hpp.
|
inlinenoexcept |
Complexity: O(1).
str | The string to be copied. |
Definition at line 185 of file stack_string_impl.hpp.
|
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.
|
inlinenoexcept |
Definition at line 166 of file stack_string_impl.hpp.
|
inlinenoexcept |
Return a const_iterator to the beginning of the contained string.
Complexity: O(1)
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.
|
inlinenoexcept |
Return an iterator to the beginning of the contained string.
Complexity: O(1)
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.
jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::BOOST_MPL_ASSERT_RELATION | ( | sizeof(pointer) | , |
<= | , | ||
small_string_max_size | |||
) |
|
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().
Definition at line 257 of file stack_string.hpp.
|
inlinenoexcept |
|
inlineconstexprnoexcept |
Return is the string is empty.
Complexity: O(1) Condition: empty()==(size()==0).
Definition at line 343 of file stack_string_impl.hpp.
References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::size().
|
inlinenoexcept |
Return a const_iterator to the end of the contained string.
Complexity: O(1)
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.
|
inlinenoexcept |
Return an iterator to the end of the contained string.
Complexity: O(1)
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.
|
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().
|
inlinenoexcept |
Insert the characters in the range [b, e) into the contained string from the specified position, growing the contained string as necessary.
Note:
p | The position immediately after the position into which the range is inserted, must be in the range [begin(), end()). |
b | The beginning of the range. |
e | The end of the range. |
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().
|
inlinestaticconstexprnoexcept |
Return the maximum size of any possible contained string, including any null termination.
Complexity: O(1) Constraint: max_size()>=capacity().
Definition at line 213 of file stack_string.hpp.
Referenced by jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::reserve().
|
inlineconstexprnoexcept |
Definition at line 259 of file stack_string_impl.hpp.
|
inlinenoexcept |
Move the basic_stack_string.
Complexity: O(1)
Definition at line 222 of file stack_string_impl.hpp.
References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::swap().
|
inlinenoexcept |
Copy the basic_stack_string.
Complexity: O(1) best case, O(new()+str.size()) worst-case. May throw: std::bad_alloc
Definition at line 214 of file stack_string_impl.hpp.
References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::swap().
|
inlineconstexprnoexcept |
Definition at line 253 of file stack_string_impl.hpp.
References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::size().
|
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)
p | The zero-based index into the contained string. |
Definition at line 355 of file stack_string_impl.hpp.
|
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)
p | The zero-based index into the contained string. |
Definition at line 349 of file stack_string_impl.hpp.
|
inlinenoexcept |
Append a character to the end of the contained string.
Note:
c | The character to append. |
Definition at line 361 of file stack_string_impl.hpp.
|
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))
b | The beginning of the range. |
e | The end of the range. |
src_b | The beginning of the source range. |
src_e | The end of the source range. |
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.
|
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:
s | Ensure 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. |
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().
|
inlinenoexcept |
Uninitialised resize of the contained string to the requested size.
Notes:
s | Ensure 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. |
Definition at line 314 of file stack_string_impl.hpp.
References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::reserve().
|
inlinenoexcept |
Initialised resize of the contained string to the requested size.
Notes:
s | Ensure 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. |
i | The value to which the s elements within the contained string should be initialised. |
Definition at line 323 of file stack_string_impl.hpp.
References jmmcg::LIBJMMCG_VER_NAMESPACE::basic_stack_string< BuffN, charT, traits >::reserve().
|
inlineconstexprnoexcept |
Return the size of the contained string, excluding any null termination.
Complexity: O(1) Constraint: size()<=capacity() && empty==(size()==0).
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==().
|
inlinenoexcept |
Swap the current basic_stack_string with the argument.
Complexity: O(1)
str | The 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=().