Skip to content

Commit

Permalink
Support SingularNameFor in unit slots
Browse files Browse the repository at this point in the history
I thought it through, and realized this is pretty clearly for "quantity"
type slots only, not "point" type slots.  The reason this exists is to
participate in multiplications, divisions, and powers with quantity
makers.  Quantity points don't have multiplicative semantics.

Fixes #373.
  • Loading branch information
chiphogg committed Jan 15, 2025
1 parent 74ebfc0 commit 65e6d52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions au/code/au/unit_of_measure.hh
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ struct SingularNameFor {
}
};

// Support `SingularNameFor` in (quantity) unit slots.
template <typename U>
struct AssociatedUnit<SingularNameFor<U>> : stdx::type_identity<U> {};

template <int Exp, typename Unit>
constexpr auto pow(SingularNameFor<Unit>) {
return SingularNameFor<UnitPowerT<Unit, Exp>>{};
Expand Down
7 changes: 6 additions & 1 deletion au/code/au/unit_of_measure_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ TEST(IsUnit, FalseIfDimOrMagHasWrongType) {

TEST(IsUnit, FunctionalFormFalseForQuantityMaker) { EXPECT_FALSE(is_unit(meters)); }

TEST(FitsInUnitSlot, TrueForUnitAndQuantityMaker) {
TEST(FitsInUnitSlot, TrueForUnitAndQuantityMakerAndSingularNameFor) {
EXPECT_TRUE(fits_in_unit_slot(meters));
EXPECT_TRUE(fits_in_unit_slot(meter));
EXPECT_TRUE(fits_in_unit_slot(Meters{}));

EXPECT_FALSE(fits_in_unit_slot(1.2));
Expand Down Expand Up @@ -242,6 +243,10 @@ TEST(AssociatedUnitT, HandlesWrappersWhichHaveSpecializedAssociatedUnit) {
StaticAssertTypeEq<AssociatedUnitT<SomeUnitWrapper<Feet>>, Feet>();
}

TEST(AssociatedUnitT, SupportsSingularNameFor) {
StaticAssertTypeEq<AssociatedUnitT<SingularNameFor<Feet>>, Feet>();
}

TEST(UnitInverseT, CommutesWithProduct) {
StaticAssertTypeEq<UnitInverseT<UnitProductT<Feet, Minutes>>,
UnitProductT<UnitInverseT<Feet>, UnitInverseT<Minutes>>>();
Expand Down

0 comments on commit 65e6d52

Please sign in to comment.