diff --git a/src/include/units/bits/deduced_unit.h b/src/include/units/bits/deduced_unit.h index 9f36466b..82a28fc6 100644 --- a/src/include/units/bits/deduced_unit.h +++ b/src/include/units/bits/deduced_unit.h @@ -66,6 +66,6 @@ struct derived_ratio, U, URest...> { template using deduced_unit = - scaled_unit::ratio>; + scaled_unit::ratio, typename D::coherent_unit::reference>; } // namespace units::detail diff --git a/src/include/units/bits/dimension_op.h b/src/include/units/bits/dimension_op.h index 6ca7122e..6089dba6 100644 --- a/src/include/units/bits/dimension_op.h +++ b/src/include/units/bits/dimension_op.h @@ -71,8 +71,8 @@ inline constexpr bool equivalent_dim = detail::equivalent_dim_impl::valu * @tparam Es zero or more exponents of a derived dimension */ template -struct unknown_dimension : derived_dimension, scaled_unit>, Es...> { - using coherent_unit = scaled_unit>; +struct unknown_dimension : derived_dimension, scaled_unit, unknown_unit>, Es...> { + using coherent_unit = scaled_unit, unknown_unit>; }; namespace detail { diff --git a/src/include/units/concepts.h b/src/include/units/concepts.h index efc1fb51..00801715 100644 --- a/src/include/units/concepts.h +++ b/src/include/units/concepts.h @@ -82,7 +82,7 @@ template concept UnitRatio = Ratio && (R::num * R::den > 0); // Unit -template +template struct scaled_unit; template diff --git a/src/include/units/unit.h b/src/include/units/unit.h index c465c4c8..7ce63081 100644 --- a/src/include/units/unit.h +++ b/src/include/units/unit.h @@ -49,14 +49,14 @@ namespace units { * @tparam U a unit to use as a reference for this dimension * @tparam R a ratio of a reference unit */ -template -struct scaled_unit : downcast_base> { - using reference = U; +template +struct scaled_unit : downcast_base> { using ratio = R; + using reference = U; }; template -using downcast_unit = downcast::reference, R>>; +using downcast_unit = downcast::reference>>; template struct same_unit_reference : std::is_same {}; @@ -70,7 +70,7 @@ struct same_unit_reference : std::is_same -struct unit : downcast_child>> { +struct unit : downcast_child, Child>> { static constexpr bool is_named = false; using prefix_type = no_prefix; }; @@ -95,7 +95,7 @@ struct unknown_unit : unit {}; * @tparam PT no_prefix or a type of prefix family */ template -struct named_unit : downcast_child>> { +struct named_unit : downcast_child, Child>> { static constexpr bool is_named = true; static constexpr auto symbol = Symbol; using prefix_type = PT; @@ -116,7 +116,7 @@ struct named_unit : downcast_child>> { * @tparam U a reference unit to scale */ template -struct named_scaled_unit : downcast_child>> { +struct named_scaled_unit : downcast_child, typename U::reference>> { static constexpr bool is_named = true; static constexpr auto symbol = Symbol; using prefix_type = PT; @@ -140,7 +140,7 @@ template // ratio_multiply, // typename U::reference> {}; struct prefixed_unit : - downcast_child>> { + downcast_child, typename U::reference>> { static constexpr bool is_named = true; static constexpr auto symbol = P::symbol + U::symbol; using prefix_type = P::prefix_type; diff --git a/test/unit_test/runtime/fmt_test.cpp b/test/unit_test/runtime/fmt_test.cpp index b3123215..c4c3aa03 100644 --- a/test/unit_test/runtime/fmt_test.cpp +++ b/test/unit_test/runtime/fmt_test.cpp @@ -110,7 +110,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") { SECTION("in terms of base units") { - const length>> q(123); + const length, metre>> q(123); stream << q; SECTION("iostream") @@ -131,7 +131,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]") SECTION("in terms of derived units") { - const energy>> q(60); + const energy, joule>> q(60); stream << q; SECTION("iostream") diff --git a/test/unit_test/static/quantity_test.cpp b/test/unit_test/static/quantity_test.cpp index ff4edce3..7dd965f3 100644 --- a/test/unit_test/static/quantity_test.cpp +++ b/test/unit_test/static/quantity_test.cpp @@ -112,7 +112,7 @@ using namespace units::si; // constexpr quantity error(0); // should not compile (unit of a different dimension) // constexpr quantity> error(0); // should not compile (quantity used as Rep) // constexpr quantity error(0); // should not compile (reordered arguments) -// constexpr quantity>, int> error(0); // should not compile (negative unit ratio) +// constexpr quantity, metre>, int> error(0); // should not compile (negative unit ratio) // member types @@ -236,23 +236,23 @@ static_assert(std::is_same_v()), length() * si::time()), length>); static_assert( - std::is_same_v() * si::time()), length>, int>>); + std::is_same_v() * si::time()), length, metre>, int>>); static_assert(std::is_same_v() * si::time()), - quantity, units::exp>, scaled_unit>>>); + quantity, units::exp>, scaled_unit, unknown_unit>>>); static_assert(std::is_same_v()), frequency>); -static_assert(std::is_same_v()), frequency>, int>>); +static_assert(std::is_same_v()), frequency, hertz>, int>>); static_assert(std::is_same_v()), si::time>); static_assert(std::is_same_v()), - quantity>, scaled_unit>>>); + quantity>, scaled_unit, unknown_unit>>>); static_assert(std::is_same_v() / 1.0), length>); static_assert(std::is_same_v() / length()), double>); static_assert(std::is_same_v() / length()), double>); static_assert( std::is_same_v() / si::time()), velocity>); static_assert( - std::is_same_v() / si::time()), velocity>>>); + std::is_same_v() / si::time()), velocity, metre_per_second>>>); static_assert(std::is_same_v() / length()), - quantity, units::exp>, scaled_unit>>>); + quantity, units::exp>, scaled_unit, unknown_unit>>>); static_assert(std::is_same_v() % short(1)), length>); static_assert(std::is_same_v() % length(1)), length>); @@ -316,7 +316,7 @@ static_assert(std::is_same_v, lengt // quantity_cast -static_assert(std::is_same_v>>(2km))::unit, metre>); +static_assert(std::is_same_v, metre>>(2km))::unit, metre>); static_assert(quantity_cast>(2km).count() == 2000); static_assert(quantity_cast>(2000m).count() == 2); diff --git a/test/unit_test/static/si_test.cpp b/test/unit_test/static/si_test.cpp index 1fec088e..19a3cb8e 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -191,7 +191,7 @@ static_assert(10V * 1F == 10C); // velocity -static_assert(std::is_same_v>, std::int64_t>>); +static_assert(std::is_same_v, metre_per_second>, std::int64_t>>); static_assert(10m / 5s == 2mps); static_assert(10 / 5s * 1m == 2mps); diff --git a/test/unit_test/static/unit_test.cpp b/test/unit_test/static/unit_test.cpp index 84dc5e10..f7b7aa42 100644 --- a/test/unit_test/static/unit_test.cpp +++ b/test/unit_test/static/unit_test.cpp @@ -45,11 +45,11 @@ struct metre_per_second : unit {}; struct dim_velocity : derived_dimension, exp> {}; struct kilometre_per_hour : deduced_unit {}; -static_assert(std::is_same_v>>, metre>); -static_assert(std::is_same_v>>, centimetre>); -static_assert(std::is_same_v>>, yard>); -static_assert(std::is_same_v>>>, foot>); -static_assert(std::is_same_v>>, kilometre_per_hour>); +static_assert(std::is_same_v, metre>>, metre>); +static_assert(std::is_same_v, metre>>, centimetre>); +static_assert(std::is_same_v, metre>>, yard>); +static_assert(std::is_same_v>, metre>>, foot>); +static_assert(std::is_same_v, metre_per_second>>, kilometre_per_hour>); static_assert(centimetre::symbol == "cm"); static_assert(kilometre::symbol == "km");