From f3e75cc63484d19e8ae9d3f0bf7c65cd7cf2d0a1 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 3 May 2024 21:35:53 -0400 Subject: [PATCH] xo-unit: stop hardwiring representation for a few qty builders --- example/ex1/ex1.cpp | 8 ++++---- include/xo/unit/quantity.hpp | 9 +++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/example/ex1/ex1.cpp b/example/ex1/ex1.cpp index a8282d7d..4b138a50 100644 --- a/example/ex1/ex1.cpp +++ b/example/ex1/ex1.cpp @@ -23,8 +23,8 @@ main () { << ", d.t^-2: " << a << endl; - static_assert(std::same_as); - static_assert(sizeof(t) == sizeof(double)); + static_assert(std::same_as); + static_assert(sizeof(t) == sizeof(int)); static_assert(t.scale() == 2); static_assert(t.abbrev() == flatstring("min")); @@ -33,8 +33,8 @@ main () { static_assert(d.scale() == 2.5); static_assert(d.abbrev() == flatstring("km")); - static_assert(std::same_as); - static_assert(sizeof(t2) == sizeof(double)); + static_assert(std::same_as); + static_assert(sizeof(t2) == sizeof(int)); static_assert(t2.scale() == 4); static_assert(t2.abbrev() == flatstring("min^2")); diff --git a/include/xo/unit/quantity.hpp b/include/xo/unit/quantity.hpp index 8947c9c0..d17d7624 100644 --- a/include/xo/unit/quantity.hpp +++ b/include/xo/unit/quantity.hpp @@ -313,8 +313,13 @@ namespace xo { inline constexpr auto nanoseconds(double x) { return quantity(x); } inline constexpr auto microseconds(double x) { return quantity(x); } inline constexpr auto milliseconds(double x) { return quantity(x); } - inline constexpr auto seconds(double x) { return quantity(x); } - inline constexpr auto minutes(double x) { return quantity(x); } + + template + inline constexpr auto seconds(Repr x) { return quantity(x); } + + template + inline constexpr auto minutes(Repr x) { return quantity(x); } + inline constexpr auto hours(double x) { return quantity(x); } inline constexpr auto days(double x) { return quantity(x); } inline constexpr auto weeks(double x) { return quantity(x); }