StringLiteral< Size > Struct Template Reference

CPP API: mio::StringLiteral< Size > Struct Template Reference

Wrapper for string literals, that allows passing them as template arguments. Should be used with constexpr. More...

#include <string_literal.h>

Public Types

using const_pointer = const value_type *
 
using pointer = value_type *
 
using size_type = size_t
 
using string_view_type = std::basic_string_view< value_type >
 
using value_type = char
 

Public Member Functions

constexpr pointer data ()
 Access the underlying array. Modification is only possible during compile time. More...
 
constexpr const_pointer data () const
 Access the underlying array. More...
 
constexpr bool empty () const
 Check whether the StringLiteral is empty. More...
 
constexpr operator string_view_type () const
 Implicit conversion from StringLiteral to string_view. More...
 
constexpr string_view_type string_view () const
 Get a string_view of this literal. Be mindful of the lifetime of the view object. More...
 
constexpr StringLiteral ()=default
 Create a string filled with '\0'. Mainly used by StringLiteral internally. More...
 
constexpr StringLiteral (const value_type(&string_literal)[size()+1])
 Construct a StringLiteral. More...
 

Static Public Member Functions

static constexpr size_type size ()
 The length of the StringLiteral (not counting the trailing '\0'). More...
 

Public Attributes

value_type value [size()+1] = {}
 Contains the actual characters. Access this through data() or string_view(). More...
 

Friends

template<size_type N>
constexpr friend auto operator+ (const StringLiteral &left, const StringLiteral< N > &right)
 Join two literals. More...
 
template<size_type N>
constexpr friend auto operator+ (const StringLiteral &left, const value_type(&right)[N])
 Join two literals. More...
 
template<size_type N>
constexpr friend auto operator+ (const value_type(&left)[N], const StringLiteral &right)
 Join two literals. More...
 
template<size_type N>
constexpr friend auto operator== (const StringLiteral &left, const StringLiteral< N > &right)
 Compare two literals. More...
 
template<size_type N>
constexpr friend auto operator== (const StringLiteral &left, const value_type(&right)[N])
 Compare two literals. More...
 

Detailed Description

template<size_t Size>
struct mio::StringLiteral< Size >

Wrapper for string literals, that allows passing them as template arguments. Should be used with constexpr.

Member Typedef Documentation

◆ const_pointer

template<size_t Size>
using mio::StringLiteral< Size >::const_pointer = const value_type*

◆ pointer

template<size_t Size>
using mio::StringLiteral< Size >::pointer = value_type*

◆ size_type

template<size_t Size>
using mio::StringLiteral< Size >::size_type = size_t

◆ string_view_type

template<size_t Size>
using mio::StringLiteral< Size >::string_view_type = std::basic_string_view<value_type>

◆ value_type

template<size_t Size>
using mio::StringLiteral< Size >::value_type = char

Constructor & Destructor Documentation

◆ StringLiteral() [1/2]

template<size_t Size>
constexpr mio::StringLiteral< Size >::StringLiteral ( const value_type(&)  string_literal[size()+1])
inlineconstexpr

Construct a StringLiteral.

Use as StringLiteral{"example string literal"}. The type of string is a const reference to a fixed-size char array.

Parameters
[in]string_literalAny string literal.

◆ StringLiteral() [2/2]

template<size_t Size>
constexpr mio::StringLiteral< Size >::StringLiteral ( )
constexprdefault

Create a string filled with '\0'. Mainly used by StringLiteral internally.

Member Function Documentation

◆ data() [1/2]

template<size_t Size>
constexpr pointer mio::StringLiteral< Size >::data ( )
inlineconstexpr

Access the underlying array. Modification is only possible during compile time.

◆ data() [2/2]

template<size_t Size>
constexpr const_pointer mio::StringLiteral< Size >::data ( ) const
inlineconstexpr

Access the underlying array.

◆ empty()

template<size_t Size>
constexpr bool mio::StringLiteral< Size >::empty ( ) const
inlineconstexpr

Check whether the StringLiteral is empty.

◆ operator string_view_type()

template<size_t Size>
constexpr mio::StringLiteral< Size >::operator string_view_type ( ) const
inlineconstexpr

Implicit conversion from StringLiteral to string_view.

◆ size()

template<size_t Size>
static constexpr size_type mio::StringLiteral< Size >::size ( )
inlinestaticconstexpr

The length of the StringLiteral (not counting the trailing '\0').

◆ string_view()

template<size_t Size>
constexpr string_view_type mio::StringLiteral< Size >::string_view ( ) const
inlineconstexpr

Get a string_view of this literal. Be mindful of the lifetime of the view object.

Friends And Related Function Documentation

◆ operator+ [1/3]

template<size_t Size>
template<size_type N>
constexpr friend auto operator+ ( const StringLiteral< Size > &  left,
const StringLiteral< N > &  right 
)
friend

Join two literals.

Parameters
[in]left,rightThe strings to join. Operands can be StringLiterals or regular string literals.
Returns
A new StringLiteral containing the joined string.

◆ operator+ [2/3]

template<size_t Size>
template<size_type N>
constexpr friend auto operator+ ( const StringLiteral< Size > &  left,
const value_type(&)  right[N] 
)
friend

Join two literals.

Parameters
[in]left,rightThe strings to join. Operands can be StringLiterals or regular string literals.
Returns
A new StringLiteral containing the joined string.

◆ operator+ [3/3]

template<size_t Size>
template<size_type N>
constexpr friend auto operator+ ( const value_type(&)  left[N],
const StringLiteral< Size > &  right 
)
friend

Join two literals.

Parameters
[in]left,rightThe strings to join. Operands can be StringLiterals or regular string literals.
Returns
A new StringLiteral containing the joined string.

◆ operator== [1/2]

template<size_t Size>
template<size_type N>
constexpr friend auto operator== ( const StringLiteral< Size > &  left,
const StringLiteral< N > &  right 
)
friend

Compare two literals.

Parameters
[in]left,rightThe strings to compare. Operands can be StringLiterals or regular string literals.
Returns
Whether both strings are the same.

◆ operator== [2/2]

template<size_t Size>
template<size_type N>
constexpr friend auto operator== ( const StringLiteral< Size > &  left,
const value_type(&)  right[N] 
)
friend

Compare two literals.

Parameters
[in]left,rightThe strings to compare. Operands can be StringLiterals or regular string literals.
Returns
Whether both strings are the same.

Member Data Documentation

◆ value

template<size_t Size>
value_type mio::StringLiteral< Size >::value[size()+1] = {}

Contains the actual characters. Access this through data() or string_view().