dimval 0.2.0
Modern C++23 header-only library of dimensional values (units, measures, ranges)
Loading...
Searching...
No Matches
dimval::MeasureValue< M, T > Struct Template Reference

A value carrying both a measure tag and a unit tag. More...

#include <measure.hpp>

Inheritance diagram for dimval::MeasureValue< M, T >:
Collaboration diagram for dimval::MeasureValue< M, T >:

Public Member Functions

constexpr MeasureValue (T value) noexcept
 Implicit conversion from the numeric type — enables DistanceValue d = 1500.0; style construction.
 
constexpr UnitValue< unit_t, T > as_unit_value () const noexcept
 Drop the measure tag and expose the underlying UnitValue.
 
MeasureDescriptor descriptor () const noexcept override
 Measure descriptor — read fields like descriptor().name from here.
 
UnitDescriptor unit_descriptor () const noexcept override
 Underlying unit's descriptor — read unit_descriptor().id, .symbol, etc.
 

Static Public Member Functions

static std::shared_ptr< MeasureValueof (T value)
 Heap-allocated shared-owned factory: auto d = DistanceValue::of(1500.0); For a stack value, just construct directly (DistanceValue d = 1500.0).
 
static std::unique_ptr< MeasureValueunique (T value)
 Heap-allocated unique-owned factory.
 
static std::expected< MeasureValue, ParseErrorparse (std::string_view input)
 Parse "100 m" → MeasureValue<M,T>. Forwards to UnitValue<base_unit_t,T>::parse.
 

Detailed Description

template<MeasureLike M, NumericValue T = double>
struct dimval::MeasureValue< M, T >

A value carrying both a measure tag and a unit tag.

The measure refines the meaning of a value beyond its physical unit. For example, Distance and Length are both stored in meters but have distinct semantics. The measure's base unit is fixed at the type level.

Template Parameters
Ma measure struct that derives from MeasureBase.
Ta numeric type. Defaults to double.

Constructor & Destructor Documentation

◆ MeasureValue()

template<MeasureLike M, NumericValue T = double>
constexpr dimval::MeasureValue< M, T >::MeasureValue ( value)
inlineconstexprnoexcept

Implicit conversion from the numeric type — enables DistanceValue d = 1500.0; style construction.

Safe because the measure tag type already prevents cross-measure assignments.


The documentation for this struct was generated from the following files: