xo-unit: gcc + doc nits

This commit is contained in:
Roland Conybeare 2025-08-22 15:10:03 -04:00
commit 2314268b43
5 changed files with 82 additions and 22 deletions

View file

@ -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);

View file

@ -21,9 +21,10 @@ namespace xo {
constexpr void
push_bpu_array(natural_unit<Int> * p_target, Ts... args);
/** null base case; nothing to push **/
template <typename Int>
constexpr void
push_bpu_array(natural_unit<Int> * p_target) {}
push_bpu_array(natural_unit<Int> * /*p_target*/) {}
template <typename Int, typename T0, typename... Ts>
constexpr void

View file

@ -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<NaturalUnit, Repr>) == 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 <typename Q2>
requires(quantity_concept<Q2>
&& Q2::always_constexpr_unit)
constexpr
quantity & operator=(const Q2 & x) {
auto x2 = x.template rescale_ext<s_scaled_unit>();
@ -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 <typename Repr>
using picoseconds = quantity<u::picosecond, Repr>;
template <typename Repr>
using nanoseconds = quantity<u::nanosecond, Repr>;
template <typename Repr>
using microseconds = quantity<u::microsecond, Repr>;
template <typename Repr>
using milliseconds = quantity<u::millisecond, Repr>;
template <typename Repr>
using seconds = quantity<u::second, Repr>;
template <typename Repr>
using minutes = quantity<u::minute, Repr>;
template <typename Repr>
using hours = quantity<u::hour, Repr>;
template <typename Repr>
using days = quantity<u::day, Repr>;
template <typename Repr>
using weeks = quantity<u::week, Repr>;
template <typename Repr>
using months = quantity<u::month, Repr>;
template <typename Repr>
using years = quantity<u::year, Repr>;
template <typename Repr>
using years250 = quantity<u::year250, Repr>;
template <typename Repr>
using years360 = quantity<u::year360, Repr>;
template <typename Repr>
using years365 = quantity<u::year365, Repr>;
} /*namespace type*/
namespace qty {
// ----- currency -----

View file

@ -21,6 +21,16 @@ namespace xo {
} /*namespace qty*/
namespace print {
template <auto NaturalUnit, typename Repr>
struct ppdetail<xo::qty::quantity<NaturalUnit, Repr>> {
using target_type = xo::qty::quantity<NaturalUnit, Repr>;
static bool print_pretty(const ppindentinfo & ppii,
const target_type & x) {
return ppdetail_atomic<target_type>::print_pretty(ppii, x);
}
};
} /*namespace print*/
} /*namespace xo*/
/** end quantity_iostream.hpp **/

View file

@ -34,9 +34,9 @@ namespace xo {
constexpr scaled_unit(const natural_unit<Int> & 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}
{}
///@}