38 constexpr NamedUnit(std::string_view lname, std::string_view sname,
Unit<> u) noexcept
44namespace shamunits::details {
48 std::span<const NamedUnit> registry, std::string_view name)
noexcept {
50 if (e.long_name == name || e.short_name == name) {
59 std::span<const NamedUnit> registry,
60 std::string_view name,
61 std::string_view kind =
"unit") {
65 throw std::invalid_argument(
66 "unknown " + std::string(kind) +
" name : '" + std::string(name) +
"'");
71 for (std::size_t i = 0; i < registry.size(); i++) {
76 for (std::size_t j = i + 1; j < registry.size(); j++) {
A physical unit as a value: its SI dimension and its magnitude in SI base units.
namespace containing the units library
constexpr const NamedUnit * find_named(std::span< const NamedUnit > registry, std::string_view name) noexcept
Entry whose long or short name is name, or nullptr.
Unit unit_from_name(std::span< const NamedUnit > registry, std::string_view name, std::string_view kind="unit")
Unit named name in registry; throws std::invalid_argument when unknown.
constexpr bool names_are_valid(std::span< const NamedUnit > registry) noexcept
True when no name is empty and no name appears twice, long and short names together.
One registry entry: a unit and the two names it can be looked up by.
Unit unit
the unit, always in the reference precision (double)
std::string_view short_name
e.g. "m", "au"
std::string_view long_name
e.g. "metre", "astronomical_unit"
constexpr NamedUnit(std::string_view lname, std::string_view sname, Unit<> u) noexcept
Constructor, so registry rows stay compact: {"metre", "m", metre}.
A unit: its dimension and its magnitude expressed in SI base units, in precision Tscal.