native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
Interned static strings

Classes

class  native::basic_static_string< CharT, Traits >
 A view of one complete interned string, with its length retained. The five standard character widths are supported by the _ss literal. Embedded NUL characters remain part of its length. Default construction selects the canonical empty string. The view constructor is a compatibility escape hatch, not a runtime interning operation: arbitrary string_view storage violates the lifetime and pointer-equality/hash contract. More...
class  native::static_c_string
 A pointer-sized view of a complete interned char string. Length is recovered from the first NUL. Use static_string when embedded NULs matter or repeated end/length scans are undesirable. Default construction selects the canonical empty string; equality compares addresses. More...

Functions

template<detail::static_string_literal Text>
consteval auto native::operator""_ss () noexcept
template<detail::static_string_literal Text>
requires std::same_as<typename decltype(Text)::char_type, char>
consteval static_c_string native::operator""_scs () noexcept

Detailed Description

Literal-backed storage has program lifetime and no allocation. With standard character traits, equality and hashing use the interned storage address.

void common_utilities() {
using namespace native;
auto first = "vector"_ss;
auto second = "vector"_ss;
check(first == second && first.data() == second.data());
check(std::hash<static_string>{}(first) == std::hash<static_string>{}(second));
auto owned = native::dup(first.data());
if (owned) check(std::string_view(owned.get()) == "vector");
check(!native::type_of(first).empty());
auto half = native::fp16(1.5f);
check(static_cast<float>(half) == 1.5f);
}

Function Documentation

◆ operator""_scs()

template<detail::static_string_literal Text>
requires std::same_as<typename decltype(Text)::char_type, char>
static_c_string native::operator""_scs ( )
constevalexportnoexcept

Intern a char literal as a pointer-sized C string.

Precondition
No embedded NUL occurs before the literal's final terminator.

Definition at line 453 of file native.static_string.ccm.

◆ operator""_ss()

template<detail::static_string_literal Text>
auto native::operator""_ss ( )
constevalexportnoexcept

Intern a standard-width literal, retaining embedded NUL characters in its length.

void common_utilities() {
using namespace native;
auto first = "vector"_ss;
auto second = "vector"_ss;
check(first == second && first.data() == second.data());
check(std::hash<static_string>{}(first) == std::hash<static_string>{}(second));
auto owned = native::dup(first.data());
if (owned) check(std::string_view(owned.get()) == "vector");
check(!native::type_of(first).empty());
auto half = native::fp16(1.5f);
check(static_cast<float>(half) == 1.5f);
}

Definition at line 441 of file native.static_string.ccm.