xo-unit: refactor: Quantity2 -> Quantity
This commit is contained in:
parent
540bdce40b
commit
e9e3c63aed
3 changed files with 17 additions and 17 deletions
|
|
@ -26,30 +26,30 @@ namespace xo {
|
|||
**/
|
||||
template <typename Repr = double,
|
||||
typename Int = std::int64_t>
|
||||
class Quantity2 {
|
||||
class Quantity {
|
||||
public:
|
||||
using repr_type = Repr;
|
||||
using unit_type = natural_unit<Int>;
|
||||
using ratio_int_type = Int;
|
||||
|
||||
public:
|
||||
constexpr Quantity2(Repr scale,
|
||||
constexpr Quantity(Repr scale,
|
||||
const natural_unit<Int> & unit)
|
||||
: scale_{scale}, unit_{unit} {}
|
||||
|
||||
constexpr const repr_type & scale() const { return scale_; }
|
||||
constexpr const unit_type & unit() const { return unit_; }
|
||||
|
||||
constexpr Quantity2 unit_qty() const { return Quantity2(1, unit_); }
|
||||
constexpr Quantity unit_qty() const { return Quantity(1, unit_); }
|
||||
|
||||
constexpr Quantity2 reciprocal() const { return Quantity2(1.0 / scale_, unit_.reciprocal()); }
|
||||
constexpr Quantity reciprocal() const { return Quantity(1.0 / scale_, unit_.reciprocal()); }
|
||||
|
||||
template <typename OtherQuantity>
|
||||
static constexpr
|
||||
auto multiply(const Quantity2 & x, const OtherQuantity & y) {
|
||||
using r_repr_type = std::common_type_t<typename Quantity2::repr_type,
|
||||
auto multiply(const Quantity & x, const OtherQuantity & y) {
|
||||
using r_repr_type = std::common_type_t<typename Quantity::repr_type,
|
||||
typename OtherQuantity::repr_type>;
|
||||
using r_int_type = std::common_type_t<typename Quantity2::ratio_int_type,
|
||||
using r_int_type = std::common_type_t<typename Quantity::ratio_int_type,
|
||||
typename OtherQuantity::ratio_int_type>;
|
||||
|
||||
auto rr = detail::nu_product(x.unit(), y.unit());
|
||||
|
|
@ -59,7 +59,7 @@ namespace xo {
|
|||
* static_cast<r_repr_type>(x.scale())
|
||||
* static_cast<r_repr_type>(y.scale()));
|
||||
|
||||
return Quantity2<r_repr_type, r_int_type>(r_scale,
|
||||
return Quantity<r_repr_type, r_int_type>(r_scale,
|
||||
rr.natural_unit_);
|
||||
}
|
||||
|
||||
|
|
@ -74,9 +74,9 @@ namespace xo {
|
|||
**/
|
||||
template <typename Repr = double,
|
||||
typename Int = std::int64_t>
|
||||
inline constexpr Quantity2<Repr, Int>
|
||||
inline constexpr Quantity<Repr, Int>
|
||||
unit_qty(const scaled_unit<Int> & u) {
|
||||
return Quantity2<Repr, Int>
|
||||
return Quantity<Repr, Int>
|
||||
(u.outer_scale_exact_.template to<double>() * ::sqrt(u.outer_scale_sq_),
|
||||
u.natural_unit_);
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "Quantity2.hpp"
|
||||
#include "Quantity.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace xo {
|
||||
|
|
@ -14,7 +14,7 @@ namespace xo {
|
|||
typename Int = std::int64_t>
|
||||
inline std::ostream &
|
||||
operator<< (std::ostream & os,
|
||||
const Quantity2<Repr, Int> & x)
|
||||
const Quantity<Repr, Int> & x)
|
||||
{
|
||||
os << "<qty"
|
||||
<< xtag("scale", x.scale())
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
#include "xo/unit/unit.hpp"
|
||||
#include "xo/unit/Quantity2_iostream.hpp"
|
||||
#include "xo/unit/Quantity2.hpp"
|
||||
#include "xo/unit/Quantity.hpp"
|
||||
#include "xo/unit/scaled_unit_iostream.hpp"
|
||||
#include "xo/unit/natural_unit.hpp"
|
||||
#include "xo/unit/natural_unit_iostream.hpp"
|
||||
|
|
@ -25,7 +25,7 @@ namespace xo {
|
|||
|
||||
namespace su2 = xo::qty::su2;
|
||||
|
||||
using xo::qty::Quantity2;
|
||||
using xo::qty::Quantity;
|
||||
using xo::qty::dim;
|
||||
using xo::qty::basis_unit2_abbrev_type;
|
||||
using xo::qty::native_unit;
|
||||
|
|
@ -807,7 +807,7 @@ namespace xo {
|
|||
//log && log("(A)", xtag("foo", foo));
|
||||
|
||||
/* not constexpr until c++26 */
|
||||
Quantity2 ng = unit_qty(su2::nanogram);
|
||||
Quantity ng = unit_qty(su2::nanogram);
|
||||
auto ng2 = ng * ng;
|
||||
|
||||
log && log(xtag("ng*ng", ng2));
|
||||
|
|
@ -828,8 +828,8 @@ namespace xo {
|
|||
//log && log("(A)", xtag("foo", foo));
|
||||
|
||||
/* not constexpr until c++26 */
|
||||
Quantity2 ng = unit_qty(su2::nanogram);
|
||||
Quantity2 ug = unit_qty(su2::microgram);
|
||||
Quantity ng = unit_qty(su2::nanogram);
|
||||
Quantity ug = unit_qty(su2::microgram);
|
||||
|
||||
{
|
||||
auto prod1 = ng * ug;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue