xo-unit: qty::grams() etc. infer quantity::repr_type from argument
This commit is contained in:
parent
a0d5991d01
commit
c5c2f83c90
2 changed files with 72 additions and 38 deletions
|
|
@ -7,13 +7,13 @@
|
||||||
int
|
int
|
||||||
main () {
|
main () {
|
||||||
namespace q = xo::qty::qty;
|
namespace q = xo::qty::qty;
|
||||||
namespace u = xo::qty::nu;
|
namespace nu = xo::qty::nu;
|
||||||
using xo::qty::quantity;
|
using xo::qty::quantity;
|
||||||
using xo::flatstring;
|
using xo::flatstring;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
constexpr quantity<u::second> t = q::minutes(2);
|
constexpr quantity<nu::second> t = q::minutes(2);
|
||||||
constexpr quantity<u::meter> d = q::kilometers(2.5);
|
constexpr quantity<nu::meter> d = q::kilometers(2.5);
|
||||||
|
|
||||||
constexpr auto t2 = t*t;
|
constexpr auto t2 = t*t;
|
||||||
constexpr auto a = d / (t*t);
|
constexpr auto a = d / (t*t);
|
||||||
|
|
|
||||||
|
|
@ -276,39 +276,63 @@ namespace xo {
|
||||||
namespace qty {
|
namespace qty {
|
||||||
// ----- mass -----
|
// ----- mass -----
|
||||||
|
|
||||||
inline constexpr auto picograms(double x) { return quantity<nu::picogram, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto nanograms(double x) { return quantity<nu::nanogram, double>(x); }
|
inline constexpr auto picograms(Repr x) { return quantity<nu::picogram, Repr>(x); }
|
||||||
inline constexpr auto micrograms(double x) { return quantity<nu::microgram, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto milligrams(double x) { return quantity<nu::milligram, double>(x); }
|
inline constexpr auto nanograms(Repr x) { return quantity<nu::nanogram, Repr>(x); }
|
||||||
inline constexpr auto grams(double x) { return quantity<nu::gram, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto kilograms(double x) { return quantity<nu::kilogram, double>(x); }
|
inline constexpr auto micrograms(Repr x) { return quantity<nu::microgram, Repr>(x); }
|
||||||
inline constexpr auto tonnes(double x) { return quantity<nu::tonne, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto kilotonnes(double x) { return quantity<nu::kilotonne, double>(x); }
|
inline constexpr auto milligrams(Repr x) { return quantity<nu::milligram, Repr>(x); }
|
||||||
inline constexpr auto megatonnes(double x) { return quantity<nu::megatonne, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto gigatonnes(double x) { return quantity<nu::gigatonne, double>(x); }
|
inline constexpr auto grams(Repr x) { return quantity<nu::gram, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto kilograms(Repr x) { return quantity<nu::kilogram, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto tonnes(Repr x) { return quantity<nu::tonne, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto kilotonnes(Repr x) { return quantity<nu::kilotonne, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto megatonnes(Repr x) { return quantity<nu::megatonne, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto gigatonnes(Repr x) { return quantity<nu::gigatonne, Repr>(x); }
|
||||||
|
|
||||||
// ----- distance -----
|
// ----- distance -----
|
||||||
|
|
||||||
inline constexpr auto picometers(double x) { return quantity<nu::picometer, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto nanometers(double x) { return quantity<nu::nanometer, double>(x); }
|
inline constexpr auto picometers(Repr x) { return quantity<nu::picometer, Repr>(x); }
|
||||||
inline constexpr auto micrometers(double x) { return quantity<nu::micrometer, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto millimeters(double x) { return quantity<nu::millimeter, double>(x); }
|
inline constexpr auto nanometers(Repr x) { return quantity<nu::nanometer, Repr>(x); }
|
||||||
inline constexpr auto meters(double x) { return quantity<nu::meter, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto kilometers(double x) { return quantity<nu::kilometer, double>(x); }
|
inline constexpr auto micrometers(Repr x) { return quantity<nu::micrometer, Repr>(x); }
|
||||||
inline constexpr auto megameters(double x) { return quantity<nu::megameter, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto gigameters(double x) { return quantity<nu::gigameter, double>(x); }
|
inline constexpr auto millimeters(Repr x) { return quantity<nu::millimeter, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto meters(Repr x) { return quantity<nu::meter, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto kilometers(Repr x) { return quantity<nu::kilometer, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto megameters(Repr x) { return quantity<nu::megameter, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto gigameters(Repr x) { return quantity<nu::gigameter, Repr>(x); }
|
||||||
|
|
||||||
inline constexpr auto lightseconds(double x) { return quantity<nu::lightsecond, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto astronomicalunits(double x) { return quantity<nu::astronomicalunit, double>(x); }
|
inline constexpr auto lightseconds(Repr x) { return quantity<nu::lightsecond, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto astronomicalunits(Repr x) { return quantity<nu::astronomicalunit, Repr>(x); }
|
||||||
|
|
||||||
static constexpr auto meter = meters(1);
|
static constexpr auto meter = meters(1);
|
||||||
|
|
||||||
// ----- time -----
|
// ----- time -----
|
||||||
|
|
||||||
inline constexpr auto picoseconds(double x) { return quantity<nu::picosecond, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto nanoseconds(double x) { return quantity<nu::nanosecond, double>(x); }
|
inline constexpr auto picoseconds(Repr x) { return quantity<nu::picosecond, Repr>(x); }
|
||||||
inline constexpr auto microseconds(double x) { return quantity<nu::microsecond, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto milliseconds(double x) { return quantity<nu::millisecond, double>(x); }
|
inline constexpr auto nanoseconds(Repr x) { return quantity<nu::nanosecond, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto microseconds(Repr x) { return quantity<nu::microsecond, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto milliseconds(Repr x) { return quantity<nu::millisecond, Repr>(x); }
|
||||||
|
|
||||||
template <typename Repr>
|
template <typename Repr>
|
||||||
inline constexpr auto seconds(Repr x) { return quantity<nu::second, Repr>(x); }
|
inline constexpr auto seconds(Repr x) { return quantity<nu::second, Repr>(x); }
|
||||||
|
|
@ -316,23 +340,33 @@ namespace xo {
|
||||||
template <typename Repr>
|
template <typename Repr>
|
||||||
inline constexpr auto minutes(Repr x) { return quantity<nu::minute, Repr>(x); }
|
inline constexpr auto minutes(Repr x) { return quantity<nu::minute, Repr>(x); }
|
||||||
|
|
||||||
inline constexpr auto hours(double x) { return quantity<nu::hour, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto days(double x) { return quantity<nu::day, double>(x); }
|
inline constexpr auto hours(Repr x) { return quantity<nu::hour, Repr>(x); }
|
||||||
inline constexpr auto weeks(double x) { return quantity<nu::week, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto months(double x) { return quantity<nu::month, double>(x); }
|
inline constexpr auto days(Repr x) { return quantity<nu::day, Repr>(x); }
|
||||||
inline constexpr auto years(double x) { return quantity<nu::year, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto year250s(double x) { return quantity<nu::year250, double>(x); }
|
inline constexpr auto weeks(Repr x) { return quantity<nu::week, Repr>(x); }
|
||||||
inline constexpr auto year360s(double x) { return quantity<nu::year360, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto year365s(double x) { return quantity<nu::year365, double>(x); }
|
inline constexpr auto months(Repr x) { return quantity<nu::month, Repr>(x); }
|
||||||
//inline constexpr auto year366s(double x) { return quantity<double,std::int64_t, nu::year366>(x); }
|
template <typename Repr>
|
||||||
|
inline constexpr auto years(Repr x) { return quantity<nu::year, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto year250s(Repr x) { return quantity<nu::year250, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto year360s(Repr x) { return quantity<nu::year360, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto year365s(Repr x) { return quantity<nu::year365, Repr>(x); }
|
||||||
|
//inline constexpr auto year366s(Repr x) { return quantity<double,std::int64_t, nu::year366>(x); }
|
||||||
|
|
||||||
static constexpr auto second = seconds(1);
|
static constexpr auto second = seconds(1);
|
||||||
|
|
||||||
// ----- volatility -----
|
// ----- volatility -----
|
||||||
|
|
||||||
/* volatility in units of 1/yr */
|
/* volatility in units of 1/yr */
|
||||||
inline constexpr auto volatility_250d(double x) { return quantity<nu::volatility_250d, double>(x); }
|
template <typename Repr>
|
||||||
inline constexpr auto volatility_360d(double x) { return quantity<nu::volatility_360d, double>(x); }
|
inline constexpr auto volatility_250d(Repr x) { return quantity<nu::volatility_250d, Repr>(x); }
|
||||||
|
template <typename Repr>
|
||||||
|
inline constexpr auto volatility_360d(Repr x) { return quantity<nu::volatility_360d, Repr>(x); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reminder: see [quantity_ops.hpp] for operator* etc */
|
/* reminder: see [quantity_ops.hpp] for operator* etc */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue