utf-42
Loading...
Searching...
No Matches
utf42::poly_enc Struct Reference

Container holding all character-encoded views of a string literal. More...

#include <utf42.h>

Collaboration diagram for utf42::poly_enc:

Public Member Functions

constexpr poly_enc (const basic_string_view< char > txt_char, const basic_string_view< wchar_t > txt_char_w, const basic_string_view< char16_t > txt_char_16, const basic_string_view< char32_t > txt_char_32) noexcept
 Constructs a polymorphic encoding container.
 
template<typename char_t >
constexpr basic_string_view< char_tvisit () const noexcept
 Selects the appropriate encoded string view for a given character type.
 
template<>
constexpr basic_string_view< charvisit () const noexcept
 
template<>
constexpr basic_string_view< wchar_tvisit () const noexcept
 
template<>
constexpr basic_string_view< char16_tvisit () const noexcept
 
template<>
constexpr basic_string_view< char32_tvisit () const noexcept
 

Public Attributes

basic_string_view< charTXT_CHAR
 Narrow character literal.
 
basic_string_view< wchar_tTXT_CHAR_W
 Wide character literal.
 
basic_string_view< char16_tTXT_CHAR_16
 UTF-16 character literal.
 
basic_string_view< char32_tTXT_CHAR_32
 UTF-32 character literal.
 

Detailed Description

Container holding all character-encoded views of a string literal.

Instances of this type are intended to be constructed only from string literals. Each member corresponds to a distinct literal encoding generated by the compiler.

No ownership is taken; all views refer directly to static storage.

Constructor & Destructor Documentation

◆ poly_enc()

constexpr utf42::poly_enc::poly_enc ( const basic_string_view< char txt_char,
const basic_string_view< wchar_t txt_char_w,
const basic_string_view< char16_t txt_char_16,
const basic_string_view< char32_t txt_char_32 
)
inlineconstexprnoexcept

Constructs a polymorphic encoding container.

Parameters
txt_charNarrow character string view.
txt_char_wWide character string view.
txt_char_8UTF-8 string view. Only defined if C++20 is available.
txt_char_16UTF-16 string view.
txt_char_32UTF-32 string view.

Member Function Documentation

◆ visit()

template<typename char_t >
constexpr basic_string_view< char_t > utf42::poly_enc::visit ( ) const
constexprnoexcept

Selects the appropriate encoded string view for a given character type.

This function is evaluated at compile time and returns a std::basic_string_view<char_t> referring to the correctly encoded literal stored in the provided poly_enc. Returns an empty string if the character type is not recognized.

Template Parameters
char_tDesired character type.
Returns
A string view of the requested character type or char_t"".

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