dimval 0.2.0
Modern C++23 header-only library of dimensional values (units, measures, ranges)
Loading...
Searching...
No Matches
unit.hpp File Reference

UnitValue<U,T>: a strongly-typed value carrying a compile-time unit tag. More...

#include <dimval/core.hpp>
#include <dimval/interface.hpp>
#include <dimval/parse_detail.hpp>
#include <dimval/traits.hpp>
#include <commons/color.hpp>
#include <commons/icon.hpp>
#include <expected>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <type_traits>
Include dependency graph for unit.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  dimval::UnitValue< U, T >
 A value paired at the type level with a unit tag. More...
 

Functions

template<UnitLike U, NumericValue T>
constexpr T dimval::operator/ (const UnitValue< U, T > &a, const UnitValue< U, T > &b) noexcept
 Dimensionless ratio of two same-unit values.
 
template<UnitLike To, UnitLike From, NumericValue T>
constexpr UnitValue< To, T > dimval::convert (const UnitValue< From, T > &v) noexcept
 Convert a UnitValue between units of the same kind.
 
template<UnitLike U, NumericValue T = double>
constexpr UnitValue< U, T > dimval::unit_value (T v) noexcept
 Sugar: produce a UnitValue from a scalar literal.
 

Detailed Description

UnitValue<U,T>: a strongly-typed value carrying a compile-time unit tag.

UnitValue<U,T> inherits from IUnitValue so it can be stored in a polymorphic container (std::unique_ptr<IUnitValue>, etc.). The vtable adds 8 bytes per instance; arithmetic itself remains constexpr.

Function Documentation

◆ convert()

template<UnitLike To, UnitLike From, NumericValue T>
constexpr UnitValue< To, T > dimval::convert ( const UnitValue< From, T > &  v)
constexprnoexcept

Convert a UnitValue between units of the same kind.

Compile error when From and To live in different kinds.