SeqAn3
seqan3::constexpr_string< N > Class Template Reference

Implements a constexpr string that can be used for compile time computations. More...

#include <seqan3/range/container/constexpr_string.hpp>

Inheritance diagram for seqan3::constexpr_string< N >:
[legend]

Public Types

Member types
using value_type = char
 
using reference = char &
 
using const_reference = const char &
 
using iterator = std::add_pointer_t< value_type >
 
using const_iterator = std::add_pointer_t< value_type const >
 
using difference_type = typename data_type::difference_type
 
using size_type = typename data_type::size_type
 

Public Member Functions

Constructors, destructor and assignment
constexpr constexpr_string ()=default
 Default default constructor.
 
constexpr constexpr_string (constexpr_string const &)=default
 Default copy constructor.
 
constexpr constexpr_string (constexpr_string &&)=default
 Default move constructor.
 
constexpr constexpr_stringoperator= (constexpr_string const &)=default
 Default copy-assignment operator.
 
constexpr constexpr_stringoperator= (constexpr_string &&)=default
 Default move-assignment operator.
 
constexpr constexpr_string (const char(&_lit)[N+1]) noexcept
 Construction from literal. More...
 
constexpr constexpr_string (std::array< char, N > const &src) noexcept
 Construction from char array. More...
 
constexpr constexpr_string (const char c) noexcept
 Construction from char. More...
 
 ~constexpr_string ()=default
 Default destructor.
 
Element access
constexpr reference operator[] (size_t pos) noexcept
 Access an element in the string. More...
 
constexpr const_reference operator[] (size_t pos) const noexcept
 Access an element in the string. More...
 
std::string string () const
 Returns the content represented as std::string. More...
 
constexpr const char * c_str () const noexcept
 Returns the content represented as 0-terminated c-style string. More...
 
Capacity
constexpr size_type size () const noexcept
 Returns the size.
 
constexpr size_type max_size () const noexcept
 Returns the maximal capacity (same as size()).
 
constexpr bool empty () const noexcept
 Determines whether the string is empty.
 
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 pass the end of the string.
 
constexpr const_iterator end () const noexcept
 Returns iterator pass the end of the string. More...
 
constexpr const_iterator cend () const noexcept
 Returns iterator pass the end of the string. More...
 
Operations
template<size_t N2>
constexpr constexpr_string< N+N2 > operator+ (constexpr_string< N2 > const &rhs) const noexcept
 Concatenates two constexpr_strings. More...
 
constexpr void swap (constexpr_string &other) noexcept
 Swaps the contents. More...
 
Comparison
template<size_t N2>
constexpr bool operator== (constexpr_string< N2 > const &rhs) const noexcept
 Compares two strings lexicographically. More...
 
template<size_t N2>
constexpr bool operator!= (constexpr_string< N2 > const &rhs) const noexcept
 Compares two strings lexicographically. More...
 
template<size_t N2>
constexpr bool operator< (constexpr_string< N2 > const &rhs) const noexcept
 Compares two strings lexicographically. More...
 
template<size_t N2>
constexpr bool operator<= (constexpr_string< N2 > const &rhs) const noexcept
 Compares two strings lexicographically. More...
 
template<size_t N2>
constexpr bool operator> (constexpr_string< N2 > const &rhs) const noexcept
 Compares two strings lexicographically. More...
 
template<size_t N2>
constexpr bool operator>= (constexpr_string< N2 > const &rhs) const noexcept
 Compares two strings lexicographically. More...
 

Protected Types

using data_type = std::array< char, N+1 >
 Alias for the underlying data type.
 

Protected Member Functions

template<size_t N1>
constexpr constexpr_string (constexpr_string< N1 > const &lhs, constexpr_string< N - N1 > const &rhs) noexcept
 Constructs new constexpr_string by merging two other constexpr_strings. More...
 

Protected Attributes

data_type lit
 The internal string stored as array including \0-byte as last character.
 

Friends

template<size_t N2>
class constexpr_string
 Gives access to the merge constructor to constexpr_string with different size.
 

Related Functions

(Note that these are not member functions.)

Operations
template<size_t N>
constexpr void swap (constexpr_string< N > &lhs, constexpr_string< N > &rhs)
 Exchanges the given values. More...
 
Deduction guides
template<size_t N>
 constexpr_string (const char(&)[N]) -> constexpr_string< N - 1 >
 Deduces constexpr_string from string literals. More...
 
template<size_t N>
 constexpr_string (std::array< char, N > const &) -> constexpr_string< N >
 Deduces constexpr_string from std::array of type char. More...
 
 constexpr_string (const char) -> constexpr_string< 1 >
 Deduces constexpr_string from char. More...
 

Detailed Description

template<size_t N>
class seqan3::constexpr_string< N >

Implements a constexpr string that can be used for compile time computations.

Template Parameters
NThe size of the constexpr string.

This class provides a string type that can be constructed, evaluated and operated on at compile time. The stored string can be accessed as either a std::string or a c-style string through the respective member functions. All operations are constexpr except the conversion functions.

Internally the string stores an array of size N+1 containing the 0-byte to allow conversion to c-style strings. This also means that when creating an instance of this string from a string literal containing a 0-byte the size of this instance is one less.

Constructor & Destructor Documentation

◆ constexpr_string() [1/4]

template<size_t N>
template<size_t N1>
constexpr seqan3::constexpr_string< N >::constexpr_string ( constexpr_string< N1 > const &  lhs,
constexpr_string< N - N1 > const &  rhs 
)
inlineprotectednoexcept

Constructs new constexpr_string by merging two other constexpr_strings.

Parameters
lhsleft-hand-side of constexpr_string to merge.
rhsright-hand-side of constexpr_string to merge.

Exceptions

No-throw guarantee.

◆ constexpr_string() [2/4]

template<size_t N>
constexpr seqan3::constexpr_string< N >::constexpr_string ( const char(&)  _lit[N+1])
inlinenoexcept

Construction from literal.

Parameters
_litThe literal to construct the string for.

Exceptions

No-throw guarantee.

◆ constexpr_string() [3/4]

template<size_t N>
constexpr seqan3::constexpr_string< N >::constexpr_string ( std::array< char, N > const &  src)
inlinenoexcept

Construction from char array.

Parameters
srcThe char array to construct the constexpr_string for.

Exceptions

No-throw guarantee.

◆ constexpr_string() [4/4]

template<size_t N>
constexpr seqan3::constexpr_string< N >::constexpr_string ( const char  c)
inlinenoexcept

Construction from char.

Parameters
cThe character to construct the constexpr_string for.

Exceptions

No-throw guarantee.

Member Function Documentation

◆ begin()

template<size_t N>
constexpr const_iterator seqan3::constexpr_string< N >::begin ( ) const
inlinenoexcept

Returns the begin to the string.

◆ c_str()

template<size_t N>
constexpr const char* seqan3::constexpr_string< N >::c_str ( ) const
inlinenoexcept

Returns the content represented as 0-terminated c-style string.

Returns
const char * The stored string.

Exceptions

No-throw guarantee.

Complexity

Constant.

◆ cbegin()

template<size_t N>
constexpr const_iterator seqan3::constexpr_string< N >::cbegin ( ) const
inlinenoexcept

Returns the begin to the string.

◆ cend()

template<size_t N>
constexpr const_iterator seqan3::constexpr_string< N >::cend ( ) const
inlinenoexcept

Returns iterator pass the end of the string.

◆ end()

template<size_t N>
constexpr const_iterator seqan3::constexpr_string< N >::end ( ) const
inlinenoexcept

Returns iterator pass the end of the string.

◆ operator!=()

template<size_t N>
template<size_t N2>
constexpr bool seqan3::constexpr_string< N >::operator!= ( constexpr_string< N2 > const &  rhs) const
inlinenoexcept

Compares two strings lexicographically.

Returns
bool true if the corresponding comparison holds, false otherwise.

Exceptions

No-throw guarantee.

Complexity

Linear in the size of the strings.

◆ operator+()

template<size_t N>
template<size_t N2>
constexpr constexpr_string<N + N2> seqan3::constexpr_string< N >::operator+ ( constexpr_string< N2 > const &  rhs) const
inlinenoexcept

Concatenates two constexpr_strings.

Parameters
rhsThe right-hand-side to concat with.
Returns
constexpr_string<N + N2> The new constexpr_string with size N + N2.

Exceptions

No-throw guarantee.

Complexity

Linear in the size of the strings.

◆ operator<()

template<size_t N>
template<size_t N2>
constexpr bool seqan3::constexpr_string< N >::operator< ( constexpr_string< N2 > const &  rhs) const
inlinenoexcept

Compares two strings lexicographically.

Returns
bool true if the corresponding comparison holds, false otherwise.

Exceptions

No-throw guarantee.

Complexity

Linear in the size of the strings.

◆ operator<=()

template<size_t N>
template<size_t N2>
constexpr bool seqan3::constexpr_string< N >::operator<= ( constexpr_string< N2 > const &  rhs) const
inlinenoexcept

Compares two strings lexicographically.

Returns
bool true if the corresponding comparison holds, false otherwise.

Exceptions

No-throw guarantee.

Complexity

Linear in the size of the strings.

◆ operator==()

template<size_t N>
template<size_t N2>
constexpr bool seqan3::constexpr_string< N >::operator== ( constexpr_string< N2 > const &  rhs) const
inlinenoexcept

Compares two strings lexicographically.

Returns
bool true if the corresponding comparison holds, false otherwise.

Exceptions

No-throw guarantee.

Complexity

Linear in the size of the strings.

◆ operator>()

template<size_t N>
template<size_t N2>
constexpr bool seqan3::constexpr_string< N >::operator> ( constexpr_string< N2 > const &  rhs) const
inlinenoexcept

Compares two strings lexicographically.

Returns
bool true if the corresponding comparison holds, false otherwise.

Exceptions

No-throw guarantee.

Complexity

Linear in the size of the strings.

◆ operator>=()

template<size_t N>
template<size_t N2>
constexpr bool seqan3::constexpr_string< N >::operator>= ( constexpr_string< N2 > const &  rhs) const
inlinenoexcept

Compares two strings lexicographically.

Returns
bool true if the corresponding comparison holds, false otherwise.

Exceptions

No-throw guarantee.

Complexity

Linear in the size of the strings.

◆ operator[]() [1/2]

template<size_t N>
constexpr reference seqan3::constexpr_string< N >::operator[] ( size_t  pos)
inlinenoexcept

Access an element in the string.

Exceptions

No-throw guarantee.

Complexity

Constant.

◆ operator[]() [2/2]

template<size_t N>
constexpr const_reference seqan3::constexpr_string< N >::operator[] ( size_t  pos) const
inlinenoexcept

Access an element in the string.

Exceptions

No-throw guarantee.

Complexity

Constant.

◆ string()

template<size_t N>
std::string seqan3::constexpr_string< N >::string ( ) const
inline

Returns the content represented as std::string.

Returns
std::string The stored string.

Exceptions

Strong exception guarantee. No data is modified.

Complexity

Linear in the size of the string.

◆ swap()

template<size_t N>
constexpr void seqan3::constexpr_string< N >::swap ( constexpr_string< N > &  other)
inlinenoexcept

Swaps the contents.

Both strings must have the same size in order to swap them.

Complexity

Constant.

Friends And Related Function Documentation

◆ constexpr_string() [1/3]

template<size_t N>
constexpr_string ( const   char(&)[N]) -> constexpr_string< N - 1 >
related

Deduces constexpr_string from string literals.

◆ constexpr_string() [2/3]

template<size_t N>
constexpr_string ( std::array< char, N > const &  ) -> constexpr_string< N >
related

Deduces constexpr_string from std::array of type char.

◆ constexpr_string() [3/3]

template<size_t N>
constexpr_string ( const char  ) -> constexpr_string< 1 >
related

Deduces constexpr_string from char.

◆ swap()

template<size_t N>
constexpr void swap ( constexpr_string< N > &  lhs,
constexpr_string< N > &  rhs 
)
related

Exchanges the given values.

Template Parameters
NThe size of the constexpr_string.
Parameters
lhsThe left operand.
rhsThe right operand.

Exceptions

No-throw guarantee.

Complexity

Constant.


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