diff --git a/src/include/units/si/length.h b/src/include/units/si/length.h index e879253a..2a6ae42f 100644 --- a/src/include/units/si/length.h +++ b/src/include/units/si/length.h @@ -27,9 +27,11 @@ namespace units { + // dimension struct dimension_length : make_dimension_t> {}; template<> struct upcasting_traits : std::type_identity {}; + // SI units struct millimeter : unit {}; template<> struct upcasting_traits : std::type_identity {}; @@ -42,6 +44,20 @@ namespace units { struct kilometer : unit {}; template<> struct upcasting_traits : std::type_identity {}; + // US customary units + struct yard : unit> {}; + template<> struct upcasting_traits : std::type_identity {}; + + struct foot : unit, yard::ratio>> {}; + template<> struct upcasting_traits : std::type_identity {}; + + struct inch : unit, foot::ratio>> {}; + template<> struct upcasting_traits : std::type_identity {}; + + struct mile : unit, yard::ratio>> {}; + template<> struct upcasting_traits : std::type_identity {}; + + // length template using length = quantity; @@ -66,6 +82,22 @@ namespace units { constexpr auto operator""_km(unsigned long long l) { return length(l); } constexpr auto operator""_km(long double l) { return length(l); } + // yd + constexpr auto operator""_yd(unsigned long long l) { return length(l); } + constexpr auto operator""_yd(long double l) { return length(l); } + + // ft + constexpr auto operator""_ft(unsigned long long l) { return length(l); } + constexpr auto operator""_ft(long double l) { return length(l); } + + // in + constexpr auto operator""_in(unsigned long long l) { return length(l); } + constexpr auto operator""_in(long double l) { return length(l); } + + // mi + constexpr auto operator""_mi(unsigned long long l) { return length(l); } + constexpr auto operator""_mi(long double l) { return length(l); } + } // namespace literals } // namespace units diff --git a/src/include/units/si/velocity.h b/src/include/units/si/velocity.h index 579b1c5a..60137874 100644 --- a/src/include/units/si/velocity.h +++ b/src/include/units/si/velocity.h @@ -34,10 +34,10 @@ namespace units { struct meter_per_second : unit> {}; template<> struct upcasting_traits : std::type_identity {}; - struct kilometer_per_hour : unit> {}; + struct kilometer_per_hour : unit> {}; template<> struct upcasting_traits : std::type_identity {}; - struct mile_per_hour : unit> {}; + struct mile_per_hour : unit> {}; template<> struct upcasting_traits : std::type_identity {}; template diff --git a/test/test_units.cpp b/test/test_units.cpp index 1ec614d7..5f089570 100644 --- a/test/test_units.cpp +++ b/test/test_units.cpp @@ -44,12 +44,17 @@ namespace { // length static_assert(1_km == 1000_m); + static_assert(1_m == 100_cm); + static_assert(1_m == 1000_mm); static_assert(1_km + 1_m == 1001_m); static_assert(10_km / 5_km == 2); static_assert(10_km / 2 == 5_km); -// static_assert(1_ft == 12_in); - static_assert(1_m == 100_cm); + static_assert(1_yd == 0.9144_m); + static_assert(1_yd == 3_ft); + static_assert(1_ft == 12_in); + static_assert(1_mi == 1760_yd); + // static_assert(5_in + 8_cm == 207_mm); // velocity @@ -63,6 +68,8 @@ namespace { static_assert(1.0_km / 1_h == 1_kmph); static_assert(1000.0_m / 3600.0_s == 1_kmph); + static_assert(10.0_mi / 2_h == 5_mph); + static_assert(2_kmph * 2_h == 4_km); // static_assert(2_kmph * 15_min == 500_m); // should not compile static_assert(2_kmph * 15.0_min == 500_m);