GMP 0.3.0
Generative Metaprogramming library for C++
Loading...
Searching...
No Matches
gmp::fixed_string< N > Struct Template Referencefinal

A compile-time string type with fixed length and constexpr operations. More...

#include <fixed_string.hpp>

Public Types

using size_type = std::size_t
 

Public Member Functions

constexpr fixed_string (const char(&str)[N+1])
 Construct a fixed string from a string literal.
 
constexpr fixed_string (std::string_view sv)
 Construct a fixed string from a string view of matching length.
 
consteval char operator[] (size_type pos) const noexcept
 Element access.
 
consteval const chardata () const noexcept
 Get a pointer to the underlying null-terminated character data.
 
constexpr auto to_string_view () const noexcept
 Convert the fixed string to std::string_view.
 
constexpr operator char const * () const noexcept
 Implicitly convert to const char*.
 
consteval size_type size () const noexcept
 Capacity.
 
consteval size_type length () const noexcept
 Get the number of stored characters.
 
consteval bool empty () const noexcept
 Check whether the fixed string is empty.
 
consteval size_type find (const char *str, size_type pos=0) const noexcept
 Modifiers.
 
template<auto Pos, auto Count = fixed_string::npos>
consteval auto substr (constant_arg_t< Pos >, constant_arg_t< Count >=constant_arg< fixed_string::npos >) const noexcept
 Extract a compile-time substring.
 

Public Attributes

char data_ [N+1]
 

Static Public Attributes

static constexpr size_type npos
 

Friends

consteval auto operator<=> (fixed_string const &, fixed_string const &)=default
 

Detailed Description

template<std::size_t N>
struct gmp::fixed_string< N >

fixed_string<N> stores N characters plus a trailing null terminator and is intended for non-type template parameter and compile-time string manipulation use cases.

Template Parameters
NThe number of characters excluding the null terminator.
Examples
type_name_and_size.cpp.

Definition at line 36 of file fixed_string.hpp.

Member Typedef Documentation

◆ size_type

template<std::size_t N>
using gmp::fixed_string< N >::size_type = std::size_t

Definition at line 37 of file fixed_string.hpp.

Constructor & Destructor Documentation

◆ fixed_string() [1/2]

template<std::size_t N>
constexpr gmp::fixed_string< N >::fixed_string ( const char(&)  str[N+1])
inlineconstexpr
Parameters
strThe source character array including the terminating null byte.

Definition at line 45 of file fixed_string.hpp.

References gmp::fixed_string< N >::data_, and gmp::enum_values().

◆ fixed_string() [2/2]

template<std::size_t N>
constexpr gmp::fixed_string< N >::fixed_string ( std::string_view  sv)
inlineconstexpr
Parameters
svThe source string view.

Definition at line 54 of file fixed_string.hpp.

References gmp::fixed_string< N >::data_, and gmp::enum_values().

Member Function Documentation

◆ data()

template<std::size_t N>
consteval const char * gmp::fixed_string< N >::data ( ) const
inlinenoexcept
Returns
Pointer to the stored character buffer.

Definition at line 76 of file fixed_string.hpp.

References gmp::fixed_string< N >::data_.

◆ empty()

template<std::size_t N>
consteval bool gmp::fixed_string< N >::empty ( ) const
inlinenoexcept
Returns
true if the string contains no characters, otherwise false.

Definition at line 112 of file fixed_string.hpp.

◆ find()

template<std::size_t N>
consteval size_type gmp::fixed_string< N >::find ( const char str,
size_type  pos = 0 
) const
inlinenoexcept

Operations

Find the first occurrence of a C-string inside the fixed string.

Parameters
strThe substring to search for.
posThe starting position of the search.
Returns
The index of the first match, or npos if not found.

Definition at line 124 of file fixed_string.hpp.

References gmp::enum_values(), and gmp::fixed_string< N >::to_string_view().

◆ length()

template<std::size_t N>
consteval size_type gmp::fixed_string< N >::length ( ) const
inlinenoexcept
Returns
The string length excluding the null terminator.

Definition at line 105 of file fixed_string.hpp.

◆ operator char const *()

template<std::size_t N>
constexpr gmp::fixed_string< N >::operator char const * ( ) const
inlineconstexprnoexcept
Returns
Pointer to the stored character buffer.

Definition at line 90 of file fixed_string.hpp.

References gmp::fixed_string< N >::data_.

◆ operator[]()

template<std::size_t N>
consteval char gmp::fixed_string< N >::operator[] ( size_type  pos) const
inlinenoexcept

Access a character at the specified compile-time index.

Parameters
posThe zero-based character position.
Returns
The character at pos.

Definition at line 66 of file fixed_string.hpp.

References gmp::fixed_string< N >::data_, and gmp::enum_values().

◆ size()

template<std::size_t N>
consteval size_type gmp::fixed_string< N >::size ( ) const
inlinenoexcept

Get the number of stored characters.

Returns
The string length excluding the null terminator.

Definition at line 98 of file fixed_string.hpp.

Referenced by gmp::type_name().

◆ substr()

template<std::size_t N>
template<auto Pos, auto Count = fixed_string::npos>
consteval auto gmp::fixed_string< N >::substr ( constant_arg_t< Pos ,
constant_arg_t< Count = constant_arg<fixed_string< N >::npos> 
) const
inlinenoexcept
Template Parameters
PosThe starting position.
CountThe number of characters to extract, or npos for the suffix.
Parameters
Thecompile-time starting position wrapper.
Thecompile-time count wrapper.
Returns
A new fixed_string containing the selected substring.

Definition at line 140 of file fixed_string.hpp.

References gmp::fixed_string< N >::data_, and gmp::enum_values().

◆ to_string_view()

template<std::size_t N>
constexpr auto gmp::fixed_string< N >::to_string_view ( ) const
inlineconstexprnoexcept
Returns
A string view covering the stored characters.

Definition at line 83 of file fixed_string.hpp.

References gmp::fixed_string< N >::data_.

Referenced by gmp::fixed_string< N >::find().

Friends And Related Symbol Documentation

◆ operator<=>

template<std::size_t N>
consteval auto operator<=> ( fixed_string< N > const ,
fixed_string< N > const  
)
friend

Member Data Documentation

◆ data_

◆ npos

template<std::size_t N>
constexpr size_type gmp::fixed_string< N >::npos
staticconstexpr

Definition at line 38 of file fixed_string.hpp.


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