dimval 0.2.0
Modern C++23 header-only library of dimensional values (units, measures, ranges)
Loading...
Searching...
No Matches
traits.hpp
Go to the documentation of this file.
1#pragma once
2
10
11#include <dimval/base.hpp>
12#include <dimval/descriptor.hpp>
13
14#include <type_traits>
15
16namespace dimval {
17
19template <typename U>
20concept UnitLike = std::is_base_of_v<UnitTag, U>;
21
23template <typename M>
24concept MeasureLike = std::is_base_of_v<MeasureTag, M>;
25
27template <UnitLike U>
28[[nodiscard]] constexpr UnitDescriptor unit_descriptor_of() noexcept {
29 return U::descriptor();
30}
31
33template <MeasureLike M>
34[[nodiscard]] constexpr MeasureDescriptor measure_descriptor_of() noexcept {
35 return M::descriptor();
36}
37
39template <UnitLike A, UnitLike B>
40[[nodiscard]] constexpr bool units_compatible() noexcept {
41 return A::kind == B::kind;
42}
43
45template <MeasureLike M, UnitLike U>
46[[nodiscard]] constexpr bool measure_uses_unit() noexcept {
47 return std::is_same_v<typename M::base_unit_t, U>;
48}
49
50} // namespace dimval
CRTP bases that turn unit/measure tag structs into self-describing types.
Concept satisfied by any struct that inherits from MeasureBase.
Definition traits.hpp:24
Concept satisfied by any struct that inherits from UnitBase.
Definition traits.hpp:20
Runtime metadata structs for units and measures.
Runtime metadata for a measure (a semantic specialization of a unit).
Definition descriptor.hpp:54
Runtime metadata for a unit.
Definition descriptor.hpp:29
constexpr bool measure_uses_unit() noexcept
True iff a measure's base unit is the given unit.
Definition traits.hpp:46
constexpr UnitDescriptor unit_descriptor_of() noexcept
Convenience accessor: descriptor of a unit struct.
Definition traits.hpp:28
constexpr MeasureDescriptor measure_descriptor_of() noexcept
Convenience accessor: descriptor of a measure struct.
Definition traits.hpp:34
constexpr bool units_compatible() noexcept
True iff two unit structs share the same kind (and therefore convert).
Definition traits.hpp:40