Unit Conversion and Dimensional Analysis Library 3.6.1
A compile-time, header-only C++23 dimensional-analysis library
Loading...
Searching...
No Matches
units::affine::basic_kind< Tag, U > Class Template Reference

A quantity distinguished by a string TAG — a "kind of quantity" that shares a unit and a dimension with others but is semantically distinct (radial vs. More...

#include <kind.h>

Public Types

using unit_type = U
using underlying_type = typename traits::unit_traits<U>::underlying_type
 < the wrapped unit type

Public Member Functions

constexpr basic_kind () noexcept=default
 < the wrapped unit's numeric type
constexpr basic_kind (const U &value) noexcept
 A plain unit converts INTO a kind by copy-initialization or assignment — the intent (this value IS a Tag kind) is explicit at the assignment site, so this ctor is non-explicit.
constexpr basic_kind (underlying_type value) noexcept
 Construct from the underlying numeric value (in U's own unit) — explicit, since a bare number carries no unit intent.
constexpr basic_kindoperator= (const U &value) noexcept
 Assign a plain unit into this kind (same clear-intent conversion as copy-initialization).
constexpr auto value () const noexcept
 The numeric value in its own unit.
constexpr auto raw () const noexcept
 The raw (linearized) value.
constexpr auto to_linearized () const noexcept
 The linearized value (as the wrapped unit's to_linearized()).
constexpr const char * abbreviation () const noexcept
 The abbreviation is the wrapped unit's (a kind does not change the abbreviation — "m" for a kind<"radial", meters<double>>).
std::string name () const
 The name is the tag followed by the wrapped unit's name — e.g. "radial meters".
template<ArithmeticType Arithmetic>
constexpr Arithmetic to () const noexcept
 Express this kind's value as a plain arithmetic type — the numeric value in its own unit, matching the wrapped unit's to<Arithmetic>().
template<UnitType PlainTarget>
requires traits::is_same_dimension_unit_v<U, PlainTarget>
constexpr PlainTarget to () const noexcept
 Express this kind as a PLAIN unit of the same dimension — unwraps (dropping the tag), scale-only.
template<KindType WrapperTarget>
requires (WrapperTarget::tag() == Tag && traits::is_same_dimension_unit_v<U, typename WrapperTarget::unit_type>)
constexpr WrapperTarget to () const noexcept
 Express this kind as another kind<Tag, V> — the tag is KEPT (radial metres → radial feet).

Static Public Member Functions

static constexpr auto tag () noexcept
 The tag of this kind.

Detailed Description

template<fixed_string Tag, UnitType U>
class units::affine::basic_kind< Tag, U >

A quantity distinguished by a string TAG — a "kind of quantity" that shares a unit and a dimension with others but is semantically distinct (radial vs.

straight-line distance, torque vs. energy). Two DIFFERENT tags never interoperate; the same tag does.

Template Parameters
Taga fixed_string naming the kind (e.g. "radial").
Uthe wrapped unit type.

Users spell it units::kind<Tag, U> (the top-level alias); this is the underlying class the alias resolves to. A kind carries no datum; it wraps a plain magnitude and converts by scale like the unit it wraps, keeping its tag. Cross to the plain unit only explicitly, via to<PlainUnit>().

Constructor & Destructor Documentation

◆ basic_kind()

template<fixed_string Tag, UnitType U>
units::affine::basic_kind< Tag, U >::basic_kind ( const U & value)
inlineconstexprnoexcept

A plain unit converts INTO a kind by copy-initialization or assignment — the intent (this value IS a Tag kind) is explicit at the assignment site, so this ctor is non-explicit.

What is NOT allowed is MIXING a plain unit with a kind in arithmetic (aKind + plainUnit); that stays ill-formed, so a value only ever enters a kind where you name it, never silently mid-expression.

Member Function Documentation

◆ to() [1/2]

template<fixed_string Tag, UnitType U>
template<KindType WrapperTarget>
requires (WrapperTarget::tag() == Tag && traits::is_same_dimension_unit_v<U, typename WrapperTarget::unit_type>)
WrapperTarget units::affine::basic_kind< Tag, U >::to ( ) const
inlineconstexprnoexcept

Express this kind as another kind<Tag, V> — the tag is KEPT (radial metres → radial feet).

Only a SAME-tag kind target is viable; a different-tag kind target has no matching overload (converting a radial distance into a straight-line distance is meaningless).

◆ to() [2/2]

template<fixed_string Tag, UnitType U>
template<UnitType PlainTarget>
requires traits::is_same_dimension_unit_v<U, PlainTarget>
PlainTarget units::affine::basic_kind< Tag, U >::to ( ) const
inlineconstexprnoexcept

Express this kind as a PLAIN unit of the same dimension — unwraps (dropping the tag), scale-only.

radial.to<feet<double>>() is plain feet; .to<meters<double>>() is the plain wrapped value.


The documentation for this class was generated from the following file:
  • /home/runner/work/units/units/include/units/kind.h