scaled_unit template parameters order fixed (sorry Oliver)

This commit is contained in:
Mateusz Pusz
2019-12-14 21:16:15 +01:00
parent 5ef0bb9a9f
commit 6596c15238
8 changed files with 28 additions and 28 deletions

View File

@@ -66,6 +66,6 @@ struct derived_ratio<exp_list<E, ERest...>, U, URest...> {
template<DerivedDimension D, Unit... Us> template<DerivedDimension D, Unit... Us>
using deduced_unit = using deduced_unit =
scaled_unit<typename D::coherent_unit::reference, typename detail::derived_ratio<typename D::recipe, Us...>::ratio>; scaled_unit<typename detail::derived_ratio<typename D::recipe, Us...>::ratio, typename D::coherent_unit::reference>;
} // namespace units::detail } // namespace units::detail

View File

@@ -71,8 +71,8 @@ inline constexpr bool equivalent_dim = detail::equivalent_dim_impl<D1, D2>::valu
* @tparam Es zero or more exponents of a derived dimension * @tparam Es zero or more exponents of a derived dimension
*/ */
template<Exponent... Es> template<Exponent... Es>
struct unknown_dimension : derived_dimension<unknown_dimension<Es...>, scaled_unit<unknown_unit, ratio<1>>, Es...> { struct unknown_dimension : derived_dimension<unknown_dimension<Es...>, scaled_unit<ratio<1>, unknown_unit>, Es...> {
using coherent_unit = scaled_unit<unknown_unit, ratio<1>>; using coherent_unit = scaled_unit<ratio<1>, unknown_unit>;
}; };
namespace detail { namespace detail {

View File

@@ -82,7 +82,7 @@ template<typename R>
concept UnitRatio = Ratio<R> && (R::num * R::den > 0); concept UnitRatio = Ratio<R> && (R::num * R::den > 0);
// Unit // Unit
template<typename U, UnitRatio R> template<UnitRatio R, typename U>
struct scaled_unit; struct scaled_unit;
template<typename T> template<typename T>

View File

@@ -49,14 +49,14 @@ namespace units {
* @tparam U a unit to use as a reference for this dimension * @tparam U a unit to use as a reference for this dimension
* @tparam R a ratio of a reference unit * @tparam R a ratio of a reference unit
*/ */
template<typename U, UnitRatio R> template<UnitRatio R, typename U>
struct scaled_unit : downcast_base<scaled_unit<U, R>> { struct scaled_unit : downcast_base<scaled_unit<R, U>> {
using reference = U;
using ratio = R; using ratio = R;
using reference = U;
}; };
template<Dimension D, UnitRatio R> template<Dimension D, UnitRatio R>
using downcast_unit = downcast<scaled_unit<typename dimension_unit<D>::reference, R>>; using downcast_unit = downcast<scaled_unit<R, typename dimension_unit<D>::reference>>;
template<Unit U1, Unit U2> template<Unit U1, Unit U2>
struct same_unit_reference : std::is_same<typename U1::reference, typename U2::reference> {}; struct same_unit_reference : std::is_same<typename U1::reference, typename U2::reference> {};
@@ -70,7 +70,7 @@ struct same_unit_reference : std::is_same<typename U1::reference, typename U2::r
* @tparam Child inherited class type used by the downcasting facility (CRTP Idiom) * @tparam Child inherited class type used by the downcasting facility (CRTP Idiom)
*/ */
template<typename Child> template<typename Child>
struct unit : downcast_child<Child, scaled_unit<Child, ratio<1>>> { struct unit : downcast_child<Child, scaled_unit<ratio<1>, Child>> {
static constexpr bool is_named = false; static constexpr bool is_named = false;
using prefix_type = no_prefix; using prefix_type = no_prefix;
}; };
@@ -95,7 +95,7 @@ struct unknown_unit : unit<unknown_unit> {};
* @tparam PT no_prefix or a type of prefix family * @tparam PT no_prefix or a type of prefix family
*/ */
template<typename Child, basic_fixed_string Symbol, PrefixType PT> template<typename Child, basic_fixed_string Symbol, PrefixType PT>
struct named_unit : downcast_child<Child, scaled_unit<Child, ratio<1>>> { struct named_unit : downcast_child<Child, scaled_unit<ratio<1>, Child>> {
static constexpr bool is_named = true; static constexpr bool is_named = true;
static constexpr auto symbol = Symbol; static constexpr auto symbol = Symbol;
using prefix_type = PT; using prefix_type = PT;
@@ -116,7 +116,7 @@ struct named_unit : downcast_child<Child, scaled_unit<Child, ratio<1>>> {
* @tparam U a reference unit to scale * @tparam U a reference unit to scale
*/ */
template<typename Child, basic_fixed_string Symbol, PrefixType PT, UnitRatio R, Unit U> template<typename Child, basic_fixed_string Symbol, PrefixType PT, UnitRatio R, Unit U>
struct named_scaled_unit : downcast_child<Child, scaled_unit<typename U::reference, ratio_multiply<R, typename U::ratio>>> { struct named_scaled_unit : downcast_child<Child, scaled_unit<ratio_multiply<R, typename U::ratio>, typename U::reference>> {
static constexpr bool is_named = true; static constexpr bool is_named = true;
static constexpr auto symbol = Symbol; static constexpr auto symbol = Symbol;
using prefix_type = PT; using prefix_type = PT;
@@ -140,7 +140,7 @@ template<typename Child, Prefix P, Unit U>
// ratio_multiply<typename P::ratio, typename U::ratio>, // ratio_multiply<typename P::ratio, typename U::ratio>,
// typename U::reference> {}; // typename U::reference> {};
struct prefixed_unit : struct prefixed_unit :
downcast_child<Child, scaled_unit<typename U::reference, ratio_multiply<typename P::ratio, typename U::ratio>>> { downcast_child<Child, scaled_unit<ratio_multiply<typename P::ratio, typename U::ratio>, typename U::reference>> {
static constexpr bool is_named = true; static constexpr bool is_named = true;
static constexpr auto symbol = P::symbol + U::symbol; static constexpr auto symbol = P::symbol + U::symbol;
using prefix_type = P::prefix_type; using prefix_type = P::prefix_type;

View File

@@ -110,7 +110,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]")
{ {
SECTION("in terms of base units") SECTION("in terms of base units")
{ {
const length<scaled_unit<metre, ratio<1'000'000>>> q(123); const length<scaled_unit<ratio<1'000'000>, metre>> q(123);
stream << q; stream << q;
SECTION("iostream") SECTION("iostream")
@@ -131,7 +131,7 @@ TEST_CASE("operator<< on a quantity", "[text][ostream][fmt]")
SECTION("in terms of derived units") SECTION("in terms of derived units")
{ {
const energy<scaled_unit<joule, ratio<1, 100>>> q(60); const energy<scaled_unit<ratio<1, 100>, joule>> q(60);
stream << q; stream << q;
SECTION("iostream") SECTION("iostream")

View File

@@ -112,7 +112,7 @@ using namespace units::si;
// constexpr quantity<si::dim_length, second, int> error(0); // should not compile (unit of a different dimension) // constexpr quantity<si::dim_length, second, int> error(0); // should not compile (unit of a different dimension)
// constexpr quantity<si::dim_length, metre, quantity<si::dim_length, metre, int>> error(0); // should not compile (quantity used as Rep) // constexpr quantity<si::dim_length, metre, quantity<si::dim_length, metre, int>> error(0); // should not compile (quantity used as Rep)
// constexpr quantity<metre, si::dim_length, double> error(0); // should not compile (reordered arguments) // constexpr quantity<metre, si::dim_length, double> error(0); // should not compile (reordered arguments)
// constexpr quantity<si::dim_length, scaled_unit<metre, ratio<-1, 1>>, int> error(0); // should not compile (negative unit ratio) // constexpr quantity<si::dim_length, scaled_unit<ratio<-1, 1>, metre>, int> error(0); // should not compile (negative unit ratio)
// member types // member types
@@ -236,23 +236,23 @@ static_assert(std::is_same_v<decltype(1.0 * length<metre, int>()), length<metre,
static_assert( static_assert(
std::is_same_v<decltype(velocity<metre_per_second, int>() * si::time<second, int>()), length<metre, int>>); std::is_same_v<decltype(velocity<metre_per_second, int>() * si::time<second, int>()), length<metre, int>>);
static_assert( static_assert(
std::is_same_v<decltype(velocity<metre_per_second, int>() * si::time<hour, int>()), length<scaled_unit<metre, ratio<3600>>, int>>); std::is_same_v<decltype(velocity<metre_per_second, int>() * si::time<hour, int>()), length<scaled_unit<ratio<3600>, metre>, int>>);
static_assert(std::is_same_v<decltype(length<metre>() * si::time<minute>()), static_assert(std::is_same_v<decltype(length<metre>() * si::time<minute>()),
quantity<unknown_dimension<units::exp<dim_length, 1>, units::exp<dim_time, 1>>, scaled_unit<unknown_unit, ratio<60>>>>); quantity<unknown_dimension<units::exp<dim_length, 1>, units::exp<dim_time, 1>>, scaled_unit<ratio<60>, unknown_unit>>>);
static_assert(std::is_same_v<decltype(1 / si::time<second, int>()), frequency<hertz, int>>); static_assert(std::is_same_v<decltype(1 / si::time<second, int>()), frequency<hertz, int>>);
static_assert(std::is_same_v<decltype(1 / si::time<minute, int>()), frequency<scaled_unit<hertz, ratio<1, 60>>, int>>); static_assert(std::is_same_v<decltype(1 / si::time<minute, int>()), frequency<scaled_unit<ratio<1, 60>, hertz>, int>>);
static_assert(std::is_same_v<decltype(1 / frequency<hertz, int>()), si::time<second, int>>); static_assert(std::is_same_v<decltype(1 / frequency<hertz, int>()), si::time<second, int>>);
static_assert(std::is_same_v<decltype(1 / length<kilometre>()), static_assert(std::is_same_v<decltype(1 / length<kilometre>()),
quantity<unknown_dimension<units::exp<dim_length, -1>>, scaled_unit<unknown_unit, ratio<1, 1000>>>>); quantity<unknown_dimension<units::exp<dim_length, -1>>, scaled_unit<ratio<1, 1000>, unknown_unit>>>);
static_assert(std::is_same_v<decltype(length<metre, int>() / 1.0), length<metre, double>>); static_assert(std::is_same_v<decltype(length<metre, int>() / 1.0), length<metre, double>>);
static_assert(std::is_same_v<decltype(length<metre, int>() / length<metre, double>()), double>); static_assert(std::is_same_v<decltype(length<metre, int>() / length<metre, double>()), double>);
static_assert(std::is_same_v<decltype(length<kilometre, int>() / length<metre, double>()), double>); static_assert(std::is_same_v<decltype(length<kilometre, int>() / length<metre, double>()), double>);
static_assert( static_assert(
std::is_same_v<decltype(length<metre, int>() / si::time<second, int>()), velocity<metre_per_second, int>>); std::is_same_v<decltype(length<metre, int>() / si::time<second, int>()), velocity<metre_per_second, int>>);
static_assert( static_assert(
std::is_same_v<decltype(length<metre>() / si::time<minute>()), velocity<scaled_unit<metre_per_second, ratio<1, 60>>>>); std::is_same_v<decltype(length<metre>() / si::time<minute>()), velocity<scaled_unit<ratio<1, 60>, metre_per_second>>>);
static_assert(std::is_same_v<decltype(si::time<minute>() / length<metre>()), static_assert(std::is_same_v<decltype(si::time<minute>() / length<metre>()),
quantity<unknown_dimension<units::exp<dim_length, -1>, units::exp<dim_time, 1>>, scaled_unit<unknown_unit, ratio<60>>>>); quantity<unknown_dimension<units::exp<dim_length, -1>, units::exp<dim_time, 1>>, scaled_unit<ratio<60>, unknown_unit>>>);
static_assert(std::is_same_v<decltype(length<metre, int>() % short(1)), length<metre, int>>); static_assert(std::is_same_v<decltype(length<metre, int>() % short(1)), length<metre, int>>);
static_assert(std::is_same_v<decltype(length<metre, int>() % length<metre, short>(1)), length<metre, int>>); static_assert(std::is_same_v<decltype(length<metre, int>() % length<metre, short>(1)), length<metre, int>>);
@@ -316,7 +316,7 @@ static_assert(std::is_same_v<common_quantity<length<kilometre, long long>, lengt
// quantity_cast // quantity_cast
static_assert(std::is_same_v<decltype(quantity_cast<scaled_unit<metre, ratio<1>>>(2km))::unit, metre>); static_assert(std::is_same_v<decltype(quantity_cast<scaled_unit<ratio<1>, metre>>(2km))::unit, metre>);
static_assert(quantity_cast<length<metre, int>>(2km).count() == 2000); static_assert(quantity_cast<length<metre, int>>(2km).count() == 2000);
static_assert(quantity_cast<length<kilometre, int>>(2000m).count() == 2); static_assert(quantity_cast<length<kilometre, int>>(2000m).count() == 2);

View File

@@ -191,7 +191,7 @@ static_assert(10V * 1F == 10C);
// velocity // velocity
static_assert(std::is_same_v<decltype(1km / 1s), velocity<scaled_unit<metre_per_second, ratio<1000>>, std::int64_t>>); static_assert(std::is_same_v<decltype(1km / 1s), velocity<scaled_unit<ratio<1000>, metre_per_second>, std::int64_t>>);
static_assert(10m / 5s == 2mps); static_assert(10m / 5s == 2mps);
static_assert(10 / 5s * 1m == 2mps); static_assert(10 / 5s * 1m == 2mps);

View File

@@ -45,11 +45,11 @@ struct metre_per_second : unit<metre_per_second> {};
struct dim_velocity : derived_dimension<dim_velocity, metre_per_second, exp<dim_length, 1>, exp<dim_time, -1>> {}; struct dim_velocity : derived_dimension<dim_velocity, metre_per_second, exp<dim_length, 1>, exp<dim_time, -1>> {};
struct kilometre_per_hour : deduced_unit<kilometre_per_hour, dim_velocity, kilometre, hour> {}; struct kilometre_per_hour : deduced_unit<kilometre_per_hour, dim_velocity, kilometre, hour> {};
static_assert(std::is_same_v<downcast<scaled_unit<metre, ratio<1>>>, metre>); static_assert(std::is_same_v<downcast<scaled_unit<ratio<1>, metre>>, metre>);
static_assert(std::is_same_v<downcast<scaled_unit<metre, ratio<1, 100>>>, centimetre>); static_assert(std::is_same_v<downcast<scaled_unit<ratio<1, 100>, metre>>, centimetre>);
static_assert(std::is_same_v<downcast<scaled_unit<metre, ratio<yard::ratio::num, yard::ratio::den>>>, yard>); static_assert(std::is_same_v<downcast<scaled_unit<ratio<yard::ratio::num, yard::ratio::den>, metre>>, yard>);
static_assert(std::is_same_v<downcast<scaled_unit<metre, ratio_multiply<typename yard::ratio, ratio<1, 3>>>>, foot>); static_assert(std::is_same_v<downcast<scaled_unit<ratio_multiply<typename yard::ratio, ratio<1, 3>>, metre>>, foot>);
static_assert(std::is_same_v<downcast<scaled_unit<metre_per_second, ratio_divide<typename kilometre::ratio, typename hour::ratio>>>, kilometre_per_hour>); static_assert(std::is_same_v<downcast<scaled_unit<ratio_divide<typename kilometre::ratio, typename hour::ratio>, metre_per_second>>, kilometre_per_hour>);
static_assert(centimetre::symbol == "cm"); static_assert(centimetre::symbol == "cm");
static_assert(kilometre::symbol == "km"); static_assert(kilometre::symbol == "km");