|
dimval 0.2.0
Modern C++23 header-only library of dimensional values (units, measures, ranges)
|
A value paired at the type level with a unit tag. More...
#include <unit.hpp>


Public Member Functions | |
| constexpr | UnitValue (T value) noexcept |
Implicit conversion from the numeric type — enables MeterValue distance = 1.78; style construction. | |
| UnitDescriptor | descriptor () const noexcept override |
Full descriptor — read individual fields (descriptor().id, ...) from here. | |
| double | numeric_as_double () const noexcept override |
| Numeric value as a double (lossy for >double types). | |
| std::string | to_string () const override |
Render <value> <symbol> (or whatever the descriptor's formatter dictates). | |
| std::string | to_formatted_string () const override |
| Render with the descriptor's default precision applied. | |
| std::unique_ptr< IUnitValue > | clone () const override |
| Deep copy as the interface type — the moral equivalent of a virtual copy ctor. | |
Static Public Member Functions | |
| static std::shared_ptr< UnitValue > | of (T value) |
Heap-allocated shared-owned factory: auto p = MeterValue::of(1.78); For a stack value, just construct directly (MeterValue v = 1.78). | |
| static std::unique_ptr< UnitValue > | unique (T value) |
Heap-allocated unique-owned factory: auto p = MeterValue::unique(1.78); | |
| static std::expected< UnitValue, ParseError > | parse (const std::string_view input) |
| Parse "42.5 m" → UnitValue<U,T>. | |
A value paired at the type level with a unit tag.
| U | a unit struct that derives from UnitBase (see DIMVAL_DEFINE_UNIT). |
| T | a numeric type. Defaults to double. |
Operators are restricted to same-unit + scalar to prevent silent mixing of incompatible quantities. Use dimval::convert<ToUnit>(v) to bridge between units of the same kind.
|
inlineconstexprnoexcept |
Implicit conversion from the numeric type — enables MeterValue distance = 1.78; style construction.
Safe because the unit tag type already prevents cross-unit assignments.
|
inlinestatic |
Parse "42.5 m" → UnitValue<U,T>.
The trailing symbol must match the unit's id, symbol, or short_name; otherwise returns ParseErrorCode::UnitMismatch. Mirrors dimval::parse_unit_value<U,T>.