Implements a small string that can be used for compile time computations. More...
#include <seqan3/range/container/small_string.hpp>
Public Types | |
Associated types | |
using | value_type = char |
The value_type type. | |
using | reference = value_type & |
The reference type. | |
using | const_reference = const value_type & |
The const_reference type. | |
using | iterator = value_type * |
The iterator type. | |
using | const_iterator = value_type const * |
The const_iterator type. | |
using | difference_type = ptrdiff_t |
The difference_type type. | |
using | size_type = detail::min_viable_uint_t< capacity_ > |
The size_type type. | |
Public Member Functions | |
Constructors, destructor and assignment | |
template<size_t N> | |
constexpr | small_string (char const (&_lit)[N]) noexcept |
Construction from literal. More... | |
constexpr | small_string (char const c) noexcept |
Construction from char. More... | |
template<size_t N> | |
constexpr small_string & | operator= (char const (&_lit)[N]) noexcept |
Assign from literal. More... | |
template<size_t N> | |
constexpr void | assign (char const (&_lit)[N]) noexcept |
Assign from literal. More... | |
template<std::forward_iterator begin_it_type, typename end_it_type > | |
constexpr void | assign (begin_it_type begin_it, end_it_type end_it) noexcept |
Assign from pair of iterators. More... | |
Modifiers | |
constexpr void | clear () noexcept |
Removes all elements from the container. More... | |
constexpr void | push_back (char const value) noexcept |
Appends the given element value to the end of the container. More... | |
constexpr void | pop_back () noexcept |
Removes the last element of the container. More... | |
constexpr void | resize (size_type const count) noexcept |
Resizes the container to contain count elements. More... | |
constexpr void | resize (size_type const count, char const value) noexcept |
Resizes the container to contain count elements. More... | |
constexpr small_string & | erase (size_type index=0, size_type count=max_size()) noexcept |
Removes specified elements from the container. More... | |
Conversion | |
std::string | str () const |
Returns the content represented as std::string. More... | |
constexpr char const * | c_str () const noexcept |
Returns the content represented as 0-terminated c-style string. More... | |
operator std::string () const | |
Implicit conversion to std::string which delegates to seqan3::small_string::str(). More... | |
Constructors, destructor and assignment | |
constexpr void | assign (std::initializer_list< value_type > ilist) noexcept(is_noexcept) |
Assign from std::initializer_list . More... | |
constexpr void | assign (size_type const count, value_type const value) noexcept(is_noexcept) |
Assign with count times value . More... | |
constexpr void | assign (other_range_t &&range) noexcept(is_noexcept) |
Assign from a different range. More... | |
Iterators | |
constexpr iterator | begin () noexcept |
Returns the begin to the string. | |
constexpr const_iterator | begin () const noexcept |
Returns the begin to the string. More... | |
constexpr const_iterator | cbegin () const noexcept |
Returns the begin to the string. More... | |
constexpr iterator | end () noexcept |
Returns iterator past the end of the vector. | |
constexpr const_iterator | end () const noexcept |
Returns iterator past the end of the vector. More... | |
constexpr const_iterator | cend () const noexcept |
Returns iterator past the end of the vector. More... | |
Element access | |
reference | at (size_type const i) |
Return the i-th element. More... | |
const_reference | at (size_type const i) const |
Return the i-th element. More... | |
constexpr reference | operator[] (size_type const i) noexcept |
Return the i-th element. More... | |
constexpr const_reference | operator[] (size_type const i) const noexcept |
Return the i-th element. More... | |
constexpr reference | front () noexcept |
Return the first element. Calling front on an empty container is undefined. More... | |
constexpr const_reference | front () const noexcept |
Return the first element. Calling front on an empty container is undefined. More... | |
constexpr reference | back () noexcept |
Return the last element. More... | |
constexpr const_reference | back () const noexcept |
Return the last element. More... | |
constexpr value_type * | data () noexcept |
Direct access to the underlying array. | |
constexpr value_type const * | data () const noexcept |
Direct access to the underlying array. More... | |
Capacity | |
constexpr bool | empty () const noexcept |
Checks whether the container is empty. More... | |
constexpr size_type | size () const noexcept |
Returns the number of elements in the container, i.e. std::distance(begin(), end()). More... | |
constexpr void | reserve (size_type) const noexcept |
Since the capacity is fixed on compile time, this is a no-op. | |
constexpr void | shrink_to_fit () const noexcept |
Since the capacity is fixed on compile time, this is a no-op. | |
Modifiers | |
constexpr iterator | insert (const_iterator pos, value_type const value) noexcept(is_noexcept) |
Inserts value before position in the container. More... | |
constexpr iterator | insert (const_iterator pos, size_type const count, value_type const value) noexcept(is_noexcept) |
Inserts count copies of value before position in the container. More... | |
constexpr iterator | insert (const_iterator pos, begin_it_type begin_it, end_it_type end_it) noexcept(is_noexcept) |
Inserts elements from range [begin_it, end_it) before position in the container. More... | |
constexpr iterator | insert (const_iterator pos, std::initializer_list< value_type > const &ilist) noexcept(is_noexcept) |
Inserts elements from initializer list before position in the container. More... | |
constexpr iterator | erase (const_iterator begin_it, const_iterator end_it) noexcept |
Removes specified elements from the container. More... | |
constexpr iterator | erase (const_iterator pos) noexcept |
Removes specified elements from the container. More... | |
constexpr void | swap (small_vector &rhs) noexcept(is_noexcept) |
Swap contents with another instance. More... | |
constexpr void | swap (small_vector &&rhs) noexcept(is_noexcept) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
Static Public Member Functions | |
Capacity | |
static constexpr size_type | max_size () noexcept |
Returns the maximal size which equals the capacity. | |
static constexpr size_type | capacity () noexcept |
Returns the maximal capacity. | |
Friends | |
Concatenation | |
template<size_t capacity2> | |
constexpr friend small_string< capacity_+capacity2 > | operator+ (small_string const &lhs, small_string< capacity2 > const &rhs) noexcept |
Concatenates two small_strings by returning a new small_string. More... | |
Input/output | |
std::ostream & | operator<< (std::ostream &os, small_string const &str) |
Formatted output for the seqan3::small_string. More... | |
std::istream & | operator>> (std::istream &is, small_string &str) |
Formatted input for the seqan3::small_string. More... | |
Related Functions | |
(Note that these are not member functions.) | |
Deduction guides | |
template<size_t N> | |
small_string (char const(&)[N]) -> small_string< N - 1 > | |
Deduces small_string from string literals. | |
template<size_t N> | |
small_string (std::array< char, N > const &) -> small_string< N > | |
Deduces small_string from std::array of type char. | |
small_string (char const) -> small_string< 1 > | |
Deduces small_string from char. | |
Implements a small string that can be used for compile time computations.
capacity_ | The capacity of the small string. |
This class provides a string type for small strings and compile-time contexts. It has fixed capacity, but variable size within the capacity. It is always allocated on the stack and most of it's members are constexpr
-qualified. The underlying data can be exposed as a null-terminated c-style string (without copying) and conversion operators to std::string are provided (this involves copying).
Internally the string stores a null-terminated array of size capacity_ + 1
and the size of the string as a member. The smallest possible type is used for storage of the size. For example, small_string<30>
uses 32bytes of memory (one byte extra for the null-terminator and one byte to save the size).
Usage:
|
inlineconstexprnoexcept |
Construction from literal.
_lit | The literal to construct the string for. |
The char
literal is expected to be null-terminated (asserted in debug-mode). If it is not, the last character will be lost when copying to the instance of small_string
.
No-throw guarantee.
|
inlineexplicitconstexprnoexcept |
Construction from char.
c | The character to construct the small_string for. |
No-throw guarantee.
|
inlineconstexprnoexcept |
Assign from pair of iterators.
begin_it_type | Must satisfy std::forward_iterator and the value_type must be constructible from the reference type of begin_it_type. |
end_it_type | Must satisfy std::sentinel_for. |
[in] | begin_it | Begin of range to construct/assign from. |
[in] | end_it | End of range to construct/assign from. |
Linear in the distance between begin_it
and end_it
.
No-throw guarantee if value_type is std::is_nothrow_copy_constructible.
|
inlineconstexprnoexcept |
Assign from literal.
_lit | The literal to assign the string from. |
The char
literal is expected to be null-terminated (asserted in debug-mode). If it is not, the last character will be lost when copying to the instance of small_string
.
Linear in the size of _lit.
No-throw guarantee.
|
inlineconstexprnoexceptinherited |
Assign from a different range.
other_range_t | The type of range to be inserted; must satisfy std::ranges::input_range and value_type must be constructible from std::ranges::range_reference_t<other_range_t>. |
[in] | range | The sequences to construct/assign from. |
Linear in the size of range
.
No-throw guarantee if value_type is std::is_nothrow_copy_constructible.
|
inlineconstexprnoexceptinherited |
Assign with count
times value
.
[in] | count | Number of elements. |
[in] | value | The initial value to be assigned. |
In .
No-throw guarantee if value_type is std::is_nothrow_copy_constructible.
|
inlineconstexprnoexceptinherited |
Assign from std::initializer_list
.
[in] | ilist | A std::initializer_list of value_type. |
Linear in the size of ilist
.
No-throw guarantee if value_type is std::is_nothrow_copy_constructible.
|
inlineinherited |
Return the i-th element.
[in] | i | Index of the element to retrieve. |
std::out_of_range | If you access an element behind the last. |
i
.Constant.
Throws std::out_of_range if i >= size()
.
|
inlineinherited |
Return the i-th element.
[in] | i | Index of the element to retrieve. |
std::out_of_range | If you access an element behind the last. |
i
.Constant.
Throws std::out_of_range if i >= size()
.
|
inlineconstexprnoexceptinherited |
Return the last element.
Calling back on an empty container is undefined. In debug mode an assertion checks the size of the container.
Constant.
No-throw guarantee.
|
inlineconstexprnoexceptinherited |
Return the last element.
Calling back on an empty container is undefined. In debug mode an assertion checks the size of the container.
Constant.
No-throw guarantee.
|
inlineconstexprnoexceptinherited |
Returns the begin to the string.
|
inlineconstexprnoexcept |
Returns the content represented as 0-terminated c-style string.
char const *
The stored string.No-throw guarantee.
Constant.
|
inlineconstexprnoexceptinherited |
Returns the begin to the string.
|
inlineconstexprnoexceptinherited |
Returns iterator past the end of the vector.
|
inlineconstexprnoexcept |
Removes all elements from the container.
Constant.
No-throw guarantee.
|
inlineconstexprnoexceptinherited |
Direct access to the underlying array.
|
inlineconstexprnoexceptinherited |
Checks whether the container is empty.
true
if the container is empty, false
otherwise.Constant.
No-throw guarantee.
|
inlineconstexprnoexceptinherited |
Returns iterator past the end of the vector.
|
inlineconstexprnoexceptinherited |
Removes specified elements from the container.
begin_it | Begin of range to erase. |
end_it | Behind the end of range to erase. |
pos
refers to the last element, the end() iterator is returned.Invalidates iterators and references at or after the point of the erase, including the end() iterator.
The iterator begin_it does not need to be dereferenceable if begin_it==end_it: erasing an empty range is a no-op.
Linear in size().
No-throw guarantee.
|
inlineconstexprnoexceptinherited |
Removes specified elements from the container.
pos | Remove the element at pos. |
pos
refers to the last element, the end() iterator is returned.Invalidates iterators and references at or after the point of the erase, including the end() iterator.
The iterator pos
must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferencable) cannot be used as a value for pos.
Linear in size().
No-throw guarantee.
|
inlineconstexprnoexcept |
Removes specified elements from the container.
index | Remove the elements starting at index . Defaults to 0 . |
count | The number of elements to remove. Defaults to max_size() . |
*this
Invalidates iterators and references at or after the point of the erase, including the end() iterator.
The iterator pos
must be valid and dereferenceable. Thus the end() iterator (which is valid, but is not dereferencable) cannot be used as a value for pos.
Linear in size().
No-throw guarantee.
|
inlineconstexprnoexceptinherited |
Return the first element. Calling front on an empty container is undefined.
Calling front on an empty container is undefined. In debug mode an assertion checks the size of the container.
Constant.
No-throw guarantee.
|
inlineconstexprnoexceptinherited |
Return the first element. Calling front on an empty container is undefined.
Calling front on an empty container is undefined. In debug mode an assertion checks the size of the container.
Constant.
No-throw guarantee.
|
inlineconstexprnoexceptinherited |
Inserts elements from range [begin_it, end_it)
before position in the container.
begin_it_type | Must satisfy std::forward_iterator and the value_type must be constructible from the reference type of begin_it_type. |
end_it_type | Must satisfy std::sentinel_for. |
[in] | pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
[in] | begin_it | Begin of range to construct/assign from. |
[in] | end_it | End of range to construct/assign from. |
pos
if begin_it==end_it
.The behaviour is undefined if begin_it and end_it are iterators into *this
or if, given the size n
of the range represented by [begin_t, end_it), size()
+ n
> capacity()
.
Worst-case linear in size().
No-throw guarantee if value_type is std::is_nothrow_copy_constructible.
|
inlineconstexprnoexceptinherited |
Inserts count copies of value before position in the container.
pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
count | Number of copies. |
value | Element value to insert. |
pos
if count==0
.If size()
+ count
> capacity()
this function results in undefined behaviour.
Worst-case linear in size().
No-throw guarantee if value_type is std::is_nothrow_copy_constructible.
|
inlineconstexprnoexceptinherited |
Inserts elements from initializer list before position in the container.
pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
ilist | Initializer list with values to insert. |
pos
if ilist
is empty.Given the size n
of ilist
, this function results in undefined behaviour if size()
+ n
> capacity()
.
Worst-case linear in size().
No-throw guarantee if value_type is std::is_nothrow_copy_constructible.
|
inlineconstexprnoexceptinherited |
Inserts value before position in the container.
pos | Iterator before which the content will be inserted. pos may be the end() iterator. |
value | Element value to insert. |
Inserting a value although the maximum capacity is reached is undefined behaviour.
Worst-case linear in size().
No-throw guarantee if value_type is std::is_nothrow_copy_constructible.
|
inline |
Implicit conversion to std::string which delegates to seqan3::small_string::str().
Strong exception guarantee. No data is modified.
Linear in the size of the string.
|
inlineconstexprnoexcept |
Assign from literal.
_lit | The literal to assign the string from. |
The char
literal is expected to be null-terminated (asserted in debug-mode). If it is not, the last character will be lost when copying to the instance of small_string
.
Linear in the size of _lit.
No-throw guarantee.
|
inlineconstexprnoexceptinherited |
Return the i-th element.
i | The element to retrieve. |
i
.Accessing an element behind the last causes undefined behaviour. In debug mode an assertion checks the size of the container.
Constant.
No-throw guarantee.
|
inlineconstexprnoexceptinherited |
Return the i-th element.
i | The element to retrieve. |
i
.Accessing an element behind the last causes undefined behaviour. In debug mode an assertion checks the size of the container.
Constant.
No-throw guarantee.
|
inlineconstexprnoexcept |
Removes the last element of the container.
Calling pop_back() on an empty container is undefined. In debug mode an assertion will be thrown.
No iterators or references except for back() and end() are invalidated.
Constant.
No-throw guarantee.
|
inlineconstexprnoexcept |
Appends the given element value to the end of the container.
value | The value to append. |
If the new size() is greater than capacity() this is undefined behaviour.
Constant.
No-throw guarantee.
|
inlineconstexprnoexcept |
Resizes the container to contain count elements.
[in] | count | The new size. |
If count is greater than capacity this is undefined behaviour.
Constant.
No-throw guarantee.
|
inlineconstexprnoexcept |
Resizes the container to contain count elements.
value | Append copies of value when resizing. | |
[in] | count | The new size. |
If count is greater than capacity this is undefined behaviour.
Constant.
No-throw guarantee.
|
inlineconstexprnoexceptinherited |
Returns the number of elements in the container, i.e. std::distance(begin(), end()).
Constant.
No-throw guarantee.
|
inline |
Returns the content represented as std::string.
std::string
The stored string.Strong exception guarantee. No data is modified.
Linear in the size of the string.
|
inlineconstexprnoexceptinherited |
Swap contents with another instance.
rhs | The other instance to swap with. |
Linear in the size of both containers.
No-throw guarantee if value_type is std::is_nothrow_copy_constructible.
|
friend |
Concatenates two small_strings by returning a new small_string.
lhs | The left-hand-side to concat with. |
rhs | The right-hand-side to concat with. |
small_string<capacity_ + capacity2>
The new small_string with size capacity_
+ capacity2
.No-throw guarantee.
Linear in the size of the strings.
|
friend |
Formatted output for the seqan3::small_string.
[in,out] | os | The std::basic_ostream to write to. |
[in] | str | The seqan3::small_string to read from. |
os
.Internally calls os << str.str()
.
|
friend |
Formatted input for the seqan3::small_string.
[in,out] | is | The std::basic_istream to read from. |
[out] | str | The seqan3::small_string to write to. |
is
.Reads at most seqan3::small_string::max_size characters from the stream. If a stream error occurred or no characters could be extracted the std::ios_base::failbit is set. This may throw an exception.