commons 0.1.5
Header-only C++23 library of common/shared types for the C++ libraries
Loading...
Searching...
No Matches
literals.hpp
Go to the documentation of this file.
1#pragma once
2
13
14#include <commons/color.hpp>
15#include <commons/icon.hpp>
16
17#include <cstddef>
18#include <string_view>
19
20namespace comms::literals {
21
25consteval Color operator""_color(const char* str, const std::size_t len) {
26 const auto c = Color::parse_hex(std::string_view{str, len});
27 if (!c) {
28 throw "commons: invalid color literal";
29 }
30 return *c;
31}
32
37consteval Icon operator""_icon(const char* str, const std::size_t len) {
38 const auto i = Icon::parse(std::string_view{str, len});
39 if (!i) {
40 throw "commons: invalid icon literal";
41 }
42 return *i;
43}
44
45} // namespace comms::literals
A tiny RGBA color container with rich, mostly-constexpr color manipulation, plus the Hsl/Hsv model st...
A tiny value type carrying an Iconify icon identifier such as mdi:abacus (a set:name pair).
An 8-bit-per-channel RGBA color. Default is opaque black.
Definition color.hpp:347
static constexpr std::optional< Color > parse_hex(std::string_view s)
Parse a hex color: #rgb, #rgba, #rrggbb, or #rrggbbaa (the leading # is optional).
Definition color.hpp:759
An Iconify icon identifier — a set:name pair such as mdi:abacus.
Definition icon.hpp:43
static constexpr std::optional< Icon > parse(const std::string_view value)
Non-throwing validation: returns the Icon for a well-formed value (exactly one :, non-empty set and n...
Definition icon.hpp:96