xo-unit: + quantity printing + tests for mass units

This commit is contained in:
Roland Conybeare 2024-04-28 19:12:40 -04:00
commit ab689b51df
4 changed files with 122 additions and 2 deletions

View file

@ -7,7 +7,7 @@
#include "Quantity.hpp"
#include "natural_unit_iostream.hpp"
#include <iostream>
//#include <iostream>
namespace xo {
namespace qty {

View file

@ -45,7 +45,16 @@ namespace xo {
};
namespace qty {
inline constexpr auto picograms(double x) { return quantity<double, std::int64_t, nu::picogram>(x); }
inline constexpr auto nanograms(double x) { return quantity<double, std::int64_t, nu::nanogram>(x); }
inline constexpr auto micrograms(double x) { return quantity<double, std::int64_t, nu::microgram>(x); }
inline constexpr auto milligrams(double x) { return quantity<double, std::int64_t, nu::milligram>(x); }
inline constexpr auto grams(double x) { return quantity<double, std::int64_t, nu::gram>(x); }
inline constexpr auto kilograms(double x) { return quantity<double, std::int64_t, nu::kilogram>(x); }
inline constexpr auto tonnes(double x) { return quantity<double, std::int64_t, nu::tonne>(x); }
inline constexpr auto kilotonnes(double x) { return quantity<double, std::int64_t, nu::kilotonne>(x); }
inline constexpr auto megatonnes(double x) { return quantity<double, std::int64_t, nu::megatonne>(x); }
inline constexpr auto gigatonnes(double x) { return quantity<double, std::int64_t, nu::gigatonne>(x); }
}
} /*namespace qty*/
} /*namespace xo*/

View file

@ -0,0 +1,31 @@
/** @file quantity_iostream.hpp
*
* Author: Roland Conybeare
**/
#pragma once
#include "quantity.hpp"
#include "natural_unit_iostream.hpp"
namespace xo {
namespace qty {
template <
typename Repr = double,
typename Int = std::int64_t,
natural_unit<Int> NaturalUnit = natural_unit<Int>(),
typename Int2x = detail::width2x<Int>
>
inline std::ostream &
operator<< (std::ostream & os,
const quantity<Repr, Int, NaturalUnit, Int2x> & x)
{
os << x.scale() << x.abbrev();
return os;
}
} /*namespace qty*/
} /*namespace xo*/
/** end quantity_iostream.hpp **/