diff --git a/xo-unit/include/xo/unit/bu_store.hpp b/xo-unit/include/xo/unit/bu_store.hpp index 2997b442..d3b1c8a8 100644 --- a/xo-unit/include/xo/unit/bu_store.hpp +++ b/xo-unit/include/xo/unit/bu_store.hpp @@ -100,7 +100,7 @@ namespace xo { const bu_abbrev_type & abbrev) { - std::int32_t i_abbrev = this->abbrev_lub_ix(scalefactor); + std::size_t i_abbrev = this->abbrev_lub_ix(scalefactor); auto entry = std::make_pair(scalefactor, abbrev); diff --git a/xo-unit/include/xo/unit/natural_unit.hpp b/xo-unit/include/xo/unit/natural_unit.hpp index a03c73e4..b8df9c03 100644 --- a/xo-unit/include/xo/unit/natural_unit.hpp +++ b/xo-unit/include/xo/unit/natural_unit.hpp @@ -21,9 +21,10 @@ namespace xo { constexpr void push_bpu_array(natural_unit * p_target, Ts... args); + /** null base case; nothing to push **/ template constexpr void - push_bpu_array(natural_unit * p_target) {} + push_bpu_array(natural_unit * /*p_target*/) {} template constexpr void diff --git a/xo-unit/include/xo/unit/quantity.hpp b/xo-unit/include/xo/unit/quantity.hpp index 4a232b5b..0760d428 100644 --- a/xo-unit/include/xo/unit/quantity.hpp +++ b/xo-unit/include/xo/unit/quantity.hpp @@ -16,15 +16,16 @@ namespace xo { * * @brief represent a scalar quantity with associated units. * - * - @p NaturalUnit is a non-type template paramoeter + * @tparam ScaledUnit is a non-type template paramoeter * identifying a unit used for this quantity. * In *xo-unit* it will be an instance of @c natural_unit - * - @p Repr is a type used to represent a multiple - * of @p NaturalUnit. + * @tparam Repr is a type used to represent a multiple + * of @p ScaledUnit. * * Enforce dimensional consistency at compile time. * sizeof(quantity) == sizeof(Repr). * + * Unit information is associated with type, not value. * A quantity's runtime state consists of exactly one @p Repr instance: * @code * sizeof(quantity) == sizeof(Repr) @@ -58,6 +59,8 @@ namespace xo { constexpr quantity() : scale_{0} {} /** @brief create a quantity representing @p scale @c ScaledUnits **/ explicit constexpr quantity(Repr scale) : scale_{scale} {} + /** @brief copy constructor **/ + constexpr quantity(const quantity &) = default; ///@} /** @defgroup quantity-constants static quantity constants **/ @@ -293,6 +296,7 @@ namespace xo { ///@{ /** assignment from quantity with identical units **/ + constexpr quantity & operator=(const quantity & x) { this->scale_ = x.scale_; return *this; @@ -302,6 +306,7 @@ namespace xo { template requires(quantity_concept && Q2::always_constexpr_unit) + constexpr quantity & operator=(const Q2 & x) { auto x2 = x.template rescale_ext(); @@ -936,49 +941,93 @@ namespace xo { // ----- time constants ---- /** a quantity representing 1 picosecond of time, with compile-time unit representation **/ - static constexpr auto picosecond = picoseconds(1); + static constexpr auto picosecond = picoseconds(1L); /** a quantity representing 1 nanosecond of time, with compile-time unit representation **/ - static constexpr auto nanosecond = nanoseconds(1); + static constexpr auto nanosecond = nanoseconds(1L); /** a quantity representing 1 microsecond of time, with compile-time unit representation **/ - static constexpr auto microsecond = microseconds(1); + static constexpr auto microsecond = microseconds(1L); /** a quantity representing 1 millisecond of time, with compile-time unit representation **/ - static constexpr auto millisecond = milliseconds(1); + static constexpr auto millisecond = milliseconds(1L); /** a quantity representing 1 second of time, with compile-time unit representation **/ - static constexpr auto second = seconds(1); + static constexpr auto second = seconds(1L); /** a quantity representing 1 minute of time, with compile-time unit representation **/ - static constexpr auto minute = minutes(1); + static constexpr auto minute = minutes(1L); /** a quantity representing 1 hour of time, with compile-time unit representation **/ - static constexpr auto hour = hours(1); + static constexpr auto hour = hours(1L); /** a quantity representing 1 day of time (exactly 24 hours), with compile-time unit representation **/ - static constexpr auto day = days(1); + static constexpr auto day = days(1L); /** a quantity representing 1 week of time (7 24-hour days), with compile-time unit representation **/ - static constexpr auto week = weeks(1); + static constexpr auto week = weeks(1L); /** a quantity representing 1 month of time (30 24-hour days), with compile-time unit representation **/ - static constexpr auto month = months(1); + static constexpr auto month = months(1L); /** a quantity representing 1 year of time (365.25 24-hour days), with compile-time unit representation **/ - static constexpr auto year = years(1); + static constexpr auto year = years(1L); /** a quantity representing 1 250-day year of time, with compile-time unit representation **/ - static constexpr auto year250 = year250s(1); + static constexpr auto year250 = year250s(1L); /** a quantity representing 1 360-day year of time, with compile-time unit representation **/ - static constexpr auto year360 = year360s(1); + static constexpr auto year360 = year360s(1L); /** a quantity representing 1 365-day year of time, with compile-time unit representation **/ - static constexpr auto year365 = year365s(1); + static constexpr auto year365 = year365s(1L); } /*namespace qty*/ + namespace type { + template + using picoseconds = quantity; + + template + using nanoseconds = quantity; + + template + using microseconds = quantity; + + template + using milliseconds = quantity; + + template + using seconds = quantity; + + template + using minutes = quantity; + + template + using hours = quantity; + + template + using days = quantity; + + template + using weeks = quantity; + + template + using months = quantity; + + template + using years = quantity; + + template + using years250 = quantity; + + template + using years360 = quantity; + + template + using years365 = quantity; + } /*namespace type*/ + namespace qty { // ----- currency ----- diff --git a/xo-unit/include/xo/unit/quantity_iostream.hpp b/xo-unit/include/xo/unit/quantity_iostream.hpp index 4a1faf73..5bc58d0b 100644 --- a/xo-unit/include/xo/unit/quantity_iostream.hpp +++ b/xo-unit/include/xo/unit/quantity_iostream.hpp @@ -21,6 +21,16 @@ namespace xo { } /*namespace qty*/ + namespace print { + template + struct ppdetail> { + using target_type = xo::qty::quantity; + static bool print_pretty(const ppindentinfo & ppii, + const target_type & x) { + return ppdetail_atomic::print_pretty(ppii, x); + } + }; + } /*namespace print*/ } /*namespace xo*/ /** end quantity_iostream.hpp **/ diff --git a/xo-unit/include/xo/unit/scaled_unit.hpp b/xo-unit/include/xo/unit/scaled_unit.hpp index 43d1e6b5..72ee4be7 100644 --- a/xo-unit/include/xo/unit/scaled_unit.hpp +++ b/xo-unit/include/xo/unit/scaled_unit.hpp @@ -34,9 +34,9 @@ namespace xo { constexpr scaled_unit(const natural_unit & nat_unit, OuterScale outer_scale_factor, double outer_scale_sq) - : natural_unit_{nat_unit}, - outer_scale_factor_{outer_scale_factor}, - outer_scale_sq_{outer_scale_sq} + : outer_scale_factor_{outer_scale_factor}, + outer_scale_sq_{outer_scale_sq}, + natural_unit_{nat_unit} {} ///@}