refl-cpp
refl::util::const_string< N > Struct Template Reference

Represents a compile-time string. More...

#include <refl.hpp>

Public Member Functions

constexpr const_string () noexcept
 Creates an empty const_string. More...
 
constexpr const_string (const const_string< N > &other) noexcept
 Creates a copy of a const_string. More...
 
constexpr const_string (const char(&data)[N+1]) noexcept
 Creates a const_string by copying the contents of data. More...
 
constexpr operator const char * () const noexcept
 Explicitly converts to const char*. More...
 
 operator std::string () const noexcept
 Explicitly converts to std::string. More...
 
constexpr const char * c_str () const noexcept
 Returns a pointer to the contained zero-terminated string. More...
 
std::string str () const noexcept
 Returns the contained string as an std::string. More...
 
template<size_t Pos, size_t Count = npos>
constexpr auto substr () const noexcept
 A constexpr version of std::string::substr. More...
 
constexpr auto find (char ch, size_t pos=0) const noexcept
 Searches the string for the first occurrence of the character and returns its position. More...
 
constexpr auto rfind (char ch, size_t pos=npos) const noexcept
 Searches the string for the last occurrence of the character and returns its position. More...
 

Public Attributes

char data [N+1]
 The statically-sized character buffer used for storing the string. More...
 

Static Public Attributes

static constexpr size_t npos = static_cast<size_t>(-1)
 The largest positive value size_t can hold. More...
 
static constexpr size_t size = N
 The length of the string excluding the terminating '\0' character. More...
 

Detailed Description

template<size_t N>
struct refl::util::const_string< N >

Represents a compile-time string.

Used in refl-cpp for representing names of reflected types and members. Supports constexpr concatenation and substring, and is explicitly-convertible to const char* and std::string. REFL_MAKE_CONST_STRING can be used to create an instance from a literal string.

@typeparam <N> The length of the string excluding the terminating '\0' character.

See also
refl::descriptor::base_member_descriptor::name

Constructor & Destructor Documentation

◆ const_string() [1/3]

template<size_t N>
constexpr refl::util::const_string< N >::const_string ( )
inlineconstexprnoexcept

Creates an empty const_string.

◆ const_string() [2/3]

template<size_t N>
constexpr refl::util::const_string< N >::const_string ( const const_string< N > &  other)
inlineconstexprnoexcept

Creates a copy of a const_string.

◆ const_string() [3/3]

template<size_t N>
constexpr refl::util::const_string< N >::const_string ( const char(&)  data[N+1])
inlineconstexprnoexcept

Creates a const_string by copying the contents of data.

Member Function Documentation

◆ c_str()

template<size_t N>
constexpr const char* refl::util::const_string< N >::c_str ( ) const
inlineconstexprnoexcept

Returns a pointer to the contained zero-terminated string.

◆ find()

template<size_t N>
constexpr auto refl::util::const_string< N >::find ( char  ch,
size_t  pos = 0 
) const
inlineconstexprnoexcept

Searches the string for the first occurrence of the character and returns its position.

make_const_string("Hello, World!").find('e') -> 1
make_const_string("Hello, World!").find('z') -> static_cast<size_t>(-1)

◆ operator const char *()

template<size_t N>
constexpr refl::util::const_string< N >::operator const char * ( ) const
inlineexplicitconstexprnoexcept

Explicitly converts to const char*.

◆ operator std::string()

template<size_t N>
refl::util::const_string< N >::operator std::string ( ) const
inlineexplicitnoexcept

Explicitly converts to std::string.

◆ rfind()

template<size_t N>
constexpr auto refl::util::const_string< N >::rfind ( char  ch,
size_t  pos = npos 
) const
inlineconstexprnoexcept

Searches the string for the last occurrence of the character and returns its position.

make_const_string("Hello, World!").rfind('o') -> 8
make_const_string("Hello, World!").rfind('z') -> static_cast<size_t>(-1)

◆ str()

template<size_t N>
std::string refl::util::const_string< N >::str ( ) const
inlinenoexcept

Returns the contained string as an std::string.

◆ substr()

template<size_t N>
template<size_t Pos, size_t Count = npos>
constexpr auto refl::util::const_string< N >::substr ( ) const
inlineconstexprnoexcept

A constexpr version of std::string::substr.

make_const_string("Hello, World!").template substr<0, 4>() -> (const_string<4>) "Hell"
make_const_string("Hello, World!").template substr<1, 4>() -> (const_string<3>) "ell"

Member Data Documentation

◆ data

template<size_t N>
char refl::util::const_string< N >::data[N+1]

The statically-sized character buffer used for storing the string.

◆ npos

template<size_t N>
constexpr size_t refl::util::const_string< N >::npos = static_cast<size_t>(-1)
staticconstexpr

The largest positive value size_t can hold.

◆ size

template<size_t N>
constexpr size_t refl::util::const_string< N >::size = N
staticconstexpr

The length of the string excluding the terminating '\0' character.


The documentation for this struct was generated from the following file:
refl::util::make_const_string
constexpr const_string< 0 > make_const_string() noexcept
Creates an empty instance of const_string<N>
Definition: refl.hpp:258