commons 0.1.5
Header-only C++23 library of common/shared types for the C++ libraries
Loading...
Searching...
No Matches
literals.hpp File Reference

User-defined literals for the Commons value types: _color and _icon. More...

#include <commons/color.hpp>
#include <commons/icon.hpp>
#include <cstddef>
#include <string_view>
Include dependency graph for literals.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

consteval Color comms::literals::operator""_color (const char *str, const std::size_t len)
 Compile-time color literal, e.g.
 
consteval Icon comms::literals::operator""_icon (const char *str, const std::size_t len)
 Compile-time icon literal, e.g.
 

Detailed Description

User-defined literals for the Commons value types: _color and _icon.

Both live in namespace comms::literals — bring them in with using namespace comms::literals;. Each is consteval, so a malformed literal is a compile error (the throw is never reached in a well-formed constant expression). They are kept out of color.hpp/icon.hpp so a translation unit pays for the literal operators only when it asks for them; the umbrella commons/commons.hpp includes this header.

Function Documentation

◆ operator""_color()

consteval Color comms::literals::operator""_color ( const char *  str,
const std::size_t  len 
)

Compile-time color literal, e.g.

"#6366f1"_color. Accepts the hex forms of Color::parse_hex (#rgb, #rgba, #rrggbb, #rrggbbaa, the # optional). Being consteval, a malformed literal is a compile error.

◆ operator""_icon()

consteval Icon comms::literals::operator""_icon ( const char *  str,
const std::size_t  len 
)

Compile-time icon literal, e.g.

"mdi:abacus"_icon. Accepts any well-formed Iconify set:name value (see Icon::parse: exactly one :, non-empty parts, within Icon::capacity). Being consteval, a malformed literal is a compile error.